views:

284

answers:

3

Hello Everyone!

This is my first post on stack, so please bear with me.

I'm a C# developer who has just recently decided to expand my knowledge of the tools available to me. The first tool I've decided to learn is Vi/Vim. Everything has been going well so far, but there are a couple of questions I can't seem to find the answer to:

1) Lets say I wanted to yank a range of lines. I know there are many ways of doing so, but I would like to do it by line number. I figured it would be similar to how the substitute commands work, something like 81,91y. Is there a way to do this?

2) I'm a little confused about the g command in normal mode. It seems to do a myriad of things and I can't really determine what the g command does at its core. I'm confused on whether or not it's a motion command or a kind of "catch all" for other commands ran through normal mode. Can someone please explain this or point me to a reference that gives a good explanation of the g command?

Thank you all in advance, this is a wonderful community and I know I will not be disappointed in the response.

+5  A: 

yank lines 81-91

:81,91y<enter>

my only use of "g" is 5gg. To go to the 5th line. 22gg: 22nd line. As jimbo said, it's really only a modifier for some other commands.

For completeness, (http://vim.wikia.com/wiki/Power_of_g) explains a lot of how g works in command mode.

hometoast
Wow, that was fast! I didn't try doing it from command mode, duh! Thank you very much for the quick response.
jnadro52
Using capital letters provides variations, too: `gg` will go to the first line, while `G` will go to the last. Also, `5G` goes to line 5. Marks can be used in lieu of line numbers also (good for macros), ie: `:'a,52y`
NVRAM
you can also do :5 in command mode to go to line five, etc
rmeador
+3  A: 

g doesn't do anything by itself. It's one of a couple meta-commands that holds a bunch of sorta-unrelated commands.

z is another one.

Jimbo
Thank you. I understand now that it's just used for different purposes. When I try to learn these tools, I try to associate the commands with something I can abstract so that I remember how to properly use it. It seems like the g command is just one of those things that you need to memorize to use properly.
jnadro52
+2  A: 

Vim's :help index describes g as:

|g|             g{char}            extended commands, see |g| below

Scroll down (or :help g) for a list.

Matthew Slattery
I was familiar with the :help but I was NOT familiar with :help (command). That will be very useful in the future. Thank you kindly, sir.
jnadro52