Vim Commands

116 阅读2分钟

Record several commands in vimtutor

  1. h, j, k, l - move cursor, h is left, j is down, k is up, l is right.
  2. esc - back to Normal mode.
  3. :q! - exit the editor, without changes(discarding changes).
  4. x - delete character under the cursor.
  5. i - insert text before the cursor.
  6. A - append text at the end of line.
  7. vim filename - start vim from the shell prompt type.
  8. :wq - save a file and exit.
  9. dw - delete a word
  10. d$ - delete to the end of the line.
  11. w - move to the start of next word.
  12. e - move to the end of the current word.
  13. $ - move to the end of the line.
  14. many commands that change text are made from an operator and a motion, eg: dw.
  15. typing a number before a motion repeats it that many times(operator [number] option), eg: 2w, 3e.
  16. 0 - move to the start of the line.
  17. dd - delete a whole line.
  18. u - undo the last command
  19. U - undo all changes on a line.
  20. ctrl+r - redo the command.
  21. p - put(paste) text after the cursor.
  22. r+newcharacter - replace the old character at the cursor with the new character.
  23. ce - change until the end of the line.
  24. ctrl+g - show your location in the file and the file status.
  25. number+G - move to a line in the file.
  26. G - move to the bottom of the file
  27. gg - move to the start of the file.
  28. /phrase - search for the phrase
  29. n - search for the same phrase again
  30. N - search for the same phrase again in the opposite direction.
  31. ?phrase - search for a phrase in the backward direction.
  32. ctrl+o - go back to where you came from
  33. ctrl+i - goes forward
  34. % - find a matching ), ], }
  35. :s/new/old - subtitute first occurrence of new for old
  36. :s/new/old/g - subtitute new for old globally.
  37. :!externalCommand - execute an external command, eg: :!ls
  38. :w filename - save changes made to this file
  39. :!rm filename - remove file
  40. v - visual mode, visual selection
  41. :'<,'>w filename - write selected lines in visual mode to the file.
  42. :r filename - insert the contents of a file.
  43. :r :!ls - read the output of ls command and put it below the cursor.
  44. o - open a line below the cursor and place you in the Insert mode.
  45. O - open a line above the cursor and place you in the Insert mode.
  46. a - insert text after the cursor.
  47. R - replace more than one character, esc to leave the Replace mode.
  48. y - in Visual mode, copy the highlighted text.
  49. :set ic - in Search mode, set the ignore case option
  50. :set hls is - in Search mode, set hlsearch and incsearch option
  51. :set noic - in Search mode, disable ignore case option
  52. :help - open online help system
  53. ctrl+w ctrl+w - jump from one window to another
  54. :q - close the help window
  55. ctrl+d - see possible completion
  56. <TAB> - use one completion

reference: Vim cheat sheet: vim.rtorr.com/