English 中文(简体)
Code folding is not saved in my vimrc
原标题:

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 *.* silent loadview 

HTML and CSS documents save and restore their folds but code folding is not being saved in my .vimrc

Any suggestions?

EDIT:

The following code solves the problem:

au BufWinLeave ?* mkview
au BufWinEnter ?* silent loadview

but if I write it, the MRU files disappear from my list (and I have to open MRU twice in order to see my list of recent files why?)

最佳回答

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 
问题回答

Per Jays comments this is the most elegant solution, I have a LOT of plugins and run it on multiple OSes and have just tested it.

autocmd BufWrite * mkview
autocmd BufRead * silent loadview

It does not break MRU and make you have to double query MRU It does not error when you :new into an empty buffer It also doesn t require you to create FileType patern for every file-type you may possibly use.

NOTE: using "loadview" on "BufNewFile" apears to be what confuses MRU, rather pointless trying to render folds on an empty buffer I would have thought??

i had a similar problem. maybe you have to create the directory which holds the data.

mkdir -p ~/.vim/view
chmod 0750 ~/.vim ~/.vim/view

With Neovim in Arch Linux, I was getting error messages until I appended a ! after silent (silent!). Here is my ~/.vimrc entry,

autocmd BufWrite * mkview
autocmd BufRead * silent! loadview

Details here:

https://github.com/neovim/neovim/issues/7442#issuecomment-339752054

Add this to the top of your vimrc to make sure the viewdir is present

let &viewdir=expand("$HOME") . "/.bk/.vim/viewdir"
if !isdirectory(expand(&viewdir))|call mkdir(expand(&viewdir), "p", 451)|endif

Then this in your autocmds section:

autocmd BufWrite * mkview
autocmd BufNewFile,BufRead * silent loadview

The view details get saved in view file in the vimfilesview directory. A separate view file is created for every file you edit.





相关问题
Autoupdate VIM Plugins?

Is it possible to update vim plugins automatically?

how to unindent in vim without leaving edit mode?

I m writing a lot of python code recently, and i used the tab-to-space mode in vim. I was just wondering how would i unindent in vim without leaving edit mode for example after i finished if...: block....

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

Vim - Deleting XML Comments

How do I delete comments in XML? If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread ...

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the ...

Profiling Vim startup time

I’ve got a lot of plugins enabled when using Vim – I have collected plugins over the years. I’m a bit fed up with how long Vim takes to start now, so I’d like to profile its startup and see which of ...

热门标签