Managing project-specific settings for Vim/Neovim projects.
I talked about managing multiple databases and projects in my previous articles. On some occasions, you may have a need to manage multiple projects with configurations only specific to the projects.
In this article, let’s explore the available options we have in Vim/Neovim. I will start with the simplest solution and then move on to explore plugins we can use.
Vim/Neovim — Managing Databases
Managing databases and run SQL statements, all within Vim/Neovim.
Vim/Neovim — Managing Multiple Projects
Managing multiple projects from Vim/Neovim.
exrc, vimrc, nvimrc
If you set the
exrc option in your
init.vim file, Vim/Neovim will execute
.exrc (for both Vim/Neovim),
.nvimrc (Neovim) found in the current directory when Vim/Neovim is started.
For security reason, you may also want to set the
secure option together (refer to
set secure exrc
secure is on,
write commands are not allowed in
.exrc in the current directory and map commands are displayed.
From the documentation for the
When on, “:autocmd”, shell and write commands are not allowed in
“.nvimrc” and “.exrc” in the current directory and map commands are
displayed. Switch it off only if you know that you will not run into
problems, or when the ‘exrc’ option is off. On Unix this option is
only used if the “.nvimrc” or “.exrc” is not owned by you. This can be
dangerous if the systems allows users to do a “chown”. You better set
‘secure’ at the end of your |init.vim| then.
This option cannot be set from a |modeline| or in the |sandbox|, for
Per Neovim documentation for
If the 'exrc' option is on (which is NOT the default), the current
directory is searched for two files. The first that exists is used,
the others are ignored.
- The file ".nvimrc"
- The file ".exrc"
Per Vim documentation for
If the ‘exrc’ option is on (which is NOT the default), the current
directory is searched for three files. The first that exists is used,
the others are ignored.
— The file “.vimrc” (for Unix, Amiga) (*)
“_vimrc” (for Win32) (*)
— The file “_vimrc” (for Unix, Amiga) (*)
“.vimrc” (for Win32) (*)
— The file “.exrc” (for Unix, Amiga)
“_exrc” (for Win32)
Plugins for Local vimrc
Built-in FileType Plugin
If your projects are of different languages, one good option is definitely to make sure of the built-in file type plugin (
For Vim, the folder to use is normally under
For Neovim, the folder to use is normally under
E.g. if you go to the default system
ftplugin folder (In my case is
/usr/local/share/nvim), you can see the default configurations for all file types.
Another option is to use the auto command. There are multiple ways you can use it.
You can set language-specific setting, e.g.
autocmd FileType markdown setlocal spell
autocmd FileType html setlocal shiftwidth=2
autocmd FileType php,html setlocal shiftwidth=2 expandtab
Or you can source a file if you have many settings, e.g.
autocmd FileType markdown source ~/.vim/settings/mysettings.vim
You can also centralize your settings to a folder using the auto command (
:h autocmd-pattern), e.g.
:autocmd BufRead,BufNewFile /path/to/dir/** setlocal ts=4 sw=4
Also, read this chapter from
Learn Vimscript the Hard Way to understand the pitfall of auto command, and how to avoid creating duplicate auto commands.
The EditorConfig Vim plugin supports the following EditorConfig properties:
root(only used by EditorConfig core)
From Vim/Nevom, type
:h editorconfig to get more details from the documentation once you installed it,
This plugin may not allow you to manually configure project-specific settings. vim-sleuth automatically adjusts
'expandtab' heuristically based on the current file, or, in the case the current file is new, blank, or otherwise insufficient, by looking at other files of the same type in the current and parent directories.
projectionist.vim provides granular project configuration using “projections”.
Let’s see a trivial example to set a color scheme for a project.
Create a file called
.projections.json in a folder with the following content.
Projectionist will detect this file and set a buffer-local variable (
b:projectionist) whenever an HTML file is loaded.
Using the dofiles I developed in my previous article, create a
plugin/projectionist.vim file with the following content.
autocmd User ProjectionistActivate call s:change_colorscheme()
augroup ENDfunction! s:change_colorscheme() abort
let l:colorscheme = projectionist#query('colorscheme')
if len(l:colorscheme) > 0
execute 'colorscheme '.l:colorscheme
Restat Vim/Neovim, and now if you open or create an HTML file in the folder the color scheme will automatically change to
Projectionist also has features that make navigating project easier.
E.g. with the following
.projections.json which describes my project structure, I can navigate the project files easily.
test_utils.pywill be loaded.
utils.pywill be loaded.
users.pywill be loaded.
You have various options to open the file in split, tab, etc. Type
:h projectionist to look at the documentation.
If you are looking for a Lua-based plugin you can try out vim-projectconfig.
Do also check out the following articles!
Neovim — Debugging Application