I'm using the following key binding to visually select the current paragraph.

nnoremap <leader>v }kV{j

Is works as follows:

  1. } Move below the current paragraph.
  2. k Move one line up.
  3. V Start line-based visual selection.
  4. { Move above the current paragraph.
  5. j Move one line down.

This works well except for the last paragraph in the file. If there is no empty line below the current paragraph } stops at the last line inside the paragraph. The following k results in the last line of the paragraph not being included in the selection. The same problem occurs with the very first paragraph in the file.

How can I make this key binding to also work for paragraphs at the top of bottom of the document?

Is there a text object for this?

1 Answer 1



You are looking for the built in vip.

Also, :h text-objects is a good start to find the text objects you are looking for.

Edit To address your comment: to move the cursor to one end or the other end of the current visual selection you can simply use o in visual mode.

:h v_o

  • Awesome, I tried vi{ but not vip. Can you think of a way to make the cursor end up at the start of the paragraph as in my key binding, rather than at the end?
    – danijar
    Commented Feb 22, 2018 at 12:20
  • 2
    @danijar o in visual mode moves the cursor to the other end of the current selection, so vipo
    – statox
    Commented Feb 22, 2018 at 12:22
  • 1
    Learned a lot, thanks. May not even need a macro for that.
    – danijar
    Commented Feb 22, 2018 at 12:25
  • @danijar Indeed that is clearly not worth a macro nor a custom mapping :)
    – statox
    Commented Feb 22, 2018 at 12:26
  • This command serves to select the current SQL query if the query is separated from other queries by carriage returns
    – Angel
    Commented Jan 4 at 8:36

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.