Confusion about vim folding - how to disable?

允我心安 提交于 2019-11-29 19:24:56

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.

Sorry, if I'm answering related question, but I found useful to display two files alongside with folding turned off with something like this:

vim "+set nofen" -O file1 file2

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

I set foldlevel=20, foldlevelstart=20 and I use foldmethod=syntax. It's help me work with correct folding in vim.

set nofoldenable disable folding but sometimes I need it

vim.wikia

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!