vimtricks.wiki Concise Vim tricks, one at a time.

How do I select an entire line in visual mode?

Answer

V

Explanation

The V (uppercase) command enters visual line mode, which selects the entire current line. As you move the cursor up or down, entire lines are added to the selection. This is the fastest way to select one or more complete lines for copying, deleting, indenting, or other operations.

How it works

  • V enters visual line mode and highlights the entire current line
  • Move the cursor with j or k to extend the selection by whole lines
  • Any operator you apply will affect the full lines in the selection

Example

Given the text:

first line
second line
third line
fourth line

With the cursor on second line, pressing V selects the entire second line. Pressing j extends the selection to include third line. Now pressing d deletes both lines, leaving:

first line
fourth line

The three visual modes

  • v (lowercase) — character-wise visual mode, selects individual characters
  • V (uppercase) — line-wise visual mode, selects entire lines
  • <C-v>block visual mode, selects a rectangular column of text

Tips

  • Use Vj to select two lines, V2j to select three lines, and so on
  • Press > to indent the selected lines, < to unindent
  • Press = to auto-indent the selected lines
  • Press : while in visual line mode to run an Ex command on the selected range (Vim auto-fills :'<,'>)
  • Use Vjj:sort to sort three lines
  • Press gv to reselect the last visual selection after exiting visual mode
  • Use VG to select from the current line to the end of the file
  • Use Vgg to select from the current line to the beginning of the file

Next

How do I edit multiple lines at once using multiple cursors in Vim?