VI Editor Commands

Editing Text

  • Entering Text
    • a append after cursor
    • A append at end of line
    • $a append at end of line
    • i insert before cursor
    • I insert at beginning of line
    • _i insert at beginning of line
    • o open line below cursor
    • O open line above cursor
    • cm change text (m is movement)
  • Cut, Copy, Paste (Working w/buffers)
    • dm delete (m is movement)
    • dd delete current line
    • D delete to end of line
    • d$ delete to end of line
    • x delete char under cursor
    • X delete char before cursor
    • ym yank to buffer(m is movement)
    • yy yank to buffer current line
    • Y yank to buffer current line
    • p paste from buffer after cursor
    • P paste from buffer before cursor
    • "bdd cut line into named buffer b (a..z)
    • "bp paste from named buffer b
  • Searching and Replacing
    • /w search forward for w
    • ?w search backward for w
    • /w/+n search forward for w and move down n lines
    • n repeat search (forward)
    • N repeat search (backward)
    • :s/old/new replace next occurence of old with new
    • :s/old/new/g replace all occurences on the line
    • :x,ys/old/new/g replace all occurences from line x to line y
    • :%s/old/new/g relpace all occurences in file
    • :%s/old/new/gc replace all occurences in file with confirmation
  • Miscellaneous
    • n>m indent n lines (m is movement)
    • n<m un-indent left n lines (m is movement)
    • . Repeat last command
    • U undo changes on current line
    • u undo last command
    • J join end of line with next line
    • :rf insert text from external file f
    • ^G show status

VI Movement Reference

  • By Character
    • h - left
    • j - down
    • k - up
    • l - right
  • By Line
    • nG to line n
    • 0 first position on line
    • $ last position on line
    • ^ first non-whitespace char on line
    • _ first non-whitespace char on line
    • + first char on next line
    • - first char on prev line
  • By Screen
    • ^F scroll forward one full screen
    • ^B scroll backward one full screen
    • ^D scroll forward one half screen
    • ^U scroll backard one half screen
    • ^E show one more line at bottom
    • ^Y show one more line at top
    • L go to bottom of the screen
    • z enter position line with cursor at top
    • z. position line with cursor at middle
    • z- position line with cursor at bottom
  • Marking position on screen
    • mp mark current position as p (a..z)
    • ‘p move to position p
    • ’p move to first non-whitespace on line with mark p
  • Miscellaneous movement
    • fm forward to charr m
    • Fm backward to charr m
    • tm forward to char before m
    • Tm backward to char after m
    • w move to next word (stops at punctuation)
    • W move to next word (skip punctuation)
    • b move to prev word (stops at punctuation)
    • B move to prev word (skip punctuation)
    • e end of word (punctuation not part of word)
    • E end of word (punctuation part of word)
    • ), next sentence
    • (, prev sentence
    • ]], next section
    • [[, prev section
    • }, next paragraph
    • {, prev paragraph
    • % go to matchin parenthesis () {} []
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License