I just wanted to post a few quick tips on using the Vim (vi iMproved) text editor. Whenever you are editing a large text file in vi you may want to know where you are? What line am I on? Well, it’s actually quite easy. Just type
CTRL-g and look at the bottom/status line of your editor. You will be informed of the name of the file you are currently editing, the line number your are on, the column within that line that your cursor is located and the total number of lines in the file.
Would you like to jump to the end of the file? Sure you would! Just type
G. That’s right, just a single letter. It has to be capital to work though. Want to get to the first line in the file? Try
:0. No, that’s not a smiley. It’s a colon followed by a zero. It actually tells vi to go to the specified line number. So if you wanted to go to line 23 you could also just type
:23. Cool, eh? You can also use the previously mentioned
G key for this purpose by pre-pending it with the line number. So you could type
23G (no colon) and would find yourself on line 23.
Ok, final tip. How about navigating within the current line that you are on? To go to the end of the line just type
$. To go to the beginning of the line just type