You don't need to define an entire alternative vimrc configuration if you just want to set a flag variable. You can do that with --cmd
:
alias kvim='vim --cmd "let g:IsKernelCode=\"yes\""'
As you use a global flag (with the g:
prefix), this will apply to all opened files (both on startup and later interactively with :edit
). For each opened file, the ftplugin/c/c.vim
will be sourced again. You can check by putting :echomsg
commands in there.
Note that using special settings for a project or subdirectory is a common use case. Various solutions have been devised for this; here's an overview:
Central configuration
If it's okay to configure the specific commands / local exceptions centrally, you can put such autocmds into your ~/.vimrc
:
:autocmd BufRead,BufNewFile /path/to/dir/* setlocal ts=4 sw=4
It is important to use :setlocal
instead of :set
, and likewise :map <buffer> ...
and :command! -buffer ...
.
On the other hand, if you want the specific configuration stored with the project (and don't want to embed this in all files via modelines), you have the following two options:
Local config with built-in functionality
If you always start Vim from the project root directory, the built-in
:set exrc
enables the reading of a .vimrc
file from the current directory. You can place the :set ts=4 sw=4
commands in there.
Local config through plugin
Otherwise, you need the help of a plugin; there are several on vim.org; I can recommend the localrc plugin (especially with my own enhancements), which even allows local filetype-specific configuration.
Note that reading configuration from the file system has security implications; you may want to :set secure
.