Search code examples
vimeditorvi

How to do column editing in vim?


Vim is pretty powerful when editing by line - the search/replace tools are modeled to work linewise.

But what if I want to change a particular column across all lines? For example, how can I change the 80th column in my file to a # easily?


Solution

  • You can use a substitution where the pattern matches a specific column (\%c):

    :%s/\%80c/#/<CR>
    

    Or you can use block-wise visual mode:

    gg80|CTRL+vGr#

    The 'virtualedit' option can be used to allow positioning the cursor to positions where there is no actual character:

    :set virtualedit