How to set the default to unfolded when you open a file?

后端 未结 8 1642
臣服心动
臣服心动 2021-01-31 13:34

In my .vimrc I\'ve put set foldmethod=syntax to enable folding of methods etc. However, I don\'t like the default that everytime I open a file, the who

8条回答
  •  醉梦人生
    2021-01-31 14:03

    In .vimrc add an autocmd for BufWinEnter to open all folds automatically like this:

    autocmd BufWinEnter * silent! :%foldopen!
    

    That tell vim to execute the silent :%foldopen! after opening BunWinEnter event (see :h BufWinEnter). The silent %foldopen! will execute foldopen on the whole buffer thanks to the % and will open all folds recursively because of the !. Any eventual error message will be suppressed by silent. (You could get error messages like E490: No fold found if the buffer actually didn't contain any fold yet)

    Note: You could use BufRead instead of BufWinEnter but then if the file has a modeline that enables the folding that will override this autocmd. I mean BufRead autocmds run before the modeline is processed and BufWinEnter will run them after. I find the later to be more useful

提交回复
热议问题