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
Venters visual line mode and highlights the entire current line- Move the cursor with
jorkto 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 charactersV(uppercase) — line-wise visual mode, selects entire lines<C-v>— block visual mode, selects a rectangular column of text
Tips
- Use
Vjto select two lines,V2jto 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:sortto sort three lines - Press
gvto reselect the last visual selection after exiting visual mode - Use
VGto select from the current line to the end of the file - Use
Vggto select from the current line to the beginning of the file