I want to influence how my vimrc file is executed when I start vim and thought of using a global variable like so
if exists("g:UseEnv1")
....
else
....
endif
This variable would be set when starting vim like so
gvim -c "let g:UseEnv1=1" file-1 file-2
However, this doesn't work because the -c ex commands are evaluated after the vimrc file is executed.
I could use environment variables
if $UseEnv1 == 1
...
endif
Yet I feel this is a bit problematic in case I forget to change the value of $UseEnv1 between two sessions. Ideally, I'd like to explicitly have to state that I want Env 1 when I start vim.
Are there other possibilities?
The --cmd
command-line argument is like -c
, but it is executed before any other initialization. You can use that to set certain Vim variables that influence your ~/.vimrc
.
If you plan to actually type those configurations in the command-line (vs. coding them into a shell alias or similar), the use of environment variables isn't actually so bad: In most (Unix) shells, you can set variables only for one command by prepending them. So instead of
$ gvim --cmd "let g:UseEnv1=1" file-1 file-2
you could write
$ UseEnv1=1 gvim file-1 file-2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With