Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a whole line for as a motion in Vim?

Tags:

vim

surround

I recently started to use the "surround" plugin. I realized I don't know how to surround the current line. I mean, ysap<p> surrounds a paragraph and ysaw<p> surrounds a word. Apparently dw deletes a word and das deletes a sentence. dd deletes a line, however, the second d is not a selection I'm afraid. So ys??<p> for a line?

like image 881
huoenter Avatar asked Dec 18 '17 04:12

huoenter


2 Answers

What you are looking for is the _ movement.

Ryan's answer is also right, dd is a easier to type version of d_ and a lot of commands have this optimization.

As it turns out, surround.vim has it too (thank you Ryan!) and cheats a bit.

As you can see with :h _ it does actually not refer the current line, but the first non-blank character on the [count] -1 line downwards. This is the behaviour dd etc. uses. But isn't really what we want in your usecase, ys_ will actually give you this:

"
line
"

Instead of this:

"line"

So the surround.vim plugin "cheats" a bit, by implementing a yss command which does not work like dd, cc or yy but works for the usecase it has.

So to answer the question as in the title: _ is the general solution.

If you are just looking for surround.vim use Ryan's answer

like image 81
Doktor OSwaldo Avatar answered Oct 19 '22 12:10

Doktor OSwaldo


Repeat s (yss), like cc, dd, yy.

like image 28
Ry- Avatar answered Oct 19 '22 10:10

Ry-