Helpful settings for editing tabular data:
1 2 3 |
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:
1 2 3 |
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:
1 2 3 4 |
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:
1 2 3 4 |
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:
1 |
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:
Another way to visualize tabs and other whitespace is with the “listchars” and “list” commands:
setlocal listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
setlocal list
With this there is no need to hide the cursor line. Also you can see the end of line markers and easily distinguish between tabs and regular space chars.
To use the right mouse button to select text in block visual mode using the mouse:
nmap <RightMouse> <LeftMouse><C-V>
Also, by default, quad-clicking the left mouse button (yes, clicking the left mouse button four times 🙂 so that the button is kept depressed after the fourth click does the same.
set virtualedit=all
or
set virtualedit=block
May also be helpful when selecting blocks when some lines are longer than others.