command
will give an error if a command with that name already exists. Vim has no way of knowing that the command in your vimrc is actually the same command; from Vim's viewpoint it's a "new" command.
You have to use command!
to override any existing commands. The same applies to functions; use function!
to override existing functions. This also works for the shorthand versions (e.g. comm!
, fun!
).
Another caveat are autocommands. If you use:
autocmd BufNew * some_command()
and you reload your vimrc then you will have two autocommands defined! Vim has no way to "see" that this autocommand was already executed and installed on startup.
To fix this use augroup
:
" Define a new autocommand group
augroup my_autocmd_name
" Clear all existing autocommands in this group
autocmd!
" This will now always be installed once only
autocmd BufNew * some_command()
augroup end
A third caveat is realizing that not all autocommands are run when you reload your vimrc. Specifically, things like VimEnter
, BufReadPost
, Filetype
WinEnter
, etc. aren't executed when you type :source $VIMRC
. This is especially important if you have something like:
" Real men use real tabs
set expandtab
" Python programmers aren't real men (augroup omitted for brevity)
autocmd Filetype *.py setlocal noexpandtab
If you now reload your vimrc while you have a buffer with a Python file, the :set
command will reset expandtab
and the Filetype
autocommand is never executed to override it for Python files.
As for your airline issue − I don't know. The FAQ recommends running the :AirlineRefresh
command.
command!
instead ofcommand
. Do you usually source yourvimrc
multiple times in a session?