How to pass vimrc argument when running (g) vim?

I want to influence how my vimrc file is executed when I run vim and thought about using a global variable like

if exists("g:UseEnv1")
   ....
else
   ....
endif

This variable will be set when vim starts, for example,

gvim -c "let g:UseEnv1=1" file-1 file-2 

However, this does not work because the -c ex commands are evaluated after the vimrc file is executed.

I could use environment variables

if $UseEnv1 == 1
   ...
endif

But I feel this is a bit problematic if I forgot to change the value of $ UseEnv1 between two sessions. Ideally, I would like to explicitly indicate that I want Env 1 when starting vim.

Are there other options?

+4
source share
1 answer

--cmd -c, . , Vim, ~/.vimrc.

( ), : (Unix) , .

$ gvim --cmd "let g:UseEnv1=1" file-1 file-2

$ UseEnv1=1 gvim file-1 file-2
+8

Source: https://habr.com/ru/post/1536905/


All Articles