WebDevChallenges Logo
WebDevChallenges

A brief introduction to Vim (Part 4)

Updated June 5, 21
Manipulations with verbs, modifiers and nouns in Vim.

About

Here is the third (previous) part of this series: A brief introduction to Vim (Part 3)
Here is the fifth (next) part of this series: A brief introduction to Vim (Part 5)

Manipulation

As I mentioned in A brief introduction to Vim (Part 1), the normal mode in Vim can not only be used to navigate within the file but also do manipulations.

This is definitely one of the most powerful features of Vim and by practicing both navigation (as explained in A brief introduction to Vim (Part 2)) and manipulation you will become very fast and have to spend less time performing the changes on the file and have more time left to think about your next steps.

When modifying your file in Vim you can almost think about it like speaking a different language, expressing your desired action with a verb, a optional modifier and a noun.

This may sound confusing but bear with me - this will make complete sense in the example section ;).

Verbs

A verb determines what action or what kind of manipulation you want to perform on the text. The following are the most noteworthy verbs for now:

  • Change (key c): Deletes the desired part of the file (specified by modifier and noun) and then switches to insert mode
  • Delete (key d): Deletes the desired part of the file (specified by modifier and noun) and stays in normal mode
  • Yank (key y): Yanks/Copies the desired part of the file (specified by modifier and noun) and stays in normal mode

Modifiers

A modifier is optional and determines in what scope the action should be performed. The following are the most noteworthy modifiers for now:

  • Inside (key i): Performs the action inside the given noun
  • Around (key a): Performs the action around the given noun
  • Till (key t): Performs the action until (not including) the given character
  • /: Performs the action until (not including) the given phrase

Nouns

A noun determines on what element of the file the action should be performed. All navigation keys can actually be used as nouns (e.g. w - word):

  • Word (key w): Performs the action on the word, the cursor currently sits on
  • Tag (key t): Performs the action on the tag, the cursor currently sits on
  • ', ", <: Performs the action on the previous and the next symbol specified to the cursor

Examples

  • Change Inside Word (ciw): Deletes the word, the cursor currently sits on and then switches to insert mode (can also be used with a uppercase W - the behaviour is the same as in the navigation section)
  • Delete Around ' (da'): Deletes everything between (including because around) the previous and the next occurrence of '
  • Delete Till l (dtl): Deletes everything between (including) the cursor and the beginning of the next occurrence of the character l
  • Yank / foo (y/foo): Yanks everything between (including) the cursor and the next occurrence of the phrase foo
  • Delete Inside Tag (dit): Deletes everything inside of the Tag, the cursor is currently inside of
  • Delete $ (d$): Deletes everything between (including) the cursor and the end of the line the cursor sits on

More manipulations

  • Press the key of an action twice (dd, cc and yy), the action will be performed on the whole line, the cursor currently sits on.
  • Press D (uppercase), the characters from (including) the cursor until the end of the line will be deleted.
  • Press C (uppercase), the characters from (including) the cursor until the end of the line will be deleted and you will be placed into insert mode.
  • Press x, the character, the cursor is currently sitting on, will be deleted.

Copy & Paste

We covered yanking in the Verbs section so I want to mention Copy & Paste for the completeness.

After yanking something, you can insert the yanked part: * By pressing p, to Paste it after the cursor * By pressing P, to Paste it before the cursor

Ask me questions

I will be happy to answer your questions in the comments section below. Also let me know if you have any tips or ideas for me to improve my post!