History
Article Edit this page Discussion

Easily open and close folds

From Vim Tips Wiki

(Redirected from VimTip1330)
Jump to: navigation, search

[edit] Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 1330 Previous Next Created: September 17, 2006 Complexity: basic Author: Peter Hodge Version: 5.7


If you're finding that 'zo' and 'zc' are hard to type or remember, you could use <spacebar> and <backspace> to open and close folds:

nnoremap <Space> zo
nnoremap <backspace> zc

Or, you could just use the <spacebar> to do both:

nnoremap <Space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

[edit] Comments

Using za is easier - see :help za.


Better add the following mappings:

inoremap <F9> <C-O>za
nnoremap <F9> za
onoremap <F9> <C-C>za
vnoremap <F9> zf

With these mappings, one can create folds in Visual mode and open/close folds in the other modes.


Space already works out of the box for opening folds. The idea for backspace to close again is a good one and will surely make it into my .vimrc :)


zA - toggle open/close folds recursively.


Tip 108 is better than this. It won't affect normal functionality of <Space> when cursor is not on folding.

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
Pixar
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Dark Shadows
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for collaboration of the month.

Send this article to a friend
"Easily open and close folds"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation