evolution
evolution

Reputation: 4742

vim move position of the closing bracket

Editing in Vim I often find myself in a situation where I want to move the position of a closing bracket.

e.g. First i type

if a == 1 then

Then I realize I really wanted to have brackets around the 'a == 1' part so I go back and put a bracket in and end up with

if ()a == 1 then

I'm using auto-pairs plugin so the paired bracket is correctly generated.

My question is, what is the quickest way to get this to look like:

if (a == 1) then

For example currently I might

  1. escape
  2. use x to delete the second character
  3. f1 to move to the 1
  4. a to append and type ')'

It seems like there should be a way to

  1. escape
  2. move the second bracket a word forward.

Upvotes: 1

Views: 478

Answers (1)

Luc Hermitte
Luc Hermitte

Reputation: 32966

With lh--brackets, you would simply have to select a == 1 and press (.

The surround plugin have similar mappings (they require several keys pressed, but they follow more the vim spirit).

If you really want to stay in insert mode, you can press CTRL-V twice, once before pressing (, then before ).

You can also select a == 1, and type s(^R"). (^R is for CTRL-R)

Upvotes: 2

Related Questions