Code folding is not saved in my vimrc

后端 未结 6 1546
伪装坚强ぢ
伪装坚强ぢ 2021-02-07 08:25

I added the following code to my .vimrc:

\" save and restore folds when a file is closed and re-opened
autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* sil         


        
6条回答
  •  不要未来只要你来
    2021-02-07 08:52

    The problem is that your original autocmd lines are set to match the pattern *.*, i.e. any filename which contains some characters, followed by a dot, followed by some more characters.

    So the file test.html or anothertest.css will be matched, and your command will run, but .vimrc, which has nothing prior to the dot, will not be matched.

    The solution is to set up an autocmd which will match .vimrc. Your guess of ?* does match this (because it's looking for any character, followed by any number of other characters), but you say it somehow affects MRUs. I don't know what plugin you're using for your MRUs, but I'm guessing it's one which opens the MRU list in a temporary window with a name that matches the ?* pattern, and the subsequent loading of the view is somehow messing with your MRUs.

    Therefore, the fix is to use something a bit more specific to match .vimrc:

    autocmd BufWinLeave .vimrc mkview
    autocmd BufWinEnter .vimrc silent loadview 
    

    It's possible that this will work, too, and is more general:

    autocmd BufWinLeave .* mkview
    autocmd BufWinEnter .* silent loadview 
    

提交回复
热议问题