Chapter 10.Table of ContentsCheatsheet

Selecting Text in Visual Mode

Visual Mode is the Vim equivalent to selecting text with a mouse. But instead of a using a slow mouse, you’ll select your text by relying on the speedy Vim motions. As you select text in Visual mode, Vim will highlight your selection providing a visual aid. This visual feedback makes Visual mode specially useful whenever you feel the need to be extra precise before performing an action.

There’s three ways in which you can start Visual mode:

Visual mode commands
  • v for visual mode character-wise. This mode lets you select text character by character
  • V for visual mode line-wise. This other one lets you select text line by line
  • <C-V> for visual mode block-wise. This last mode lets you select text using rectangular blocks

Visual mode can be very helpful for copying and pasting stuff and when operating on blocks of text or code where you feel you need that extra visual feedback. It works in the opposite way of Normal mode. In Normal mode you first define the operator and then a motion that represents some text to which to apply that operator:

{operator}{count}{motion}

In Visual mode, however, you select the text first and then you type the operator:

{trigger visual mode}{motion}{operator}
Visual mode is opposite to Normal mode

So, in order to delete the following two lines:

lines filled with mambo jambo.
that totally deserved to be deleted from existence.

You could either type d2s in Normal mode or:

  1. Go to line-wise visual mode with V which selects the current line
  2. Press j to go down one line and thus selecting it.
  3. Now you’ve selected both lines you type d and they’re gone. Forever. Bye lines of text. You lived a good life. not-really

Visual mode is often slower than using commands directly in Normal mode but you’ll have that extra visual aid that gives you assurance that you’re applying a command exactly where you want it applied.

Use Visual mode when confronted with tricky situations

  1. They aren’t really gone for ever. Vim has a thing for resurrecting deleted text. You’ll learn about it soon. Exciting!

Jaime González García

Written by Jaime González García , dad, husband, software engineer, ux designer, amateur pixel artist, tinkerer and master of the arcane arts. You can also find him on Twitter jabbering about random stuff.Jaime González García