DEV Community

Cover image for Reapply the Previous Visual Selection in Vim

Reapply the Previous Visual Selection in Vim

jbranchaud profile image Josh Branchaud ・1 min read

Visual selections in Vim are powerful because they allow you to visually define a sub-context for all kinds of commands. Defining a precise visual selection can be important to making surgical changes.

Have you ever carefully defined a visual selection, had to back out of it to do something else, and then carefully re-define that same visual selection?

It's not a big deal, but as Vim users, we try to make every keystroke count. To this end, Vim has a way of reapplying the previous visual selection, which I cover in an episode of Vim 🔥 Tips and Tricks.

Hitting gv, from normal mode, will put you back into visual mode with the same bounds as the previously defined selection. See :h gv.

Vim is able to do this because it keeps track of the bounds of your previous visual selection using the < and > marks.

There is more where that came from. If you enjoyed this post and screencast, subscribe to my newsletter and check out the rest of the Vim 🔥 Tips and Tricks series.


Editor guide