Tuesday, June 10, 2014

Re: Having trouble grokking the g family of commands

Chris Pickard wrote:
> Can anyone explain the language of the g family of commands to me? It
> seems like there are a lot of random, really useful things in there that
> I just can't discover because it doesn't seem to follow a pattern to me.

That's it, you've figured it out.

Begin history lesson.

In traditional vi, 'g' doesn't have any commands associated with it.
There are not a lot of characters for which that is true. So when new
commands were added to vim, there were not a lot of options for how
to fit them in. The solution was "make a bunch of them start with g".

Off hand, I believe the single characters that were NOT assigned
command-mode meanings in vi are:

#
*
\
q
g
K

Plus some control keys, which I confess I learned very few of in my
pre-vim days. You could argue that # does have a meaning in vi, since
some implementations use it for triggering function keys on terminals
that lack fuction keys: <#><4> for <F4>.

(I think "*" might have had a meaning if autoindent and lisp mode
were enabled, but not otherwise.)

In vim, #, *, q, g, and K have all been given meanings. I don't know
why "g" was selected to use for such a slew of multi-character commands,
but I recall it happening around the time of the vim 3 to vim 4
transition. I recall the change because the old 'Q' command became 'gq'
when vim finally added a real ex mode and needed the vi 'Q' command back.

Some characters only had meaning as part of multicharacter sequences.
The 'Z' only has a meaning in the context of 'ZZ' in traditional vi,
vim adds 'ZQ'. Also, there are a lot of '[' and ']' movement commands
in vim, but only a very few in vi.

Here ends the history lesson.

Elijah

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment