# Vim

# Movement

  • w start of next word, W to after next white-space character, b start of previous word, e end of next word.
  • 0 begining of the line, $ end of the line.
  • I Insert text at begining of the line, A Append text at the end of the line
  • gg go to top first line of file, G go to last line.
  • H go to first line in screen, M go to middle line, L go to last line in screen.
  • :set number In normal mode, go to particular line number.
  • Ctrl-y Moves screen up one line
  • Ctrl-e Moves screen down one line
  • Ctrl-u Moves cursor & screen up half page
  • Ctrl-d Moves cursor & screen down half page
  • Ctrl-b Moves screen up full page & cursor to last line
  • Ctrl-f Moves screen up full page & cursor to first line
  • ( Move forward one sentence, ) Move backward one sentence
  • { Move forward one paragraph, } Move backward one paragraph
  • zz move current line to middle of screen
  • zt move current line to top
  • zb move current line to bottom
  • f<character> move to next , F<character> move to previous character
  • ; to repeat operation, , to repeat operation in opposite direction

# Inset text in multi-line

  1. Ctrl-V to enter visual mode.
  2. Select the lines of text to edit.
  3. Shift-i to insert start of all lines, Shift-a to append at the end of all lines.
  4. Esc.

# Change to all UPPERCASE or lowercase

  1. Highlight lines
  2. Shift+u to change all to UPPERCASE or u to change to lowercase

# Copy / Cut / Paste

  1. Move cursor to starting character.
  2. v to select character, or V to select whole line.
  3. Move cursor to end character.
  4. d delete/cut, or y yank/copy.
  5. Move to where to paste
  6. p to paste after cursor, or P paste before cursor.
  • yy or Y yank current line
  • y$ yank to end of line
  • yiw yank current word
  • yaw yank current word + whitespace
  • ytx yank to character x (before x)
  • yfx yank to character x (including x)

# Undo / Redo

  • u undo last change.
  • U undo all changes in a line or restore Line.
  • Ctrl-R or :redo redo to reverse an undo.
  • 4u undo last 4 changes.
  • 4Ctrl-R redo last 4 undos.
  • . repeat last command.
  • /foo search for "foo"
    • Esc to cancel and Enter to search
    • n to search forward and N to search backwords
  • In normal mode, * search forward for the word cursor is on, # search backwards.

# Search / Replace

  • :%s/foo/bar/g find "foo" and replace with "bar" in all lines
  • :s/foo/bar/g find "foo" and replace with "bar" in current line

# Tags

  1. Cursor to tag
  2. Ctrl-V to enter visual mode.
    • at to highlight matching tags including content.
    • it to highlight only content.
  3. o to toggle between start and end.
  • cs'" to change surrunding ' to ".
  • cst<div> change surrounding tag to
  • ds' to delete surrunding '`'
  • ysaptli> to surround a paragrpah with an <li> tag (ys{motion}{char})
  • Highlight text and S{char or tag} to surround text
Last Updated: 7/3/2021, 6:26:58 AM