When I am coding in c++, I want vim to expand ( into ()<++> and place the cursor in the parenthesis. I do this by putting the following line in one of the files loaded at startup:inoremap (      ()<++><Left><Left><Left><Left><Left>However, I would like this binding to be disabled in comments, like// Inline comment where ( shouldn't become ()<++>or /* Comment block where ( shouldn't become ()<++>*/How can I do it?
Define new command that works only outside c++ comments
comments;filetype c++
You can make use of expression mappings. The basic idea is to test the current syntax and only expand, if it is not a comment. That is basically what all the plugins will be hiding from you::inoremap <silent><expr> ( synIDattr(synIDtrans(synID(line('.'), col('.')-1, 'name')),'name')=~?comment?(:()<++><Left><Left><Left><Left><Left>Which means, check that the current syntax item is not of type comment and in that case replace by your ()<++> item or else replace by themselves. Note, it is probably more easier to hide that functionality behind a function that does the necessary checks.Note: to make undo and redo work properly, instead of using <Left> you should use <C-G>U<Left>, which is a relative recent addition to Vim. Read the help at :h i_CTRL-G_U