Overall View:
1. Move the cursor:
1) j --> move down
2) k --> move up
3) h --> move forward
4) l --> move afterward
5) 0 --> move to the start of current line
6) $ --> move to the end of current line
7) w --> move to the start of next word
8) e --> move to the end of next word
9) 3w --> move 3 words afterward
10) 3e --> move 3 words afterward
2. Deletion
1) x --> delete single character at the cursor
2)dw --> delete whole word at the cursor including all the spaces after the word.
3)d$ --> delete all characters including and after the current cursor.
4) d3w --> delete 3 words afterward
5) d3e --> delete 3 words afterward
6) dd --> delete current line
7) d2d --> delete 2 lines afterward including current line
8) 2dd --> delete 2 lines afterward including current line. same with d2d
9) ce --> delete the left character in the word after & including the current cursor
10) c$
3. Insertion
1) i --> insert before current cursor
2) I --> insert before the first character of current line.
3) a --> insert after current cursor
4) A --> insert after the last character of current line.
w - until the start of the next word, EXCLUDING its first character. e - to the end of the current word, INCLUDING the last character. $ - to the end of the line, INCLUDING the last character.
5) o --> open a line BELOW the cursor and start Insert mode
6) O --> open a line ABOVE the cursor and start Insert mode
4) Exit
1) :q! --> quit without saving changes
2) :wq --> quit and saving all changes
5) Undo
1) u --> undo single operation
2) U --> undo all the operations on a line.
1. To delete from the cursor up to the next word type: dw 2. To delete from the cursor to the end of a line type: d$ 3. To delete a whole line type: dd 4. To repeat a motion prepend it with a number: 2w 5. The format for a change command is: operator [number] motion where: operator - is what to do, such as d for delete [number] - is an optional count to repeat the motion motion - moves over the text to operate on, such as w (word), $ (to the end of line), etc. 6. To move to the start of the line use a zero: 0 7. To undo previous actions, type: u (lowercase u) To undo all the changes on a line, type: U (capital U) To undo the undo's, type: CTRL-R
6) Paste
1) p --> paste after current line
2) P --> paste before current line
7) Replace
1) r --> replace single character on the cursor
2) R --> replace more than one character on the cursor.
3) :s/thee/the --> replace the word 'thee' with 'the' in current line. only replace once.
4) :s/thee/the/g --> replace the word 'thee' with 'the' in current line. replace all occurence in current line.
5) :%s/thee/the/g --> replace the word 'thee' with 'the' replace all occurence in current file.
type :#,#s/old/new/g where #,# are the line numbers of the range of lines where the substitution is to be done. Type :%s/old/new/g to change every occurrence in the whole file. Type :%s/old/new/gc to find every occurrence in the whole file, with a prompt whether to substitute or not.
8) Position
1) G --> Go to the last line of the file
2) gg --> Go to the first line of the file
3) ctrl + g --> Also called CTRL-G, show the detail position information for current line.
4) 123G --> Move cursor to line 123.
5) Ctrl + b --> Move backward one screen
6) Ctrl + f --> Move forward one screen
9) Search
1) /errroor<ENTER> --> find the word "errroor" in file search FORWARD for the phrase.
2) ?errroor<ENTER> --> find the word "errroor" in file search BACKWARD for the phrase.
3) n --> go to next match
4) N --> go to prev match
5) % --> go to the corresponding character. {}, [], ()
This is very useful in debugging a program with unmatched parentheses!
6) ctrl+o --> go to older position
7) ctrl+i --> go to newer position
10) Select
1) v --> start visual selection
11) Copy
1) y --> yank (copy)
2) yw --> copy word
3) ye --> copy word
4) y$ --> copy till the end of line
5) yy --> copy whole line
12) Set command
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.