How do I reselect the last visual selection?
Answer
gv
Explanation
The gv command reselects the exact same area that was last selected in visual mode. This is incredibly useful when you need to perform multiple operations on the same block of text without manually reselecting it each time.
How it works
gvrestores the last visual selection, including the mode (character, line, or block)- The cursor returns to the same position it was in when you left visual mode
- The selection boundaries are remembered even after performing an operation
Example
Given the text:
first line
second line
third line
You select all three lines with ggVG and indent them with >. The selection disappears after the indent. Pressing gv reselects the same three lines so you can indent again with >, or perform a different operation entirely.
Tips
- Use
gvafter indenting with>or<to reselect and indent again without pressing. - After yanking a visual selection with
y, pressgvto reselect and perform another action likedorU - In visual mode, press
oto jump the cursor between the start and end of the selection — this works withgvtoo - Use
gvfollowed by:sortto sort the same lines you previously selected - If you accidentally exit visual mode with
<Esc>,gvbrings the selection right back gvremembers which visual mode was used — if you last used<C-v>(visual block),gvrestores a block selection