Vim Text Selection Trick

I just learned some techniques from my friend today.

Say we have the following text:

  NSString* text = [NSString stringWithFormat:@"This is a string %@", self.title];

First trick

If I wanted to do something with the string within “, I can do it easily with Vim using this pattern in command mode.


The thing to do first is to move the cursor within the “.

Next, follow the above command pattern.

The first set of command <c|v|d|y> indicates the action you want to perform.

  • c: for making a change
  • v: for selection
  • d: for delete
  • y: for copy

The second set of command <a|i> indicates the scope of selection.

  • a: cover the string between the input character including the input character (“ here).
  • i: cover the string between the input character excluding the input character (“ here).

The last one is the character you want, which is “ here.

Second trick

If you want to select “With” from “stringWithFormat”, you can do it by moving the cursor to “W”, then use [h]. This means, enter visual mode, and make a selection until the first met “h”.

Side trick

To quickly move to “W” in the last question, it’s easily done by using [W]. This means to find the first occurence “W” on the left side of cursor.