Mikko Kortelainen

Editing Tabular Data in Vim

Helpful settings for editing tabular data:

setlocal noexpandtab
setlocal nowrap
setlocal tabstop=16 softtabstop=16 shiftwidth=16

Noexpandtab disables expanding of inputted tabs to spaces. Adjust the number of spaces to your liking. Tabstop sets the visual appearance of tab stops (here 16 spaces).

Show tabs visually, disable cursor line:

syntax match Tab /\t/
hi Tab gui=underline guifg=blue ctermbg=blue
setlocal nocursorline

Jump one column left or right Ctrl+H / Ctrl+L in both normal and visual modes to make navigation easier:

nmap <C-L> f<Tab>
nmap <C-H> F<Tab>
vmap <C-L> f<Tab>
vmap <C-H> F<Tab>

Jump 10 lines up or down with Ctrl+K / Ctrl+J:

nmap <C-J> 10j
nmap <C-K> 10k
vmap <C-J> 10j
vmap <C-K> 10k

Disable the behaviour of going to start of line after jumps to make it easier to work on columns:

setlocal nosol

Now you can G or gg and have your cursor in the same column where it was. Makes it easy to select, yank, delete and move columns. Just don't add an empty line at the bottom of the file (you can use "set virtualedit=all" to work around that as well if you want).

Excellent blog post on the subject: