.vimrc
これを実現するには、独自の変数を使用してVIMを起動し、その変数に応じてさまざまなファイルを入手します。
あなたの.vimrc
中で(それを使用するいくつかの異なる方法を示しています):
"# this is _not_ an error if env. variable 'what_to_do' isn't used
let WhatToDo = $what_to_do
if WhatToDo == "this"
"# Use 'source'
source $HOME/.vim/.vimrc_this
"# This should not do 'common stuff'
finish
elseif WhatToDo == "that"
"# ...or use 'runtime', finds and sources the first file with the given
"# name looking in folders in 'runtimepath' (default includes e.g. ~/.vim)
runtime .vimrc_that
else
runtime .vimrc_default
endif
"# common stuff...
次に、Unixコマンドラインで使用するには:
$ vim text.txt # will use '.vimrc_default'
$ what_to_do=that vim text.txt # will use '.vimrc_that'
$ # what_to_do is not defined after that line
コマンドと同じ行でUnix環境変数を使用する場合、その変数はそのコマンドに対してのみ有効です。NB!=
Unix変数を設定するときは、前後にスペースを入れることはできません。
または、前に設定することもできます。
$ what_to_do=that
$ vim text.txt # will use '.vimrc_that'
$ # what_to_do has still the value "that" here
またはスクリプト(startvim)で:
what=$1
shift
what_to_do=$what vim "$@"
と一緒に使用します
$ startvim that <whatever flags you want> text.txt
または、おそらく最善の方法は、選択肢ごとに1つのエイリアスを使用することです。そうすれば、必要なフラグを
$ alias vim_that='what_to_do=that vim'
使用して、同じように使用できます。vim
例えば
$ vim_that <whatever flags you want> text.txt
環境変数を使用する代わりに、フラグ--cmdを使用する方法があります。
--cmd {command} --cmd {command}は、vimrcファイルを処理する前に実行されます。それ以外の場合は、-c{command}のように機能します。「-c」コマンドとは別に、これらのコマンドを最大10個使用できます。{Viにはありません}
で開始しますが
$ vim --cmd 'let WhatToDo = "that"' text.txt
、
エイリアスを
$ alias vi_that='vi --cmd "let WhatToDo = \"that\""'
使用する場合は注意が必要です(その場合、その変数で開始されていない場合に処理するには、の先頭で使用し、の行をスキップする
if ! exists("WhatToDo") | let WhatToDo = "" | endif
必要があります)。.vimrc
$what_to_do
もちろん、を使用-c "source the_file_you_want"
して空にすることもできますが.vimrc
、その場合、ソーシングは開始シーケンスの中で、を持っているのと同じ場所にない可能性があり.vimrc
ます。
これのヘルプ:
:h runtime
:h runtimepath
:h --cmd