VIM Cheatsheet

Here a collection of useful  VIM commands should expand. Mainly for myself, but could also be for help for others.

Links

Commandos

Most of them are from him, thank you for sharing your knowledge! I tried to order them somehow, improvement suggestions welcome.

For my syntax: {} refers to a mandatory argument, [] to an optional one. Alternatives are specified with „/„. All commands are in normal mode (if not stated otherwise). Ex commands start with „:„.

 

Moving around

  • H/M/L: Move the cursor to the top/middle/bottom of the screen
  • {line number}G: go to line number
  • gg/G: Go to first/last line of file
  • t{x}/f{x}: Moves the cursor to the next occurrence of character x
  • ;: Next occurrence (like n for normal search)
  • Ctrl-o/Ctrl-i: Jump forward/backward through jump history

Editing

  • [count]d{motion}: Delete stuff.
  • c{motion}: Delete stuff and change to insert mode.

Motions

  • t{x}/f{x}: To next occurrence of character x (excluding/including).
  • w: To end of current word.
  • ^/$: To beginning/end of line.
  • Motions can be prefixed with [count] to repeat the motion.

Insert mode specials

  • Ctrl-o{command}: Execute command and go back to insert mode

Word completion (insert mode)

  • Ctrl-x Ctrl-f: Complete filename in current directory
  • Ctrl-x Ctrl-n: Search forward for keyword in front of the cursor
  • Ctrl-x Ctrl-p: Search backward for keyword in front of the cursor
  • General: Ctrl-n/Ctrl-p: Next/previous match

Macros

  • q{letter}{commands}q: Record macro (till you press q again)
  • [count]@{letter}: Execute macro count times

Executing commands

  • :[range]g/{pattern}/[cmd]: Execute cmd (ex command) on the lines within range where pattern matches.
    :g/^A/d: Delete lines starting with A
  • :[range]v/{pattern}/[cmd]: Same as above, but where pattern does not match.

Executing shell commands

  • :%!{command}: Pipe the file through command and replace the current buffer with the output.
    :%!sort Sort the current file

Help

  • :h[elp] {command}: Help on thecommand or keybinding in normal mode.
    :h d: Help on the delete command
  • :h[elp] i_{command}: Help on the command in insert mode.
    :h i_Ctrl-o: Help on execute command in insert mode.

Schreibe einen Kommentar