Skip to content

Instantly share code, notes, and snippets.

@EddiG
Last active September 3, 2018 08:52
Show Gist options
  • Save EddiG/09b1429e7500bdff352b0a8a01a442ec to your computer and use it in GitHub Desktop.
Save EddiG/09b1429e7500bdff352b0a8a01a442ec to your computer and use it in GitHub Desktop.

Vim cheat sheet

Motions and Operators

Motions

  • [operator]aw - current word with trailing space
  • [operator]iw - current word
  • [operator]ap - current paragraph with trailing space
  • [operator]ip - current paragraph
  • [operator]l - current letter
  • [operator]it - inside the tag
  • [operator]0 - move to begin of line
  • [operator]g_ - move to end of line
  • [operator]gg - move to the begin of buffer
  • [operator]G - move to the end of buffer
  • [operator]{ - move to the prev paragraph
  • [operator]} - move to the next paragraph
  • [operator]H - move to the top
  • [operator]L - move to the bottom
  • [operator]M - move to the middle

Operators

  • c[motion] - change
  • d[motion] - delete
  • y[motion] - copy
  • g~[motion] - swap case
  • gu[motion] - make lowercase
  • gU[motion] - make uppercase
  • gq[motion] - format text
  • zf[motion] - define a fold
  • =[motion] - autoindent
  • >[motion] - shift right
  • <[motion] - shift left
  • ![motion]{external program} - filter through an external program
Change
  • cl - change letter
  • caw - change a word and trailing space
  • cap - change a paragraph
  • ciw - change a word
Change on motion
  • gUl - switch to uppercase letter
  • gUaw - switch to uppercase a word
  • gUap - switch to uppercase a paragraph
  • gUit - switch to uppercase the text inside a tag
Delete
  • dl - delete letter
  • daw - delete a word and trailing space
  • dap - deleta a paragraph
Copy
  • yl - copy letter
  • yaw - copy a word with trailing space
  • yap - copy a paragraph with trailing space
  • yy - copy a line
External program
  • !ap{grep -oP '\d+'} - leave only digits in the current paragraph

Execute external program

  • `:%! [external command] - execute external command on the whole buffer and replace with result

Edit in Insert mode

  • <C-h> - delete back one character
  • <C-w> - delete back one word
  • <C-u> - delete back to start of line

Normal Insert mode

  • <C-o> - enter into Normal Insert mode

Insert special symbol by code

  • <C-v>[code] - by decimal code
  • <C-v>u[code] - by hexadecimal code
  • <C-k>[char][char] - by digraph (:h digraph-table)
  • <C-k>12 - digraph combo for the ½ symbol

Insert expression result

  • <C-r>=[expression]<CR> - calculate an expression and place result in cursor position
  • <C-r>=5*5<CR> - insert 25 in current cursor position

Macros

  • q a - begin recording macros to register a
  • q - end recording macros
  • @a - perform macros from register a

Combo

  • 30@a - perform macros from register a 30 times

Visual mode

  • o - toggle the free end
  • gv - reselect the last selection
  • vit - select text inside the tag
  • viw - select current word
  • vip - select current paragraph
Useful combos
  • <C-v>5j$A;<CR> - append the ";" symbol at the end of 5 lines

Paste

  • p - paste after cursor
  • P - paste before cursor

Paste in Insert mode

  • <C-r><C-p>[register] - paste from register

Folding

  • zf - create folding
  • za - toggle folding

Calculations

  • [num]<C-a> - add [num] to the first found value
  • [num]<C-x> - subtract [num] from the first found value

Navigate

  • <C-d> - scroll down
  • <C-u> - scroll up
  • <C-m> - scroll to the middle
  • <C-o> - go to older cursor position in jump list
  • <C-i> - go to newer cursor position in jump list
  • H - move to the top
  • L - move to the bottom
  • M - move to the middle
  • 0 - move to begin of line
  • g_ - move to end of line
  • gg - move to begin of buffer
  • G - move to end of buffer

Search in current line

  • f[char] - move to the [char]
  • t[char] - move before a [char]
  • ; - move to the next [char]
  • , - move to the prev [char]

Search in whole buffer

  • * - search a word that is under cursor
  • n - search next occurrence
  • N - search prev occurrence

Resize windows

  • <C-w>[columns]> - increase the width of window
  • <C-w>[columns]< - decrease the width of window
  • <C-w>[rows]+ - increase the height of window
  • <C-w>[rows]- - decrease the height of window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment