VIM Cheat sheet

VIM is improved version VI. There are two modes, command mode and Insert mode. You can switch to insert mode with i and command mode with ESC. Insert mode is for inserting text and paragraph. Command mode is for all other things.

Commands

Opening and Creating file

  1. Opening or creating file vim filename.txt or vi filename.txt
  2. Opening two file vi file1.txt file2.txt
  3. Compare two file vi -d file1.txt file2.txt

    Editing

  4. Insert mode i
  5. Insert mode from starting of line SHIFT + i or I
  6. Insert mode from ending of line SHIFT + a or A
  7. Insert mode on next line o
  8. Insert mode on previous line SHIFT + o or O

    Search and Replace

  9. Search using /yourtext + ENTER for next n for previous N
  10. Reverse Search using ?yourtext + ENTER for next n for previous N
  11. Replace text in full document %s/yourtext/replacetext/g (+c)
  12. Replace a single character r

    Cut Copy Paste

  13. Delete full line dd
  14. Delete Multiple lines 5dd
  15. Delete Right side shift + d or D
  16. Delete Single char x
  17. Delete Multiple chars 5x
  18. Copy whole line SHIFT + v or V (entering visual line mode) Now, copy y cut d
  19. Select from char v (entering visual mode) Now, copy y cut d
  20. Select CTRL + V (entering visual mode) Now, copy y cut d
  21. Paste below p
  22. Paste above SHIFT + p or P

    Action

  23. Undo with u
  24. Redo with ctrl-r
  25. Undo all changes :e! + ENTER

    Movement

  26. Top gg
  27. Bottom G
  28. Move to line :100 eg :linenumber
  29. Move to different file CTRL + ww when opened two file with vi file1.txt file2.txt

    Setting change

  30. Show line number :set nu
  31. Word wrap :set wm
  32. Syntax color mode off :syntax off
  33. Syntax color mode on :syntax on

    Save

  34. Saving Text: :w!
  35. Quite :q!
  36. Save and Quite with :wq!