notes

Vim

Table of content

Common

  1. . - repeat last command
  2. v - go to visual mode
  3. :w - save
  4. :q - quit
  5. u - undo
  6. ctrl + r - redo
  7. :help - help

Code navigation

  1. h - one character left
  2. l - one character right
  3. j - one character down
  4. k - one character up
  5. w - moves forward to the start of next word
  6. e - moves forward to the end of the next (current) word
  7. b - moves back to beginning of the word
  8. *nw - moves through n to the begining of the nth line
  9. % - jump to the next matching parenthesis

Go To

  1. :10 - go to line 10
  2. gg - go to begining of a file
  3. G - go to the end of a file

Code editing

  1. i - go to the edit mode under cursor
  2. a - go to the edit mode starting with next character to cursort
  3. A - go to the end of line and start edit mode
  4. o - insert new line after the current
  5. O - insert new line before the current
  6. r - replace one character and not go to edit mode
  7. s - delete charcter under cursor and enter edit mode
  8. cc - delete current line and go to edit mode
  9. cw- delete next word and go to edit mode
  10. :m line_number or +\- number - moves current line
    • :m +1 - move line one line down
    • :m 12 - move current line to 12 line
  11. 30itext + esc - inserts word text 30 times

Deleting

  1. d$ - deletes from current position to the end of line
  2. d^ - deletes from current backward to first non-white-space character
  3. d0 - deletes from current backward to begining of line
  4. dw - deletes current to end of current word (including trailing space)
  5. dd - cuts whole line
  6. db deletes current to begining of current word
  7. x - removes character under the cursor
  8. X - removes one character left to the cursor

Copying and Pasting

  1. p - past from buffer
  2. yy - yank next line to buffer
  3. 10yy - yank next 10 lines to buffer

Find

  1. fa - finds the next occurences of a
  2. * - finds the next occurence of the word
  3. # - finds the previous occurence of the word
  4. / - search a word
    • n - go to next occurence
    • N - go to previous occurence

Multiple Edition

  1. Go to visual mode ctrl + v
  2. Select necessary lines
  3. Go to edit mode shift i
  4. Write something
  5. Press esc twice

Searching

  1. To set word boundaries during search use /<pattern/>

Find and replace

  1. Everywhere:

     :%s/old/new/g
    
  2. In the selected text

    • select text with ctrl+V

    • then type :

     '<,'>s/old/new/g