2

Pressing spacebar on a + fold in vim in diff mode causes the fold to open.

What and where do I key if I want to close the fold again?

3

I believe you want z+c to close the fold. You can read more by typing :help fold in vim. The following is pasted for convenience:

zo Open one fold under the cursor. When a count is given, that many folds deep will be opened. In Visual mode one level of folds is opened for all lines in the selected area.

zc Close one fold under the cursor. When a count is given, that many folds deep are closed. In Visual mode one level of folds is closed for all lines in the selected area. 'foldenable' will be set.

Also, za can be used to toggle the fold open or closed. There is a vim tip on the wiki that describes mapping the key to the spacebar with the following:

nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
  • It works. Plus now I can have VStudio style folding! If only Vim had a code intelligence, or whatever that thing in VStudio was called. Plus that remap works nicely too. The guy's a genius! – Cris Stringfellow Feb 27 '13 at 1:32
  • They called it Intellisense. Vim has some built in shortcuts for this in insert mode: ctrl+n and ctrl+x ctrl+n. See: :help i_ctrl-N & :help i_CTRL-X_CTRL-N – Brett Feb 27 '13 at 2:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.