vim cheatsheet.txt 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. OUTSIDE VIM:
  2. vim
  3. file open file
  4. -S [session file] open session file
  5. ~/.vimrc vim configuration file, set keymappings, settings etc. here
  6. IN VIM:
  7. navigation:
  8. hjkl/arrows move
  9. shift+arrows move by words and bigger line jumps
  10. w move to next word (beginning)
  11. b move to previous word (beginning)
  12. Ctrl-D move half page down
  13. Ctrl-U move half page up
  14. Ctrl-F page down
  15. Ctrl-B page up
  16. 0 move to the beginning of the line
  17. $ move to end of the line
  18. nG move to line n (e.g. 10G), 0 = end of file
  19. mx mark given line as "x"
  20. 'x go to line marked as "x"
  21. M move cursor to the middle of the view
  22. Ctrl-Y move view up by one line
  23. Ctrl-E move view down by one line
  24. zz center view on the current line
  25. editing:
  26. d delete (also copies, behaves like cut)
  27. dd delete current line (also copies, behaves like cut, for no copy use: "_dd)
  28. o add new line under
  29. p paste after
  30. P paste before
  31. u undo
  32. Ctrl-r redo
  33. v select (highlight) by characters
  34. V select (highlight) by lines
  35. Ctrl-v select (highlight) block (visual)
  36. y copy
  37. yy copy (yank) curent line
  38. > shift (indent) text right (to indent more use .)
  39. < shift (indent) text to left (to indent more use .)
  40. . repeat previous
  41. how to mass-prepend text (comment out) multiple lines:
  42. Ctrl-v 1. block select the lines
  43. Shift-i 2. prepend command - this will enter insert mode
  44. # 3. type what to prepend (e.g. '#', '//', ';' etc.)
  45. Esc 4. this will perform the prepend (takes a second)
  46. to uncomment use block select again and delete
  47. search/replace:
  48. /what search for what (case sensitive)
  49. /\cwhat case insensitive search
  50. :%s/x/y/g replace all "x"s with "y"s
  51. * find word under the cursor
  52. :noh unmark found results
  53. n jump to next found result
  54. N jump to previous found result
  55. multiple files:
  56. :hsplit horizontally split window (close with q:)
  57. :open file open file (over the current one, better to use :tabedit)
  58. :q quit, closes only the current file
  59. :qa quit all
  60. :q! quit without saving
  61. resize +n resize window height by n lones (- can also be used)
  62. :save file saves as file
  63. :tabedit file opens a file in tab
  64. :tabmove n move tab to position n
  65. :vertical resize +n resize window width by n columns (- can also be used)
  66. :vsplit vertically split window (close with :q)
  67. :wa save all open files
  68. :w save
  69. Ctrl-ww jump between split windows
  70. Ctrl-PageDown previous tab
  71. Ctrl-PageUp next tab
  72. compiling/errors:
  73. :cfile file load errors from file (gcc ... 2>&1 | grep "error">file.txt)
  74. :cn jump to next error
  75. :cp jump to previous error
  76. other:
  77. :! show terminal
  78. :!cmd executes "cmd" in terminal
  79. :mksession [file] saves current sessions
  80. :set syntax=lang set syntax to language (javascript, php, c, cpp, java, ...)
  81. Ctrl-n autocomplete
  82. Ctrl-Q fix vim freeze
  83. Ctrl-z suspend vim, temporarily go to terminal, get back by typing "fg"