VIM’s got a lot of helpful commands that start with g. Not sure why g,
of all letters, but there you are.
One that I find really helpful when running through Apache
configurations is gf. If you put your cursor over the path to a file
and type:
gf
VIM will open up the file that’s under your cursor. So, given a vhost
like the following:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName example.com
</VirtualHost>
If you put your cursor over /var/www/html and type gf, VIM will open up
a directory listing of that directory. Or, if you’ve piped the output
of httpd -S to a file and you put your cursor over the path to a
particular virtual host’s configuration file, you can open it up in the
same way. Note that if you’ve updated the current file and it hasn’t
been written to disk yet, VIM will complain that the current file hasn’t
been saved yet and gf will fail.
Another handy use of g is when you’re editing a file with wrapped
lines. Ever find yourself on a line that is wrapped, and you want to
make a change that’s right below the cursor, so you type j or hit the
down arrow, but the cursor skips right past what you want and goes to
the next line? Don’t you just HATE that? Well, if you type gj or
g<down arrow> instead, the cursor will move according to displayed
lines, not logical lines. Much better.
Finally, my favorite stupid VIM trick. g? will ROT-13 text. Use the
ggVG sequence to highlight your entire file. Then type:
g?
And presto – every alphabetic character is shifted 13 places to the
right in the alphabet. Quick and easy obfuscation.
Happy VIMming!
- David Roth



Comments on this entry are closed.