Editing visual selections

4.4
(232)

Visual selection is a powerful tool for applying commands to specific regions of a buffer. But it can be frustrating to have selected the wrong portion and need to start your selection over. Many times I’ve had to hit <Esc> and restart a visual selection because I realized my selection didn’t start at the right point. But this frustration can be easily remedied by making use of o:

  • Pressing o while visually selecting moves the cursor to the opposite end of the selection.

Instead of pressing <Esc> and starting over, I can press o to move the cursor back to the beginning of the visual selection. From there, I can use the usual suspects to adjust the beginning of the visual selection. For example j or k, or <C-u>, or perhaps ?^3. If I want to get back to the bottom of the visual selection and select more, I can press o to bounce to the other end. This trick has remedied a frustration I’ve long had with using visual mode.

Check out the gif at the bottom of this message. In it, I incrementally select some text that I wish to move to the left. But I missed the first few lines, so I press o to move my cursor to the back of the selection, then press k to adjust the top boundary.

How useful was this tip?

Average rating 4.4 / 5. Vote count: 232

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Andy Libby

36 Posts

Rider of bicycles. Writer of code. User of Vim.
View all posts