Some useful vi keystrokes/cheatsheet

Some useful vi keystrokes/cheatsheet

A couple of useful keystrokes for vi

command mode
/                 search (down)   n=next occurance (down)
?                 search (up)      N=next occurance (up)

dd                delete line(s)
5dd               delete 5 line(s)
u                 undo delete
.                 repeat command

yy                copy line(s)
5yy               copy 5 line(s)
p                 paste line(s)

edit mode
i                 INSERT (mode)
:r FILENAME       insert contents of FILENAME here
:! CMD            execute external command
:r ! CMD          insert result of external CMD into file
O/o               add a line above/below current line

r                 replace text under cursor (eg. rE with cursor on an e will capitalise the e)
:w                write/save (! to force)
:q                quit/exit (! to force)
:wq!              save+exit+forced

$                 beginning of line
^                 end of line
:1                1st line
G                 last line
:244              nth line (goto)

:%s/abc/xyz/g     regex replace global
:sp               split the session
:vsp              vertical split
  e FILE          edit FILE in the split(s)
  ctrl-w ctrl-w   switch splits


Leave a Reply

Your email address will not be published. Required fields are marked *

seven + eight =