vimsurround

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


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?


Solution

  • 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