Useful Vim Instruction

Due to recent task that is related to vim, I want to collect some useful instructions for vim here for further inference

Moving:.

  • h moves the cursor one character to the left.
  • j moves the cursor down one line.
  • k moves the cursor up one line.
  • l moves the cursor one character to the right.
  • 0 moves the cursor to the beginning of the line.
  • $ moves the cursor to the end of the line.
  • w move forward one word.
  • b move backward one word.
  • G move to the end of the file.
  • gg move to the beginning of the file.
  • `. move to the last edit.

Editing Vim Style:

  • d starts the delete operation.
  • dw will delete a word.
  • d0 will delete to the beginning of a line.
  • d$ will delete to the end of a line.
  • dgg will delete to the beginning of the file.
  • dG will delete to the end of the file.
  • u will undo the last operation.
  • Ctrl-r will redo the last undo.

Searching and Replacing:

  • / text search for text in the document, going forward.
  • n move the cursor to the next instance of the text from the last search. This will wrap to the beginning of the document.
  • N move the cursor to the previous instance of the text from the last search.
  • ? text search for text in the document, going backwards.
  • :%s/text/replacement text/g search through the entire document for text and replace it withreplacement text.
  • :%s/text/replacement text/gc search through the entire document and confirm before replacing text.

Copy and Pasting:

  • v highlight one character at a time.
  • V highlight one line at a time.
  • Ctrl-v highlight by columns.
  • p paste text after the current line.
  • P paste text on the current line.
  • y yank text into the copy buffer.