DEV Community

Cover image for Reapply the Previous Visual Selection in Vim
Josh Branchaud
Josh Branchaud

Posted on

3 3

Reapply the Previous Visual Selection in Vim

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.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay