vim Configuring Vim Autocommand groups

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

  • Autocommand groups are good for organization but they can be useful for debugging too. Think of them as small namespaces that you can enable/disable at will.

Example

augroup MyGroup
    " Clear the autocmds of the current group to prevent them from piling
    " up each time you reload your vimrc.
    autocmd!

    " These autocmds are fired after the filetype of a buffer is defined to
    " 'foo'. Don't forget to use 'setlocal' (for options) and '<buffer>'
    " (for mappings) to prevent your settings to leak in other buffers with
    " a different filetype.
    autocmd FileType foo setlocal bar=baz
    autocmd FileType foo nnoremap <buffer> <key> :command<CR>

    " This autocmd calls 'MyFunction()' everytime Vim tries to create/edit
    " a buffer tied to a file in /'path/to/project/**/'.
    autocmd BufNew,BufEnter /path/to/project/**/* call MyFunction()
augroup END

See :help autocommand.



Got any vim Question?