How do you select text in vim?

In vim, text is selected by entering Visual mode. This can be done in multiple ways.

  • v (lower case v) begins regular Visual mode, and works similar to selecting text with a mouse. Use h and l to expand the selection left and right to include more words, and use j and k to expand the selection to the lines below and above.
  • V (upper case v) begins linewise visual mode. This selects entire lines of text at a time. Use j and k to expand the selection up and down.
  • Ctrl+v(lower case v) enters block visual mode. This selects text in a block format, allowing you to select parts of multiple lines without including the entire line. Use hjkl as usual.
  • As @FDinoff suggested, if your terminal emulator supports it, you can even specify visual selections with the mouse by enabling mouse input with :set mouse=a.

Once you have selected the text you want, you can use all sorts of commands on them. Some of the more useful ones are:

  • Escape visual mode
  • delete the text
  • yank (copy) the text
  • paste your clipboard onto the text, replacing it
  • change the text, which deletes it and sets your cursor for typing
  • replace the text with the next character you type
  • yq/p search for the text elsewhere in your document

You can learn more about Visual mode by typing :help v while inside vim.

Leave a Comment