vimtricks.wiki Concise Vim tricks, one at a time.

How do I override plugin or filetype settings that load after my vimrc?

Answer

~/.vim/after/ftplugin/{filetype}.vim

Explanation

Vim's after directory (~/.vim/after/) loads scripts after all plugins and standard runtime files. This lets you override any setting that a plugin or filetype plugin sets without modifying the plugin itself.

How Vim loads files

  1. ~/.vimrc — your config
  2. ~/.vim/plugin/ — plugin files
  3. $VIMRUNTIME/ftplugin/ — built-in filetype plugins
  4. ~/.vim/after/ftplugin/ — your overrides (loaded LAST)

Override filetype settings

Create ~/.vim/after/ftplugin/python.vim:

setlocal tabstop=4
setlocal shiftwidth=4
setlocal expandtab
setlocal colorcolumn=88

Create ~/.vim/after/ftplugin/go.vim:

setlocal noexpandtab
setlocal tabstop=4
setlocal shiftwidth=4

Override plugin settings

Create ~/.vim/after/plugin/overrides.vim:

" Override any plugin's mappings or settings
silent! unmap <leader>x
nnoremap <leader>x :MyCustomCommand<CR>

Directory structure

~/.vim/after/
  ftplugin/
    python.vim    " Overrides for Python files
    go.vim        " Overrides for Go files
    javascript.vim " Overrides for JavaScript files
  plugin/
    overrides.vim " Global overrides for plugins
  syntax/
    python.vim    " Syntax highlighting overrides

Tips

  • Use setlocal (not set) in ftplugin files — set affects all buffers
  • The after/ directory is guaranteed to load after everything else
  • This is the proper way to fix filetype settings — not autocmd FileType hacks
  • In Neovim, the path is ~/.config/nvim/after/
  • Check load order with :scriptnames to verify your after files load last
  • Documented under :help after-directory

Next

How do I run the same command across all windows, buffers, or tabs?