Step 4 of 5

4. Basic Editing

Deleting within special characters

A few characters are normally intended to “capture” things. For example: ", (), {}, and [] are typically intended to delimit something. In written language, quotes are used to capture what a person is saying, and parentheses are used to insert additional information into text. If you’re a software engineer, you will have also seen {} and [] used to capture chunks of code.

Vim understands these constructs. In Vim parlance, we have text objects representing the content that is grouped by certain characters. We can perform operations on them.

This is when most people start to glimpse at the true power of Vim, so hold on to your hats!

We can use di" in normal mode to delete everything inside quotes. We can similarly use di(, di{, and di[ to delete everything inside parentheses, braces, and square brackets respectively. Note that you have to be inside the quotes/parentheses/etc for these commands to work. The mnemonic here is “delete inside something

The editor has some examples of these text constructs — work through the checklist below to try each command.

  1. Delete inside the quotes Put the cursor anywhere inside the quoted string, then type di".
  2. Delete inside the parentheses Move inside the ( ) pair and type di(.
  3. Delete inside the square brackets Move inside a [ ] pair and type di[.
  4. Delete inside the braces Move inside the { } pair and type di{.
Delete inside the quotes Put the cursor anywhere inside the quoted string, then type di".

Next: Delete inside the parentheses

Loading editor…