1

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.
6
  • 1
    xf1p will save you a little trouble. I would strongly suggest you get out of the habit of being in input mode. That is, rather than thinking of your first step being 'escape to normal mode', think of it as being normal to be in normal mode, and using i,I,a, or A to enter insert mode only to enter text, followed by <esc> to exit insert mode. Commented Mar 17, 2015 at 16:00
  • ack, i deleted the words 'normal mode' from the post. <esc>xf1p is marginally better but i'm looking to do less. Commented Mar 17, 2015 at 16:05
  • @evolution - Then make it a macro? Commented Mar 17, 2015 at 16:06
  • "move the second bracket a word forward.": That's just xwp. Commented Mar 17, 2015 at 16:06
  • 2
    I recommend surround plugin Commented Mar 17, 2015 at 16:06

1 Answer 1

2

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)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.