Visual and select mode

Vim's visual mode allows for an arbitrary selection of text (usually to perform some sort of operations on). It's useful when you want to work with a section of a file that does not map to an existing text objects (word, sentence, paragraph, and so on). There are three ways to enter visual mode:

  • v enters a character-wise visual mode (status line text: -- VISUAL --)

  • V enters a line-wise visual mode (status line text: -- VISUAL LINE --)

  • Ctrl enters a block-wise visual mode (status line text: -- VISUAL BLOCK --)

Once you enter visual mode, you are able to move your cursor using the usual movement commands, which would expand the selection. In the following example, we've entered a character-wise visual mode and moved the cursor by three words and one character to the right (by executing 3e and then l). You can see animal_farm.add_animal() being selected in visual mode:

You can control the selection by doing the following:

  • Pressing o to go to the other end of the highlighted text (hence allowing the selection to expand from the other side)
  • Pressing o when in block-wise visual mode to the other end of the current line

After you're satisfied with the selection, you can run a command you'd like to execute on a selection. For example, hit d to delete the selected text:

In the preceding screenshot, Vim is back to normal mode (-- VISUAL -- is not in a status line anymore), and the selection has been deleted. You can always hit Esc to come back to normal mode without making a change.

Text objects become a powerful tool when used in visual mode. See Utilizing Text Objects in Chapter 2Advanced Editing and Navigation, for more information.

Vim also has a select mode, which emulates selection mode in other editors: pressing any printable character immediately erases the selected text and enters the insert mode (so the usual movement commands don't work here). Just like the ex mode shown before, select mode has a very specific and limited set of uses. In fact, I have never used it myself, except for when doing research for this book.

You can enter select mode by pressing gh from normal mode or Ctrl from visual mode and exit it by pressing (you guessed it) Esc.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.96.61