Tuesday, July 11, 2006

Cool gvim trick for marking

You know how you edit some code at line 10, then move to line 30, and forget where you were originally (line 10)? There is a gvim command for taking care of this. You can use markers. In line 10, you can (in command mode) type ma to mark the position with identifier 'a', and now after editing line 30, you can type 'a to move back to line 10 (marker a). Markers are also useful for deleting lines between two markers and so on.
But, it so happens if you create too many markers, you will forget that marker 'a' is actually line 10. More problems!

The solution - Ctrl-i and Ctrl-o can be used in gvim to move around the last places you edited. Thus, saving you from marking everyplace you edited.

Of course markers are still needed, when you want to delete lines between two markers, or search and replace between them.

e.g.
d'a - delete from current position to mark a

:'a,'b d -delete all lines between markers a and b
:'a,'b s/ef/cd -you know what this means

No comments: