Reputation: 7941
In a *.c file in gVim, when I type for(
I want Vim to generate rest of the basic for loop structure as below.
for(;;)
{
}
I have achieved this with the help of the following abbreviation in _vimrc.
ab for( for(;;)<CR>{<CR>}
But, I want this abbreviation to be active only in a c
file.
Is there a condition I can use in _vimrc
so that the abbreviation is disabled in all the files but in *.c file?
Upvotes: 2
Views: 118
Reputation: 10541
One good way to achieve this with vim is by the use of autocommand
, for instance with:
autocmd FileType c abb <buffer> for( for(;;)<CR>{<CR>}
autocommand
is really powerful, and the documentation is quite good.
In this example, be careful to use abb
with the <buffer>
parameter, since you want this abbreviation to be active only on the c source file buffer. See abbreviate-local documentation for example.
Upvotes: 1
Reputation: 42218
This feature is usually called "snippets".
It is supported by various Vim plugins like SirVer/ultisnips
Upvotes: 6