Two Vim tidbits

The first one is a boon to *nix programmers: how to open a man page from inside vim! Turns out this is rather easy: your vim installation came with the file /usr/share/vim/vim72/ftplugin/man.vim, which defines the command Man (with a capital ‘M’), which you can call like so: :Man _some_manpage_. To make this command available, just add this to your .vimrc:

runtime! ftplugin/man.vim

Now, while editing a C file for instance, you can do a :Man printf and vim will horizontally split the screen, and display the manpage in the upper half. If you’re like me, and prefer to split the screen vertically, do ^Wt^WH.

The second tidbit is about Vim folding. Whatever the fold method used (indent, marker, …), if one is used, when opening a file, all folds present will be collapsed. More often than not, I find this an annoyance, so after setting the indent method, I added another line that expands all the folds, like so (again done in ~/.vimrc):

set foldmethod=indent
set foldminlines=10
autocmd BufRead *.* norm zR

The last line expands all folds; the middle line is actually to prevent folds with less than 10 lines (which is fairly common in source code, given that the fold method is indent).


Os comentários estão fechados.