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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -