iartist93
iartist93

Reputation: 335

Selection surrounding in Vim

What's the best way to surround a selected text in vim ?

e.g.

cout << this is some statement << endl;

and I want to quick surround this statement with " " to be

cout << "this is some statement" << endl;

Upvotes: 3

Views: 925

Answers (2)

romainl
romainl

Reputation: 196606

I love and use Surround but doing it with vanilla Vim is dead simple:

c"<C-r>""<Esc>

which means "change the selected text (c) to a double quote ("), then insert the content of the unnamed register (<C-r>"), followed by another double quote ("), and leave insert mode (<Esc>)".

See :help i_ctrl-r.

Upvotes: 7

L3viathan
L3viathan

Reputation: 27283

Use vim-surround for all your surrounding needs.

Once installed, if your cursor is on the "t" of "this", type yst<" to accomplish what you want:

ys<text object><type> surrounds the text object with things of the type.

Upvotes: 5

Related Questions