Skip to content

Instantly share code, notes, and snippets.

@kalinchernev
Last active September 20, 2021 17:17
Show Gist options
  • Save kalinchernev/aad31a60c2a5503700bd7ca905e24186 to your computer and use it in GitHub Desktop.
Save kalinchernev/aad31a60c2a5503700bd7ca905e24186 to your computer and use it in GitHub Desktop.

Visual mode

  • v: character
  • Shift + v: whole line
  • Ctrl + v: cursor, multiple lines

Navigation

  • h,j,k,l
  • f{c}: move to c character (useful for characters which would otherwise mess with / regex search: .,,,;,:, etc.)
  • t{c}: same as f{c}, but before the c character
  • F{c}: and T{c} are moving backwards
  • w: from word to word
  • b: like w, but backwards
  • e: end of word
  • ge: like e, but backwards
  • {, }: move paragraph up/down
  • 0: move to the beginning of the line
  • ^: move to the first character of the line
  • $: move to end of line
  • gg: top of the file
  • G: bottom of the file
  • zz: center screen
  • zt: put cursor on top
  • zb: put cursor on bottom

Semantic navigation

  • gd: go to definition
  • gf: jump to file in an import
  • ``: jump between 2 last lines, useful when jumping b/n variable definitions and usage lower in the file
  • Ctrl + 0/I: jump back and forth of lines in history

Search

  • /{pattern}: go to specific word (n repeats)
  • %: find a matching ({[]})
  • *: go to next occurrence of the word under the cursor
  • #: go to previous occurrence of the word under the cursor

Nifty inserts

  • o: open a line below cursor
  • O: open a line above cursor
  • a: after cursor
  • A: at the end of a line
  • I: at the start of a line

Select

Follow the (zone) selection pattern <action>a<object> or <action>i<object>

  • text within a tag: vit
  • all with the tag: vat
  • mark a word: vaw
  • text within (): vib
  • all with (): vab
  • text within {}: viB
  • all with {}: vaB

Others

  • add to selection: gb (similar to Ctrl + D)

Delete

Follow the (zone) deletion pattern <action>a<object> or <action>i<object>

Others

  • entire line: dd
  • n lines: ndd, i.e. 3dd
  • word: dw
  • until character: dtc, where c is the char
  • until end of line: D,d$
  • character under cursor: x
  • character before cursor: X

Undo/Redo

  • undo: u
  • redo: Ctrl+R
  • repeat last change: .

Replace/Subtitude

Regular expressions are supported

  • r: character beneath cursor
  • R: enter replace mode
  • :s/old/new/g: entire line
  • :#,#s/old/new/g: line numbers
  • :%s/old/new/g: entire file
  • :%s/old/new/gc: entire file with a prompt

Misc

  • Ctrl + [p|n]: autocomplete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment