vi Cheat Sheet
Navigating File |
asdf
| ||||
w forward one word | b back to start of word | ||||
0 start of line | $ end of line | ||||
nG go to line n | G go to last line | ||||
Inserting Text (§) ESC to finish | |||||
i insert before cursor (§) | A append at the end of line (§) | ||||
o open new line below (§) | C change to end of line (§) | ||||
O open new line above (§) | D delete to end of line | ||||
Editing: | 1 char | 1 word | n words | 1 line | n lines |
delete | x | dw | ndw | dd | ndd |
change | r | cw(§) | ncw(§) | cc(§) | ncc(§) |
copy (yank) into buffer | yw | nyw | yy | nyy | |
p paste buffer after/below cursor | P paste buffer before/above cursor | ||||
delete -> move cursor -> paste = cut & paste | |||||
copy -> move cursor -> paste = duplicate | |||||
Searching for Text: | |||||
/pattern search for pattern | n repeat last search | ||||
:n,ms/old/new/ between lines n and m substitute old with new | |||||
Miscellaneous | |||||
. repeat last edit command | u undo last edit command | ||||
>> indent line | U undo all changes to current line | ||||
J join lines | ^L redraw screen | ||||
Writing the file/Quitting vi | |||||
:r file read contents of file and place after current line | |||||
:n,mw file write portion of file between lines n and m to file | |||||
:w save | :w file save to file | :w! force save (often as root) | |||
:q quit | :wq save & quit | :q! force quit (no save) | |||
Escaping into shell | |||||
:!ksh run interative shell; press ^D to return to vi | |||||
:!cmd run cmd; press <CR> to return to vi | |||||
!!cmd run cmd; put its output into file being edited |
Comments
Post a Comment