Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusion about vim folding - how to disable?

Tags:

vim

vi

folding

People also ask

How do I delete a fold in Vim?

To delete all fold markers, visually select all the file with ggVG before doing a zd .

How does folding work in Vim?

Vim uses the same movement commands to define folds. Folding also works in visual mode. If you enter visual mode using v or V , then select a few lines of text using the movement keys, and type zf , Vim will create a fold comprising those lines. Another option is to specify a range in command mode.

What is code folding in Vim?

Yanis. March 15, 2020. Folding is a way to hide a chunk of text, and thus unclutter the view. That comes handy when you need to focus on some other part of code, or if you want to get a quick overview of the whole file.

How do I save a fold in Vim?

The problem is that when you close Vim, your artfully folded code returns to its unfolded state. The solution is quite simple - when you are ready to save your folds run the :mkview command. This will save your folds in the current buffer to your viewdir ( :h viewdir ) depending on your environment.


You're not alone.

set nofoldenable    " disable folding

The easiest way to disable (and enable) folding on the fly is zi.

zi is the normal mode command that toggles 'foldenable', just like :set foldenable!.

Mnemonic: "fold invert". See :h zi.


Add set nofoldenable to your ~/.vimrc to disable folding.


Here is an article which briefly and concisely sums up why folding is cool. The one line reason is that folding makes navigating very large files a breeze.

If you want to leave folding enabled, and simply always start with all folds open, the vim wiki tells how. The method of interest to you would probably be the autocommand method.

" Tweak the event and filetypes matched to your liking. 
" Note, perl automatically sets foldmethod in the syntax file
autocmd Syntax c,cpp,vim,xml,html,xhtml setlocal foldmethod=syntax
autocmd Syntax c,cpp,vim,xml,html,xhtml,perl normal zR

I would also recommend searching for custom folding methods for the language you use. Simply googling "vim <insert language here> folding" should bring up a number of options. Play around with the different options until you find a folding method you like.


I have added this line to my .vimrc file cause I had the same issue:

autocmd FileType * exe "normal zR"

This command will be executed every time you open a file automatically. So you won't see the bug and the folding feature won't be lost too)


Just adding one more to make it complete to the point of discussion.

To enable code folding:

:set foldenable or in short, :set fen

To disable code folding:

:set nofoldenable or in short, :set nofen

Once you enable codefolding, you will have all the commands like zf,zo etc at your wish according to the setting of :set fdm=xxxx where typical values are expr,syntax,manual etc.


Vim makes it amazingly hard to disable folding, especially when using vimdiff.
None of the above posted solutions worked for me, but this did (add to ~/.vimrc):

au WinEnter * set nofen
au WinLeave * set nofen