How can I make .vimrc read from an external file?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Darkness Approaches Looping
--
Chapters
00:00 How Can I Make .Vimrc Read From An External File?
00:59 Accepted Answer Score 44
01:15 Answer 2 Score 2
01:39 Answer 3 Score 5
01:53 Answer 4 Score 5
02:37 Thank you
--
Full question
https://superuser.com/questions/224607/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#vim #vimrc
#avk47
ACCEPTED ANSWER
Score 44
in your main .vimrc file:
source otherVimScriptFilePath.vim
then just put your variable statement in that file:
" otherVimScriptFilePath.vim
let whoami = "user1"
ANSWER 2
Score 5
To answer the last question, files in ~/.vim
are not automatically loaded, but all files in ~/.vim/plugin
are.
ANSWER 3
Score 5
You can have your ~/.vimrc load another file using the :source
command. For example, you could each put your unique commands in ~/.myvimrc and load those commands with
source ~/.myvimrc
Or, as you were thinking, you could each put your name in that file like this:
let user = "user1"
and then put this in your ~/.vimrc:
source ~/.myvimrc
if user == "user1"
" do this
elseif user == "user2"
" do that
else
echo "Invalid user"
endif
Rather than put your names in files, though, you could use $USER as akira suggested, or set user
using whoami
, like this:
let user = substitute(system('whoami'), '\n', '', '')
The substitute() function is needed because the output of system() usually has a '\n' tacked on the end.
ANSWER 4
Score 2
the name of the logged-in user is available in the $USER environment variable. you can access that variable easily:
:echo $USER
so, just use
execute "silent! source vimrc." . $USER
in your vimrc and put your user specific settings into
vimrc.joe
or whatever your login-name is