Starting vi
- vi filename : edit filename starting at line 1
- vi -r filename : recover filename that was being edited when system crashed
Navigating
- ^f : move forward one screen
- ^b : move backward one screen
- ^d : move down (forward) one half screen
- ^u : move up (back) one half screen
Searching Text
- /string : search forward for occurrence of string in text
- ?string : search backward for occurrence of string in text
- n : move to next occurrence of search string
- N : move to next occurrence of search string in opposite direction
Adding / Changing / Deleting text
- i : insert text before cursor, until hit
- I : insert text at beginning of current line, until hit
- a : append text after cursor, until hit
- A : append text to end of current line, until hit
- o : open and put text in a new line below current line, until hit
- O : open and put text in a new line above current line, until hit
Cutting and Pasting Text
- yy : copy (yank, cut) the current line into the buffer
- Nyy or yNy : copy (yank, cut) the next N lines, including the current line, into the buffer
- p : put (paste) the line(s) in the buffer into the text after the current line
Exit vi
- : x ENTER : quit vi, writing out modified file to file named in original invocation
- :wq ENTER : quit vi, writing out modified file to file named in original invocation
- :q ENTER : quit (or exit) vi
- :q! ENTER : quit vi even though latest changes have not been saved for this vi call
References :
- https://www.cs.colostate.edu/helpdocs/vi.html