Vim Tips Wiki
Advertisement
Tip 940 Printable Monobook Previous Next

created June 2, 2005 · complexity basic · author brailsmt · version 6.0


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

Comments

[{zf% is enough.


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?


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).

See :help mapleader.


I think "zfa}" is enough.


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 folds the block which is closest to your cursor.


Advertisement