Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #940 - Easily add folds in code

Created: June 2, 2005 15:21 Complexity: basic Author: brailsmt Version: 6.0 Karma: 6/9 Imported from: Tip#940

This is a simple keymapping to make adding folds to source code simpler. I use foldmethod=marker, but that shouldn't be necesary for this tip. It will fold the current block (block being anything delimted with '{' and '}') no matter where you are in that block.

Add this to your .vimrc:

nmap <silent> <leader><leader> [{V%zf 

Enjoy!

Comments

[{zf% is enough :-) Have Fun :-)

yohann coppel , June 3, 2005 0:26


Can you explain what key to press and what will happen?

Seems like the tip is meant for people who already know what it is about?

Anonymous , June 4, 2005 20:15


in his mapping the "<leader><leader>" signifies the keys used to invoke the command.

<leader> is a special variable for vim mappings, which represents a user configured key. The <leader> defaults to (backslash), but can be changed to another key if you wish.

So, by default, to invoke the mapping above you would use '\' (backslash backslash).

in vim type :help mapleader for more information.

Anonymous , June 6, 2005 7:37


bah... the backslash in my post above got removed... see the english version in parens above

maybe this will show up... <leader> defaults to '\' and '\\\' invokes the mapping.

Anonymous , June 6, 2005 7:40


I think "zfa}" is enough.

Anonymous , June 6, 2005 11:26


well, it's not working on my computer which runs vim6.3.

since the cursor must be under the '{' , i have to use a search:

nmap <silent> <leader><leader> /{<cr>zf% 

it works. and it can folds the block which is closest to your cursor. the status bar will display some message though, i could not find a better solution..:(

Anonymous , June 7, 2005 19:17


Advertisement