我无法更改我的.vimrc,因为我使用的是多人使用的登录信息。我希望能够在不更改vimrc的情况下为我当前的shell设置vim选项。要么在调用时将参数传递给vim,要么将其传递给vim。我希望能够设置以下内容:
:set nu
:set shiftwidth=4
:set tabstop=4
:set ai
:set expandtab
这是一个很长的镜头,但任何想法将不胜感激
答案 0 :(得分:6)
在:help EXINIT
中运行vim
会显示:
*VIMINIT* *.vimrc* *_vimrc* *EXINIT* *.exrc* *_exrc* *$MYVIMRC*
c. Four places are searched for initializations. The first that exists
is used, the others are ignored. The $MYVIMRC environment variable is
set to the file that was first found, unless $MYVIMRC was already set
and when using VIMINIT.
- The environment variable VIMINIT (see also |compatible-default|) (*)
The value of $VIMINIT is used as an Ex command line.
- The user vimrc file(s):
"$HOME/.vimrc" (for Unix and OS/2) (*)
"s:.vimrc" (for Amiga) (*)
"home:.vimrc" (for Amiga) (*)
"$VIM/.vimrc" (for OS/2 and Amiga) (*)
"$HOME/_vimrc" (for MS-DOS and Win32) (*)
"$VIM/_vimrc" (for MS-DOS and Win32) (*)
Note: For Unix, OS/2 and Amiga, when ".vimrc" does not exist,
"_vimrc" is also tried, in case an MS-DOS compatible file
system is used. For MS-DOS and Win32 ".vimrc" is checked
after "_vimrc", in case long file names are used.
Note: For MS-DOS and Win32, "$HOME" is checked first. If no
"_vimrc" or ".vimrc" is found there, "$VIM" is tried.
See |$VIM| for when $VIM is not set.
- The environment variable EXINIT.
The value of $EXINIT is used as an Ex command line.
- The user exrc file(s). Same as for the user vimrc file, but with
"vimrc" replaced by "exrc". But only one of ".exrc" and "_exrc" is
used, depending on the system. And without the (*)!
这表示设置环境变量$VIMINIT
优先,然后是.vimrc
文件,然后是$EXINIT
中的设置,然后是.exrc
个文件。这与我发现的一致 - 不是很令人惊讶。我有一个.vimrc
文件;它优先于我设置的$EXINIT
变量,但设置$VIMINIT
有效,覆盖了.vimrc
文件。
答案 1 :(得分:4)
你可以这样做:
$ vim -c "set nu sw=4 ts=4 ai et"
您还可以将设置放在~/my.vim
中,然后使用以下命令启动Vim:
$ vim -Nu ~/my.vim
答案 2 :(得分:0)
我发现我可以编写一个脚本来调用带有我想要的参数的vim并用它代替vim:
vim -c "set tabstop=4" -c "set nu" -c "set ai" -c "set expandtab" $1
现在正在呼叫
./myvim fileToEdit
用我想要的选项打开vim。 VIMINIT确实也有效,谢谢你的提示。