Vim Tip: Finding a Variable Declaration
For most programming, I use Vim as my text editor of choice. It has a steep learning curve, but is very efficient once you get accustomed to it. I'm far from an expert on Vim and I'm always learning new things. From time to time I will endeavor to post about these tips so others can benefit from my learning.
Often times when editing code in a function, one runs across a variable that's type isn't immediately obvious. Here's a few navigation techniques I just discovered to help find out what the variable is:
gd - go to declaration. This starts at the top of the function/method and works down until it finds the declaration of the variable the cursor is on. Note that this will also highlight all instances of the variable, making it easy to pick it out in a crowd.
g, - go to last edit. When using something like gd, this helps you get back to where you were. g; will go forward to the "next" edit if you need to bounce between locations.
Comments
Anonymous
May 19, 2008
Heh. g; and g, are pretty handy. I've previously used `. and '. to go to the last change after I've had to jump around looking for something, but it doesn't give jump list functionality like g; and g, do.Anonymous
May 22, 2008
I use ctrl-t and ctrl-] along with tags. I'll have to try gd and g, next time.