Sexy vim "text objects" feature
Posted Sat, 15 Apr 2006
Read about text objects in vim with
:help text-objects
Text objects are basically direction macros for simple deletion/copy/changing. For instance,
diB
This will delete everything between the nearest { and closing }. That is:
static int update() {
if (u) {
printf("Update\n");
} else {
printf("No update\n";
}
}
Paste the above code in vim. Put the cursor on the first printf (line 3) and,
in command mode, do diB - undo that and try ciB. The
d command will delete the code block, where as c will
do the obvious and delete the code block and leave you in insert mode.
These text object direction things are quite neat. Again, check out the help
page on it (:help text-objects). Neat little shortcuts.