Is it possible to do conditional abbreviation in vim? -
i have following abbreviation in .vimrc
:
:iab stdio #include <stdio.h>
is possible make substitution occur when stdio
not preceded <
, if paste in code has line #include <stdio.h>
, not expand following?
#include <#include <stdio.h>.h>
there might easier way heres did.
function! insertheader(replacement, mapping) if getline('.')[col('.')-len(a:mapping)-2] != '<' return a: replacement endif return a:mapping endfunction iabbrev <expr> stdio insertheader('#include <stdio.h>', 'stdio')
i used function checks see if mapping preceded <
if return mapping. if isn't return return replacement. return value gets replaced.
rereading question seems pasting code in. before pasting use
:set paste
this stops of abbreviations activating. after pasting use
:set nopaste
(or use :set paste!
toggle it)
Comments
Post a Comment