Instructor: Doug Riecken (email:
dougrieckenclass@gmail.com
)
This document contains information that should be useful to students
taking classes with me at SCI at Rutgers University.
Please send your corrections and suggestions
Go to Doug's Home Page
A Reason to Learn the UNIX vi Editor
In the real world of Microsoft Windows/NT and UNIX (LINUX and others)
there are 2 editors you must know. They are MS Word and the UNIX vi
editor. While I and many others enjoy to work in emacs, the emacs editor
does not always get loaded on various UNIX machines. You will find the
primary work environments you work in to consist of PCs, Macs, NT servers
and UNIX servers. You will find MS Word on the majority of PCs, Macs,
and NT servers, and you will always find vi on UNIX servers.
Command to start a vi session
Command Line Commands with the : character
- :f - displays filename
- :0 - move to beginning of file
- :$ - move to end of file
- :.= - print current line number
- :sh - temporary exit from vi - hit cntl-D to return to vi
- :w - save contents of vi to the default file
- :w filename - save content of vi to filename
- :q - quit vi
- :wq - save contents of vi then quit
- :1,$ s/this string of characters/with this new string/g - global
substitution
Navigation Commands
- j - move down one line
- Nj - move down N lines
- k - move up one line
- Nk - move up N lines
- spacebar - move right one character
- Nspacebar - move right N characters
- backspace - move left one character
- Nbackspace - move left N characters
- 0 - zero character moves you to beginning of line
- $ - $ character moves you to end of line
- w - move forward one word
- b - move backward one word
- e - move to end of current word
Edit Commands
- Y - copy current line
- NY - copy N lines starting from current line
- p - (if buffer holds line) paste line after current line
- P - (if buffer holds line) paste before current line
- dd - delete current line
- Ndd - delete N lines starting from current line
- u - undo last action
- x - delete current character
- Nx - delete N characters starting from current character
- p - (if buffer holds character) paste after current character
- P - (if buffer holds character) paste before current character
- r - replace current character with the next character typed
Commands to Start Entering Text
- o - open to enter text after current line
- O - open to enter text before current line
- i - insert/open to enter text before current character
- a - append/open to enter text after current character
- s - substitute current character and start enter text mode
- Ns - substitute N characters starting from current character
and enter text mode
- esc key - the esc (escape) key ends the enter text mode
Other Edit Commands
- /stringfoo - search on stringfoo
- n - find next instance of last search string
- J - append current and next lines
Go to Doug's Home Page