VIM Tutor makes you know enough commands-easily use VIM. If you wanna get full version of VIM Tutor, execute vimtutor in the shell. Lesson 1
- The cursor is moved using either the arrow keys or the HJKL keys:h (left), J (off), K (UP), L (right)
- To start Vim from the shell prompt Type:vim FILENAME
- To exit Vim
- Type:: q! To trash all changes.
- Type:: Wq to save the changes.
- To delete the character at the cursor type:x
- To insert or append text type:
- I type inserted text insert before the cursor
- A type appended text append after the line
Lesson 2
- 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 (d2w). where
- Operator-is, such as D for delete
- [Number]-is a optional count to repeat the motion
- Motion-moves over the text to operate in, such as w (word), $ (to the end of line), etc.
- To move to the start of the line use a zero:0
- To move to the end of the line use a zero: $
- Undo
- To undo previous actions, type:u (lowercase u)
- To undo all the changes in a line, type:u (capital U)
- To undo the undo ' s, type:ctrl-r
Lesson 3
- To put the back text, which has just been deleted, type P. This puts the deleted text after the cursor (if a line is deleted it'll go on the line below the cursor).
- Move a line to another place:dd then P
- Move lines to Another place: (num) DD then P
- To replace the character under the cursor, type R and so the character you want to has there.
- The change operator allows a 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
Lesson 4
- CTRL-G displays your location in the file and the file status.
- G moves to the end of the file.
- Number G/GG moves to this line number.
- GG moves to the first line.
- Search
- Typing/followed by a phrase searches FORWARD for the phrase.
- Typing? followed by a phrase searches backward for the phrase.
- After a search for type N to find the next occurrence in the same direction, or N to search in the opposite direction.
- Ctrl-o takes you older positions, ctrl-i to newer positions.
- Typing% while the cursor was on a (,), [,],{, or} goes to its match.
- Substitute
- To substitute new for the first old in a line type:s/old/new
- To substitute new for all ' old ' on a line type:s/old/new/g
- To substitute phrases between-line # ' s type: #, #s/old/new/g
- To substitute all occurrences in the file type:%s/old/new/g
- To ask for confirmation each time add ' C ':%S/OLD/NEW/GC
Lesson 5
- :!command executes an external command. Some useful examples is:
- :!ls-shows a directory listing.
- :!rm filename-removes file FILENAME.
- : w FileName writes the current Vim file to disk with name FILENAME.
- V motion:w filename Saves the visually selected lines in file FILENAME.
- To delete blank spaces in multiple lines, ctrl-v.
- : R FILENAME Retrieves disk file FILENAME and puts it below the cursor position.
- : R!dir reads the output of the dir command and puts it below the cursor position.
Lesson 6
- Type o to open a line BELOW the cursor and start Insert mode; Type O to open a line ABOVE the cursor.
- Type A To insert text after the cursor; Type A to insert text after the end of the line.
- The e command moves to the end of a word.
- The Y operator Yanks (copies) text, p puts (pastes) it.
- Typing a capital R enters Replace mode until is pressed.
- Typing ": Set XXX" sets the option "XXX". Some options are:
- ' IC ' ' ignorecase ' ignore upper/lower case when searching
- ' Is ' ' incsearch ' show partial matches for a search phrase
- ' HLS ' hlsearch ' highlight all matching phrases
- You can either use the long or the short option name.
- Prepend "No" to switch an option off:: Set Noic
Lesson 7
- Type:help or press or to open a Help window.
- Type:help cmd to find help on CMD.
- Type ctrl-w ctrl-w to another window
- Type:q to close the Help window
- Create a VIMRC startup script to keep your preferred settings.
- When typing A:command, press ctrl-d to see possible completions. Press to use one completion.
Vim Tutor Summary