Skip to content

aadityarraj0/vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Vim Cheatsheet

this is my vim commands cheatsheet


Cursor Movement

  • h – move cursor left
  • j – move cursor down
  • k – move cursor up
  • l – move cursor right
  • H – move to top of screen
  • M – move to middle of screen
  • L – move to bottom of screen
  • w – jump forwards to the start of a word
  • W – jump forwards to the start of a word (words can contain punctuation)
  • e – jump forwards to the end of a word
  • E – jump forwards to the end of a word (words can contain punctuation)
  • b – jump backwards to the start of a word
  • B – jump backwards to the start of a word (words can contain punctuation)
  • 0 – jump to the start of the line
  • ^ – jump to the first non-blank character of the line
  • $ – jump to the end of the line
  • g_ – jump to the last non-blank character of the line
  • gg – go to the first line of the document
  • G – go to the last line of the document
  • 5G – go to line 5
  • fx – jump to next occurrence of character x
  • tx – jump to before next occurrence of character x
  • F<char> – jump to previous occurrence of character <char> on line
  • T<char> – jump just before previous occurrence of character <char>
  • ; – repeat last f/F/t/T
  • , – repeat last f/F/t/T in reverse
  • } – jump to next paragraph or block
  • { – jump to previous paragraph or block
  • zz – center cursor on screen
  • Ctrl + b – move back one full screen
  • Ctrl + f – move forward one full screen
  • Ctrl + d – move forward half a screen
  • Ctrl + u – move back half a screen
  • |<n> – move to column <n>
  • z. – center current line
  • z<CR> – current line to top of screen
  • z- – current line to bottom of screen
  • <C-e> – scroll down by one line
  • <C-y> – scroll up by one line
  • [[ – go to previous section/function
  • ]] – go to next section/function
  • [] – go to end of previous section
  • ][ – go to end of next section
  • :n – go to line number n

💡 Prefix a cursor movement command with a number to repeat it. Example: 4j moves down 4 lines.


Insert Mode - Inserting/Appending Text

  • i – insert before cursor
  • I – insert at beginning of line
  • a – append after cursor
  • A – append at end of line
  • o – open new line below
  • O – open new line above
  • ea – insert at end of word
  • Ctrl + h – delete character before cursor
  • Ctrl + w – delete word before cursor
  • Ctrl + u – delete to beginning of line
  • Ctrl + j – insert new line
  • Ctrl + t – indent (shift right)
  • Ctrl + d – de-indent (shift left)
  • Ctrl + n – next match auto-complete
  • Ctrl + p – previous match auto-complete
  • Ctrl + rx – insert contents of register x
  • Ctrl + ox – temporarily enter normal mode for one command
  • Esc – exit insert mode
  • <C-r>{reg} – insert contents of register
  • <C-o>{motion} – run Normal command while in Insert
  • :startinsert – enter Insert mode from command line
  • :stopinsert – exit Insert mode from command line
  • <C-l> – clear and redraw screen

Editing

  • r – replace one character
  • R – enter replace mode
  • J – join line with line below (with space)
  • gJ – join line with line below (no space)
  • gwip – reflow paragraph
  • g~ – switch case up to motion
  • gu – lowercase up to motion
  • gU – uppercase up to motion
  • guu – lowercase current line
  • gUU – uppercase current line
  • g~~ – toggle case of current line
  • gE – end of previous WORD
  • ge – end of previous word
  • cc – change entire line
  • c$ or C – change to end of line
  • ciw – change inner word
  • cw / ce – change word / to end of word
  • s – delete and substitute character
  • S – delete and substitute line
  • xp – transpose characters
  • u – undo
  • U – undo entire line
  • Ctrl + r – redo
  • . – repeat last command
  • :norm – run Normal command across lines
  • gq – format text

Marking Text (Visual Mode)

  • v – visual character mode
  • V – visual line mode
  • Ctrl + v – visual block mode
  • o – move to other end of selection
  • O – move to other corner of block
  • aw / ab / aB / at – around word / () / {} / tags
  • iw / ib / iB / it – inner word / () / {} / tags
  • Esc – exit visual mode
  • >gv, <gv – reselect after indenting
  • I, A – block insert / append
  • gq – format selected text

💡 Use ( or { in place of b or B for text object movement.


Visual Commands (In Visual Mode)

  • > / < – shift right / left
  • y – yank
  • d – delete
  • ~ – switch case
  • u – lowercase
  • U – uppercase

Registers

  • :reg – list registers
  • "xy – yank into register x
  • "xp – paste from register x
  • "ayy – yank current line into register a
  • "+y, "+p – system clipboard (X11 clipboard)
  • "*y, "*p – primary selection (X11 primary)

💡 Registers are saved in ~/.viminfo and persist across sessions.

Special Registers

  • "0 – last yank
  • " – unnamed register
  • % – current filename
  • # – alternate filename
  • * – X11 primary
  • + – X11 clipboard
  • / – last search
  • : – last command
  • . – last inserted text
  • - – last small delete
  • = – expression
  • _ – black hole

Mark and Positions

  • :marks – show all marks
  • ma – set mark a
  • `a – go to mark a
  • y\a` – yank to mark
  • `0 – previous Vim exit position
  • `" – last editing position in file
  • `. – last edit
  • `` – last jump
  • :ju[mps] – jump list
  • Ctrl + i – jump forward
  • Ctrl + o – jump back
  • :changes – change list
  • g – next change
  • g; – previous change
  • Ctrl + ] – jump to tag under cursor
  • '[, '] – start/end of last change/yank

💡 Use ' to jump to the start of a line, ` to jump to exact position.


Macros

  • qa – start recording into a
  • q – stop recording
  • @a – play macro from a
  • @@ – repeat last macro

Cut and Paste

  • yy, 2y – yank 1 or 2 lines
  • yw, yiw, yaw – yank word variants
  • y$ or Y – yank to end of line
  • p, P – paste after/before
  • gp, gP – paste and leave cursor after text
  • dd, 2dd – delete lines
  • diw, daw – delete word variants
  • d$ or D – delete to end of line
  • x – delete character

Indent Text

  • >>, << – shift line right/left
  • >% – indent block
  • >ib, >at – indent text object
  • 3== – re-indent 3 lines
  • =%, =iB, gg=G – re-indent scopes
  • ]p – paste and match indentation

Exiting

  • :w – save
  • :w !sudo tee % – save with sudo
  • :wq, :x, ZZ – save and quit
  • :q – quit
  • :q!, ZQ – force quit
  • :wqa – save and quit all

Search and Replace

  • /pattern, ?pattern – search forward/back
  • n, N – repeat search
  • :%s/old/new/g – replace in whole file
  • :%s/old/new/gc – replace with confirmation
  • :noh[lsearch] – remove highlights
  • /\cword, /\<word\> – smart word searches
  • :vimgrep /pattern/ **/*.c – search across files
  • :10,20s/old/new/g – range replace
  • :'<,'>s/old/new/g – visual replace
  • :.s/old/new/g – current line replace

Diff / Folding

  • za, zo, zc – toggle/open/close fold
  • zr, zm, zi – fold more/less/toggle
  • ]c, [c – jump to next/prev change

💡 Use uppercase (e.g., zA) to apply folding recursively.

About

vim commands cheatsheet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors