tags:

views:

57

answers:

2

I want to try the following things in vim insert mode:

  • to have closing bracket/parenthesis inserted (after the cursor) every time I type the opening one

  • to have #{} inserted whenever I type # inside "" (optionally, inside %() too)

I know it is possible, but my competence in this part of vim does not even reach the self-starter level.

+2  A: 

This script will do the first one (auto inserting the closing bracket and placing the cursor between the brackets.)

mikej
Thanks! That solves almost all of it.
artemave
+1  A: 

lh-brackets helps define brackets related mappings. It also provides a few functions aimed at defining context-sensitive mappings and abbreviations (see Map4TheseContext).

If in ruby %() is associated to a syntax highlighting, Map4TheseContext will also solve your last request. If not, you'll have to play with searchpair() to detect the current context. Let me know if you have troubles to come up with a working solution.

Luc Hermitte