Vim autocmds: Inserting default code
How to setup mappings and default snippets for your source file
Today, I worked on setting up Vim for
d programming (Whole other story),
when I got to my autocommands.
For those of you that don't know what an
autocommand is, it is a Vim command that is ran on the target.
A autocommand has this form:
autocmd target filename_regex command
While writing this, I made this one:
autocmd BufWrite \*.md !grip % -b
You can make a groups of autocommands.
The syntax is:
augroup name autocmd! " Clear all command autocmd * * * augroup END
To make Vim insert a template text for a file
Make a dir,
For the language you want, (I'll use C), make a file named ~/.vim/defaults/c
In your Vimrc:
augroup c autocmd! autocmd BufNewFile *.c r~/.vim/defaults augroup END