tags:

views:

640

answers:

5

While editing .scm files it would be great if VIM would automatically put the ending brace ")" as soon as I start "(". How do I do this?

+9  A: 

You can map the opening brace to your liking:

:imap ( ()<left>
soulmerge
Really simple and clever, made me smile.
Zsolt Botykai
The plugins mentioned in the other answers have the advantage of behaving "intelligently" when typing the corresponding closing ")". If this is not needed, then I'd also go with the straigt forward map.
Some plugins also : - don't expand within comment and string contexts, - define a way to surround the selection with a pair of brackets, - inserts a placeholder/marker in order to jump past the closing bracket (which is consistent with most snippets/templates expander plugins).
Luc Hermitte
+10  A: 

Try to use AutoClose plugin.

Mykola Golubyev
+1 Much more versatile than the accepted solution, in my opinion.
Andy
+1 I think so, too :)
soulmerge
+4  A: 

There are many tips and plugins on the subject. Have a look at the relevant entry in the vimtips site.

Luc Hermitte
+5  A: 

I needed one too, and I already tried a few of the plug-ins:

AutoClose, http://www.vim.org/scripts/script.php?script_id=1849, is a bit aggressive.

simple pairs, http://www.vim.org/scripts/script.php?script_id=2339, depends on Python. If you are on Linux it is not a problem, but on Windows it can be a trouble to match the Vim version to the Python interpreter you have.

My advice would be ClosePairs, that you can find at http://www.vim.org/scripts/script.php?script_id=2373 which has been working perfectly for me. It is simple and useful.

Caglar Toklu
+1  A: 

There is a problem with using this (via the imap or one of the scripts). You won't be able to repeat the complete edit by using the . command.

e.g. (foo) with . only gets you foo, without the brackets.

It works fine if you insert the brackets normally, as two characters.