Reputation: 37
I am unable to change my .vimrc because I am using a login that multiple people use. I would like to be able to set vim options for my current shell without changing vimrc. Either that or pass in arguments to vim when called. I am hoping to be able to set the following:
:set nu
:set shiftwidth=4
:set tabstop=4
:set ai
:set expandtab
It's a long shot but any ideas would be greatly appreciated
Upvotes: 1
Views: 556
Reputation: 196886
You could do:
$ vim -c "set nu sw=4 ts=4 ai et"
You could also put your settings in ~/my.vim
and start Vim with:
$ vim -Nu ~/my.vim
Upvotes: 4
Reputation: 755064
Running :help EXINIT
in vim
reveals:
*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 (*)!
This indicates that setting environment variable $VIMINIT
gets precedence, then your .vimrc
file, then the setting in $EXINIT
, then .exrc
files. This is consistent with what I found — not very surprisingly. I have a .vimrc
file; it took precedence over the $EXINIT
variable I was setting, but setting $VIMINIT
worked, overriding the .vimrc
file.
Upvotes: 6
Reputation: 37
I found that I can write a script to call vim with the parameters I want and use that in place of vim:
vim -c "set tabstop=4" -c "set nu" -c "set ai" -c "set expandtab" $1
now calling
./myvim fileToEdit
opens vim with my desired options. VIMINIT did work as well, thanks for the tip.
Upvotes: 0