Jonas Geiregat
Jonas Geiregat

Reputation: 5442

Enclose quotes, parentheses, etc. in Vim

I would like to make Vim behave in the following way.

When I type a ", ', (, [ or { it should add an extra ", ', (, [ or { and move the cursor back one character.

So if I type "▉ I would love to see it automagically change that into "▉", where shows position of the cursor.

Upvotes: 1

Views: 368

Answers (4)

Jonas Geiregat
Jonas Geiregat

Reputation: 5442

After fiddling around, I found that a plugin for such a feature would be overkill.

I've setup my vimrc as such:

inoremap { {}<C-o>i

I've also added:

inoremap <C-l> <C-o>A
inoremap <C-L> <C-o>A<Space> 

So I can quickly jump outside of the parentheses and start typing again, with our without an extra space.

Upvotes: -2

Luc Hermitte
Luc Hermitte

Reputation: 32966

lh-brackets provides both the insert mode mappings and the surrounding mappings. If you want to use it for a filetype that I don't work with, you may have to add your specializations -- which is meant to be easy.

Upvotes: 2

romainl
romainl

Reputation: 196751

There are many plugins for that. Did you search vim.org's plugin repository before asking?

You could also do something like:

inoremap { {}<C-o>h

Upvotes: 5

wholerabbit
wholerabbit

Reputation: 11566

The surround plugin might work for you:

http://www.vim.org/scripts/script.php?script_id=1697

Upvotes: 0

Related Questions