Vi IMproved (Vim)

Contenido

Vi IMproved (Vim)#

Cheat Sheet#

  • esc: normal mode.

  • i | I: insert mode.

  • v: visual mode.

  • h: move left through the text in insert mode.

  • j: move down through the text in insert mode.

  • k: move up through the text in insert mode.

  • l: move right through the text in insert mode.

  • w: moves to the start of next word.

  • e: moves to the end of the next word.

  • b: moves to the beginning of the previous word.

  • g + e: moves to the end of the previous word.

  • [n] + [action / movement]: do n times the selected action or move.

  • [n] + i + [word] + esc: write n times the word.

  • x | X: remove character.

  • a | A: append.

  • f + [char]: move to next given char in line.

  • F + [char]: move to previous given char in line.

  • ; | ,: repeat last f or F.

  • / + [word] + n | N: search next word.

  • d + [movement]: delete by giving movement.

  • D: delete to the end of line.

  • r + [char]: replaces character below cursos.

  • %: jump to the matching ), ] or }.

  • 0: move to start of line.

  • $: move to end of line.

  • o: insert new line below current line and go to insert mode.

  • O: insert new line above current line and go to insert mode.

  • c + i + [movement]: change inside of given movement.

  • S: clear current line; to insert mode.

  • g + g: takes to the beginning of the file.

  • [n] + G: takes to the n line of the file.

  • G: takes to the end of the file.

  • y + y: copy current line.

  • p: paste copied text after cursor.

  • *: .

  • #: .

  • .: repeat previous command.

  • : + w: save.

  • : + q: quit.

  • : + q + !: quit with out saving.

  • u: undo.

  • Ctrl + R: redo.

  • : + help: when having a problem, or want to learn more about what Vim offers.

Hacks#

  • Find and Replace: :[range]s/{pattern}/{string}/[flags]

    • [range]: pass a range of lines. Pass % to find and replace in all lines. Use two numbers separated by a comma to indicate range (eg. 5,10), use a dot . to represent the current line and $ for the las line of the file.

    • {pattern}: pass regex patterns here.

    • {string}: replacement string.

    • [flags]: additional flags, for example: c to confirm before replacement, i to change to case-insensitive search, and g make a change globally.