how to activate vim folding markers?
OK, after googling around for a bit, I found this which seems to work:
set foldmethod=marker
nnoremap <space> za
The default keybindings for folding are za
or zm
(though zm
I think only closes folds, while za
toggles them), so you should add the following lines to your .vimrc:
set foldmethod=marker
to enable folding triggered by markers (the {{{
things in your code)
nnoremap <space> za
to enable space
to trigger the fold in normal mode.
But! if you're not sure if you want to enable folding in other files, you could use autocmd
s, like so:
autocmd FileType vim,c++,txt setlocal foldmethod=marker
and that will ensure that folding only works in vim, c++, and text files.
By the way, what you've posted is only one kind of folding mentioned by vim guru Steve Losh in this article. Read it to learn more about folding. It's super cool.
If you only have a few files or if you just wish to control option(s) on a per file basis you may want to use modeline
. My intro to folding came when I download a z-shell script and when I opened it, was surprised to find everything folded. Found something like this at the end of the file:
# vim:ts=4:sw=4:ai:foldmethod=marker:foldlevel=0:
Change commenting to match your code type, and insure there is a space before the word vim
. As always a good place to start: :help modeline
and :help folding
. You may have to add set modeline
to your .vimrc file if modeline
was not set at build time.