History Report a problem
Article Edit this page Discussion

Easily add folds in code

From Vim Tips Wiki

Jump to: navigation, search

Tip 940 Previous TipNext Tip

Created: June 2, 2005 Complexity: basic Author: brailsmt Minimum 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

[edit] 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.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pushing Daisies
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Astronomy Wiki
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for featured Wikia!

Send this article to a friend
"Easily add folds in code"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation