Wednesday, November 4, 2009

Beginning and End of a Buffer

Hitting "gg" in normal mode will take you to the first line of the current buffer. Hitting "G" will take you to the end of the current buffer.


Nico said...

Combined with visual blocks this is a really useful tip (vgg & vG)

bibliotranstornado said...

I usualy use 1G to go to the first line but gg is one key less (the shift key for uppercase G).

I will use your trick.


Seth said...

To follow-up on what Nico said, I use ggvG to visually select the entire file.

djib said...

And if you're a gamer, gg should be easy enough to remember.

Anonymous said...

you can open a file on the command line and automatically put the cursor on the last line by typing:

vim + file

If you want vim to start at a specific line you can do the following instead:

vim +LINENUMBER file

laufbloggen said...

To follow-up on what Seth said, interestingly enough I found out that ggvG does not visually select quite the entire file. So to make this command really general : If the last line is not empty - you can never know it always is - you would have to do ggvG$ ($ meaning shift 4) for that.
And if you want to be sure to delete or e.g replace the whole content in a file with the word blubber - which is something like foo baar I guess - you would have to do
if I do not mistaken.