Daily Vim Devotional
i for inside, a for around

Two useful keys to remember are i and a. You can combine them with d, c, and other commands to manipulate text “inside” and “around” different markers.

For example, say you had a line of text like this:

someMethod('some arg|ument');

…(where | is your cursor position in normal mode) and you wanted to change the argument to an empty string. You’d just type di', for “delete inside single-quotes,” leaving you with this:

someMethod('');

But, you ask, what if you wanted to remove the argument entirely? Instead of i, use a for around—da':

someMethod();

There’s another way you could have accomplished the same, though—`di(`, or “delete inside parentheses.

Furthermore, you can combine this with other operators like w:

someMethod('some ');  // diw (delete inside word)
someMethod('some');   // daw (delete around word)

i and a can be combined with other commands, to mostly obvious effect. yi' would yank some argument, whereas va' would highlight 'some argument' (including the single-quotes) in visual mode. ciw would delete the word argument and switch to insert mode, putting the cursor after the space following some.

I love i and a because they’re so versatile and, with the “inside and around” mnemonic, so easy to remember.

  1. napszemuvegbe reblogged this from dailyvim
  2. dailyvim posted this
blog comments powered by Disqus