Context-specific remap

Posted by dotancohen on Super User See other posts from Super User or by dotancohen
Published on 2012-10-31T10:45:21Z Indexed on 2012/10/31 11:04 UTC
Read the original article Hit count: 207

Filed under:

I have the following handy VIM map:

inoremap ( ()<Left>

However, sometimes I will enter Insert mode to add a function call around a variable, like so:

Was: $sql = "SELECT * FROM " . $someTable;
 To: $sql = "SELECT * FROM " . mysql_real_escape_string($someTable);

The mapping makes a redundant ) after mysql_real_escape_string(. Is there any way to refactor the mapping so that if there exists a character after the cursor, and the character after the cursor is not whitespace, then )<left> is not appended to (?

Thanks.

© Super User or respective owner

Related posts about vim