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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

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

Okay