MikeJerome
MikeJerome

Reputation: 660

Vim how can I move text into a set of parentheses?

In Vim, this has been happening to me and I'm wondering the best way to handle it. Example:

something(|)something, else // pipe is the cursor location

I'd like to end up with this:

something(something, else)

I'd also like to be able to do this:

something(something) else _// in case I only want the first word

Upvotes: 1

Views: 130

Answers (2)

René Nyffenegger
René Nyffenegger

Reputation: 40489

I assume the pair of paranthesis has no space in between so that it looks like ()word, another-word etc etc. Then

d EEp

changes it into (word, another-word) etc etc.

The d initiates a delete. The following space tells vim how much you want to delete: one character (this is the )). An E jumps over a word. So, the double EE jumps over two words. With the final p you insert (paste) what you have deleted (that is the )).

Upvotes: 1

romainl
romainl

Reputation: 196476

Assuming you are in insert mode:

" first example
<Del><S-Right><S-Right><S-Right>)

and:

" second example
<Del><S-Right><Del>)

Assuming you are in normal mode, with the cursor on the closing parenthesis:

" first example
x$p

and:

" second example
xeplx

Upvotes: 2

Related Questions