Skip to content

Instantly share code, notes, and snippets.

@jdmichaud
Last active May 4, 2025 06:20
Show Gist options
  • Select an option

  • Save jdmichaud/2c52de547f32a8b836febac8c6a01482 to your computer and use it in GitHub Desktop.

Select an option

Save jdmichaud/2c52de547f32a8b836febac8c6a01482 to your computer and use it in GitHub Desktop.
My VIM stuff

Vim grammar

Reload configuration after change: :so $MYVIMRC

navigate:

  • hjkl: <v^>
  • w: advance to beginning of next word
  • b: rewind to beginning of next word
  • e: advance to end of next word
  • Ctrl-o: exit INSERT mode for one and only one command, then get back at it
  • gd: Go to Definition
  • gg: Go to the first line
  • G: Go to the last line
  • ma: set mark a
  • 'a: go to mark a
  • ^ or _ to go to the first non-whitespace character of a line
  • $ to go to the last non-whitespace character of a line
  • f$c to go to the next $c of the line (for example f? to move the curstor to the next ?)
  • F$c to go to the previous $c of the line (for example f? to move the curstor to the previous ?)

verbs:

  • v: visual,
  • c: change,
  • d: delete,
  • s: delete and switch to insert mode,
  • x: delete character,
  • y: yank/copy.
  • p: put (P: put without yanking)
  • q: format (e.g. restrict to 80 column)

modifiers:

  • i: inside,
  • a: around,
  • t: till..finds a character,
  • f: find..like till except including the char,
  • /: search..find a string/regex

objects:

  • w: word,
  • s: sentence,
  • p: paragraph,
  • b: block/parentheses,
  • t: tag (works for html/xml).

Sentences:

  • diw - delete the current word
  • ciw - change current word
  • cc or S - change line
  • cis - change current sentence
  • ci” - change a string inside quotes
  • c/foo - change until next occurrence of ‘foo’
  • ctX - change everything from here to the letter X
  • vap - visually select this paragraph
  • d$ - cut from here to the end of line
  • ya( - yank around the enclosing parenthesis
  • 29j - Go down 29 times
  • db - delete word backward
  • Vp - Select line and replace by default register
  • V"0p - Select line and replace by the previous register (the one you paste no the one you replaced before)
  • yiw - yank word
  • viwp - select whole word and paste (to replace a word with default register)
  • viwP - select whole word and paste (to replace a word with default register without modifying the default register)

Remove trailing whitespace

:%s/\s\+$//g

Selection

word

viw

from space to space:

viW

paragraph

vip

Substitution

in the whole buffer:

:%s/foo/bar/g

with confirmation (add c)

:%s/foo/bar/gc

with confirmation starting at cursor to the end of the file

:.,$s/foo/bar/gc

in selection:

:'<,'>s/foo/bar/g

Search

case insensitive: use \c anywhere in the search term

/cop\cyright

Shortcut

  • * - Forward search word under cursor
  • # - Backward search word under cursor
  • . - Repeat the last action (verb)
  • A-f - CoC Autofix

Clipboard

Copy to clipboard:

"+y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment