Access vim tutor via vimtutor
and follow along with the instructions.
- The cursor is moved using either the arrow keys or the
hjkl
keys.h
: leftj
: downk
: upl
: right
- To start Vim from the shell prompt type:
vim FILENAME <ENTER>
- To exit Vim:
<ESC> :q! <ENTER>
: trash all changes<ESC> :wq <ENTER>
: save the changes
- To delete the character at the cursor type:
x
- To insert or append text type:
i type inserted text <ESC>
: insert before the cursorA type appended text <ESC>
: append after the line
- Pressing
<ESC>
will place you in Normal mode or will cancel an unwanted and partially completed command.
- To delete from the cursor up to the next word type:
dw
- To delete from the cursor to the end of a line type:
d$
- To delete a whole line type:
dd
- To repeat a motion prepend it with a number:
2w
- The format for a change command is:
operator number motion
- where:
operator
: is what to do, such asd
for deletenumber
: is an optional count to repeat the motionmotion
: moves over the text to operate on, such asw
(word),$
(to the end of line), etc.
- To move to the start of the line use a zero:
0
- Undo:
u
: undo previous actionsU
: undo all the changes on a lineCTRL-R
: redo
- To put back text that has just been deleted, type
p
. This puts the deleted text AFTER the cursor (if a line was deleted it will go on the line below the cursor). - To replace the character under the cursor, type
r
and then the character you want to have there. - The change operator allows you to change from the cursor to where the motion takes you. eg. Type
ce
to change from the cursor to the end of the word,c$
to change to the end of a line. - The format for change is:
c number motion