Tuesday, June 10, 2014

Re: Having trouble grokking the g family of commands

On 2014-06-10 09:03, Chris Pickard wrote:
> Every time I discover a new command with a g prefix it makes me
> realize that I don't really understand the g prefix at all. I
> assume that the "g" means "go," like in gd it means go to
> declaration, or gg is go to top of file, and I've done :help g, but
> there is also g~, which is swap case for a motion, or ga which
> prints the ascii value of the character under the cursor.
>
> 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.

I think you've got most of it. In traditional vi, there was no "g"
command, so a large number of things got overloaded into one prefix
character. Much of them suggest (as you discern) the idea of "go"
such as

gd/gD = go to the definition
gg = go to the top of the file
gf/gF = go to file
go = go to a particular byte offset
gm = go to the middle-of-the-screen column

Some of them suggest "do the following behavior but modify it in
some way". These would include

gI = insert at the beginning of the line at column 1 rather than
before the first character of the line
gh/gl/gk/gj/g^/g$ = move screen line rather than file line
g*/g# = search for the word under the cursor, but don't force
word-boundary matching
g' = go to mark without modifying the jumplist
gJ = join lines without modifying spacing
gp/gP = paste but put the cursor at the end

You also have text transformations: gq, g?, g~, gu, and gU.

However, as it's a bit of a catch-all, there's a mishmash of other
stuff crammed under that prefix. The above three categories allow
me to clump much of the "g" functionality, and I only use a small
subset of the other g{whatever} commands in my day-to-day (i.e.,
non-vimgolf) usage.

-tim










--
--
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