Saturday, October 3, 2009

Some useful vi commands

gg -- Start of file
G -- End of File

^ -- Start of Line (Numeric 0 also work)
$ -- End of Line
w -- move forward word by word (Sometime use capital W to move forward,e also works)
b -- move backward word by word
3G -- will move to 3rd line
o(Alphabet) -- Insert into Next line
Page up and Page down works great

* -- Read the string under the cursor and go to the next place it appears.
(For instance, if your cursor was somewhere on the word "bob," the cursor
would move to the next occurrence of "bob" in your file.)

# -- Same as above but in reverse order

u -- undo .. Press successively if required.

U (Capital) -- Undo all changes in the line

typing . (a period) -- will repeat the last command you gave.
For instance, if your last command was dw (delete word), vi will delete another word.

Counts are one of the most powerful and time-saving features of vim.
Any command can be preceded by a number.
The number will tell vim how many times to execute the command. Here are a few examples:

3j will move the cursor down three lines.

10dd will delete ten lines.

y3f" will yank (copy) text from the cursor to the third quotation mark after
the cursor on the current line. Counts are useful to extend the range of a motion in this manner.

F -- Move one screen forward
B -- Move one screen backward

H -- Move the cursor to the top of screen -- Page UP
L -- Move the cursor to the bottom of screen -- Page Down

No comments: