article is kind of lame. Why call
it the Capital-G Command.
Surely it would make more sense
to name the command by what it
does rather than how you do it.
I've decided to call it the Vim
Capital-G Command because this
is how I remember it. While it
makes more sense to call it the
Goto Line Number Command,
for some reason that's not what I
first chose as a search string
when I went looking for more
information on this command.
Here's the first article on the
Capital-G Command that I came
across:
The Vim
Goto Line Number Command
The article does a nice job of
explaining the command. I particularly
like the fact that the author points
out that a single Capital-G will instantly
take you to the last line of the file.
The reason I'm somewhat in love with
the Vim Capital-G Command is that I've
always used the ex editor command
for jumping to a certain line number.
For example, if I wanted to go to the
last line in a file, I would typically
type this:
:$
That's two keystrokes: colon followed by
a dollar sign. The colon accesses all the
legacy ex commands and then the dollar
sign signifies the last line in the file.
The reason I'm still using this legacy
ex command is because I've been
able to get away with it for so many
years.
It isn't until I started making heavy use
of highlighting commands (Capital-V, for
example) that using ex to go to a specific
line has become a liability.
There's no convenient way to highlight text
and then drop into an ex command
that I know of. Therefore, I really needed
to start using a pure vi command to
go to specific lines.
I've always been aware of the Capital-G
Command. I just never use it. Old habits
die hard.
This becomes cumbersome when highlighting an
entire file for cross-application copy and
paste. For example, I'll copy and paste
text files from Vim to the OpenOffice.org
text editor for formatting and printing.
Copying the entire file from Vim is so much
easier when I use the following commands:
- Bring the file up in Vim
- Make sure the cursor is on the first
line of the file (don't worry, it will be) - Type Control-V to highlight the first line
- Type Capital-G to highlight all lines
(in other words, go to the last line) - Type double-quote, plus-sign, lowercase-y
to push all highlighted text into the clip board - Switch applications from Vim to the OpenOffice.org
text editor - Paste the text from the clip board by typing
Control-V
I hate to admit it, but prior to getting a little
bit smarter about this, I'd been scrolling to the
bottom of the file rather than using the Capital-G
Command.
The lesson? No matter how well the way you've
been doing things for years works, there is always
a better way.
Another lesson is it pays handsome dividends to update
your habits once in a while.
Sometimes what used to be a good habit can erode into
a bad habit over time.
Ed Abbott
No comments:
Post a Comment