[copy paste of the answer given on SO...]
Install lh-brackets it already detects the context to not expand anywhere. It also adds a placeholder after the closing brackets. If you directly install lh-cpp, the control statements will also be context aware.
(I must admit your request is quite surprising as nobody seems to use placeholders any more. And yet lh-brackets is the plugin that (re-)introduced this concept (idea stolen from Stephen Riehm's original bracketing macros). Then mu-template used a similar bracketing philosophy, and finally latex-suite did as well. BTW, lh-brackets should be compatible with an installed version of latex-suite)
NB: for the ones that absolutely want to define the mappings themselves, look at the
Map*Context() functions from lh-brackets. The first version recognized comments and string contexts to not expand the key. The last version (
Map4TheseContext()) permits to specify how the key should be expanded for a list of possible contexts.
The idea is to test the context with
synIDattr(synID(line('.'),col('.')-1,1),'name'), then to interpret possible special character sequences like