Abbreviations override in comments and quoted text

Posted by dotancohen on Super User See other posts from Super User or by dotancohen
Published on 2012-10-14T14:48:54Z Indexed on 2012/10/14 15:40 UTC
Read the original article Hit count: 207

Filed under:

I have the following handy abbreviation in VIM:

iab for for<Space>(<Space>{{<Esc>kA<Left><Left><Left><Left><C-R>=Eatchar('\s')<CR>

This nicely replaces for with the following text:

for (  ) {

}

However, I would like this abbreviation to work only in code, not in comments or in single- or double- quoted strings. How might this constraint be accomplished?

Note that I usually code in PHP, but often enough I find myself in other C-style languages (C, Java, occasional C#, etc.). Preventing the abbreviation from working in Python would be a nice bonus though I don't mind manually turning it off in Python if that is not an option. Thanks!

© Super User or respective owner

Related posts about vim