How to tell VIM to store the viminfo file somewhere else?
Is it possible to tell vim to save its viminfo file somewhere else? Such as in开发者_如何学C the .vim folder
Try adding set viminfo+=n~/.vim/viminfo
to your ~/.vimrc
file. From :help 'viminfo'
:
n Name of the viminfo file. The name must immediately follow
the 'n'. Must be the last one! If the "-i" argument was
given when starting Vim, that file name overrides the one
given here with 'viminfo'. Environment variables are expanded
when opening the file, not when setting the option.
set viminfo='1000,nc:\\users\\abcdef\\_viminfo
This works for me in Windows 7.
I had a similar problem but had no write permission to my home folder (thus could not create the ~/.vimrc
).
I solved it by modifying (through the Administrator) the _vimrc in C:\Program Files\VIM
to include the line:
let $HOME = $USERPROFILE
I placed it at the beginning of the file and it worked well. Just in case someone comes across this question and this answer didn't work.
I know its quite a while now, but I am just mentioning this for future readers.
I was facing the same issue while trying to change the location for viminfo file in vimrc. At last setting the value of viminfofile
option worked for me.
Added the following to my vimrc:
set viminfofile=D:\vim\viminfo
It works for me on windows with vim 8.2
TL;DR
This seems to be a bug in vim
where set nocompatible
is not idempotent and doesn't follow the principle of least astonishment.
As a workaround, either:
Ensure that you
set nocompatible
(or the equivalentset nocp
) only once, and at the top of yourvimrc
.Don't set it again if it's already set:
if &compatible | set nocompatible | endif " Avoid side effects if `nocp` already set
Explanation and bug illustration
From :help compatible
(empahsis mine):
This is a special kind of option, because when it's set or reset, other options are also changed as a side effect. CAREFUL: Setting or resetting this option can have a lot of unexpected effects: Mappings are interpreted in another way, undo behaves differently, etc. If you set this option in your vimrc file, you should probably put it at the very start.
Note that &viminfo
is not listed in the side-effects, however the following lines clearly show the side effect upon &viminfo
:
set nocompatible
set viminfo+=nWatch-my-viminfo-file-location-be-ignored
echom &viminfo
set nocompatible " do side effects even though nocomptible is already set
echom 'After 2nd "set nocompatible":'
echom &viminfo
Output:
'100,<50,s10,h,nWatch-my-viminfo-file-location-be-ignored After 2nd "set nocompatible": '100,<50,s10,h
vim --version | head -1
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 05 2016 16:48:20)
Resolution
I have raised two GitHub issues regarding this:
- Undocumented "set nocompatible" side effect upon &viminfo
set nocompatible
not idempotent - setting produces side effects when already set
See also Vi StackExchange's question: Can't move viminfo
file - &viminfo reverts upon loading vim which I raised before seeing this one.
The ordering of settings in the .vimrc affects the use of :set viminfo. The setting of viminfo should be after the setting of nocompatible. After reordering my .vimrc, the above solution to have the viminfo file be located in the .vim directory worked for me.
In gvim8.2 on Windows10, following option works to change path of viminfo :
set viminfofile=$VIM/.viminfo
Write this in .vimrc .
It could to change viminfo file path to under the $VIM.
精彩评论