16

How does one select from the current line to the next empty line?

I'm aware of SHIFT+V but then I have to either jump to the next empty line or press the down key a bunch of times. I know how to do this well when there's a matching character like a } but I have no idea how to do this for an empty line.

0

3 Answers 3

27

Vim understands the concept of a "paragraph". Vim's definition of a paragraph is a block of text surrounded by blank lines*. There are several motions and text objects to work with this.

  • [count]} – Move [count] paragraphs forward. You can use <S-v>} to select all lines from the current line to the next blank line. This will include the blank line, so you may want to use <S-v>}k.
  • [count]ip – Select [count] paragraphs. It's like iw (inner word) except for, well, paragraphs. Using vip will select all of the paragraph though, rather than from the current line to the end of the paragraph.
  • [count]ap – like ip, except that this will include the blank lines surrounding the paragraph.

One caveat here is that Vim doesn't consider a line with only whitespace as a "blank line". So make sure to check this (e.g. with :set list) if it doesn't appear to work.


Also remember you can always search for the pattern you want. You can get an empty line with /^$; or if you don't want to select the empty line itself you can use \n\n to put the cursor at the end of the line before the first blank line:

  • <S-v>/^$<CR>
  • <S-v>/\n\n<CR>

* There are some exceptions, see :help paragraph for the full logic. But for most intents and purposes this definition works fine.

0
18

A shortcut for next empty line is }. So you just might want to use SHIFT+v}

0
0

Simply pressing Shift + } will take to next empty line without any text selection.

With Sift + v + }, vim selects the text from current cursor position to next empty line and you have to Press ESC to exit from selection mode

2
  • Why Shift + }? A simple } does the move. See other answers.
    – Ralf
    Commented Jan 22, 2019 at 20:44
  • @Ralf Sift + } to invoke/enter the curly bracket } unless your keyboard directly supports inserting } without pressing Shift
    – Junaid
    Commented Jan 23, 2019 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.