|
Donation?
Harley Hahn Home Page
Send a Message to Harley
A Personal Note from Harley Hahn
Unix Book Home Page
SEARCH
List of Chapters
Table of Contents
List of Figures
Chapters...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Glossary
Appendixes...
A
B
C
D
E
F
G
H
Command Summary...
• Alphabetical
• By category
Unix-Linux Timeline
Internet Resources
Errors and Corrections
Endorsements
INSTRUCTOR AND STUDENT MATERIAL...
Home Page & Overview
Exercises & Answers
The Unix Model Curriculum &
Course Outlines
PowerPoint Files for Teachers
|
Appendix C...
Summary of vi Commands
This appendix contains a summary of all the
vi commands covered in this book. For
more information, see Chapter 22 in which I
discuss vi in detail.
Starting vi
| |
| vi file | Start vi, edit specified file |
| vi -R file | Start vi read-only, edit specified file |
| view file | Start vi read-only, edit specified file | |
| vim file | Start Vim, edit specified file |
| vim -C file | Start vi in compatibility mode |
Stopping vi
| |
| :q! | Stop without saving data |
| ZZ | Save data and stop |
| :wq | Save data and stop | |
| :x | Save data and stop |
Recovering After System Failure
| |
| vi -r | Display names of files that can be recovered |
| vi -r file | Start vi, recover specified file |
Keys to Use to Make Corrections
| |
| <Backspace>/ | Erase the last character typed
| | ^W | Erase the last word typed
| | ^X/^U | Erase the entire line
|
Controlling the Display
| |
| ^L | Redisplay the current screen
| | :set number | Display internal line numbers
| | :set nonumber | Do not display internal line numbers
|
Moving the Cursor
| |
| h | Move cursor one position left
| | j | Move cursor one position down
| | k | Move cursor one position up
| | l | Move cursor one position right
| | <Left> | Move cursor one position left
| | <Down> | Move cursor one position down
| | <Up> | Move cursor one position up
| | <Right> | Move cursor one position right
| | <Backspace> | Move cursor one position left
| | <Space> | Move cursor one position right
| | - | Move cursor to beginning of previous line
| | + | Move cursor to beginning of next line
| | <Return> | Move cursor to beginning of next line
| | 0 | Move cursor to beginning of current line
| | $ | Move cursor to end of current line
| | ^ | Move cursor to first non-space/tab in current line
| | w | Move cursor forward to first character of next word
| | e | Move cursor forward to last character of next word
| | b | Move cursor backward to first character of previous word
| | W | Same as w; ignore punctuation
| | E | Same as e; ignore punctuation
| | B | Same as b; ignore punctuation
| | ) | Move forward to next sentence beginning
| | ( | Move backward to previous sentence beginning
| | } | Move forward to next paragraph beginning
| | { | Move backward to previous paragraph beginning
| | H | Move cursor to top line
| | M | Move cursor to middle line
| | L | Move cursor to last line
|
Moving Through the Editing Buffer
| |
| ^F | Move down (forwards) one screenful
| | ^B | Move up (backwards) one screenful
| | n^F | Move down n screenfuls
| | n^B | Move up n screenfuls
| | ^D | Move down a half screenful
| | ^U | Move up a half screenful
| | n^D | Move down n lines
| | n^U | Move up n lines
|
Searching for a Pattern
| |
| / regex | Search forward for specified regular expression
| | / | Repeat forward search for previous pattern
| | ? regex | Search backward for specified regular expression
| | ? | Repeat backward search for previous pattern
| | n | Repeat last / or ? command, same direction
| | N | Repeat last / or ? command, opposite direction
|
Special Characters to Use in Regular Expressions
| |
| . | Match any single character except newline
| | * | Match zero or more of the preceding characters
| | ^ | Match the beginning of a line
| | $ | Match the end of a line
| | \< | Match the beginning of a word
| | \> | Match the end of a word
| | [ ] | Match one of the enclosed characters
| | [^ ] | Match any character that is not enclosed
| | \ | Interpret the following symbol literally
|
Line Numbers
| |
| n G | Jump to line number n
| | 1G | Jump to first line in editing buffer
| | gg | Jump to first line in editing buffer
| | G | Jump to last line in editing buffer
| | :map g 1G | Define macro so g will be the same as 1G
| | :n | Jump to line number n
| | :1 | Jump to first line in editing buffer
| | :$ | Jump to last line in editing buffer
|
Inserting
| |
| i | Change to insert mode: insert before cursor position
| | a | Change to insert mode: insert after cursor position
| | I | Change to insert mode: insert at start of current line
| | A | Change to insert mode: insert at end of current line
| | o | Change to insert mode: open below current line
| | O | Change to insert mode: open above current line
| | <Escape> | Leave insert mode, change to command mode
|
Making Changes
| |
| r | Replace exactly 1 character (do not enter input mode)
| | R | Replace by typing over
| | s | Replace 1 character by insertion
| | C | Replace from cursor to end of line by insertion
| | cc | Replace entire current line by insertion
| | S | Replace entire current line by insertion
| | c move | Replace from cursor to move by insertion
| | ~ | Change the case of a letter
|
Replacing a Pattern
| |
| :s/pattern/replace/ | Substitute, current line
| | :line s/pattern/replace/ | Substitute, specified line
| | :line,line s/pattern/replace/ | Substitute, specified range
| | :%s/pattern/replace/ | Substitute, all lines
|
Notes:
At the end of a command, use c to ask for confirmation, and g (global) to replace all occurrences on each line.
To specify a line number, you can use:
an actual number
. (period) for the current line
1 for the first line in the editing buffer
$ for the last line in the editing buffer
Undoing or Repeating a Change
| |
| u | Undo last command that modified the editing buffer
| | U | Restore current line
| | . | Repeat last command that modified the editing buffer
|
Breaking and Joining Lines
| |
| r | Break current line into two (replace character with newline)
| | J | Join current line and next line into one long line
| | :set wm=n | Auto line break within n positions of right margin
|
Deleting
| |
| x | Delete character at cursor
| | X | Delete character to left of cursor
| | D | Delete from cursor to end of line
| | dd | Delete the entire current line
| | d move | Delete from cursor to move
| | dG | Delete from current line to end of editing buffer
| | d1G | Delete from current line to start of editing buffer
| | :line d | Delete specified line
| | :line,line d | Delete specified range
|
Deleting: Useful Combinations
| |
| dw | Delete 1 word
| | d n w | Delete n words
| | d n W | Delete n words (ignore punctuation)
| | db | Delete backward, 1 word
| | d n ) | Delete n sentences
| | d n } | Delete n paragraphs
| | dG | Delete from current line to end of editing buffer
| | dgg | Delete from current line to start of editing buffer
| | d1G | Delete from current line to start of editing buffer
|
Copying the Last Deletion
| |
| p | Copy buffer; insert after/below cursor
| | P | Copy buffer; insert before/above cursor
| | xp | Transpose two characters
| | deep | Transpose two words (start to the left of first word)
| | ddp | Transpose two lines
| | "1pu.u.u ... | Recall one deletion after another
|
Copying and Moving Lines
| |
| :line co target | Copy specified line; insert below target
| | :line,line co target | Copy specified range; insert below target
| | :line m target | Move specified line; insert below target
| | :line,line m target | Move specified range; insert below target
|
Yanking
| |
| y move | Yank from cursor to move
| | yy | Yank the entire current line
|
Yanking: Useful Combinations
| |
| yw | Yank 1 word
| | y n w | Yank n words
| | y n W | Yank n words (ignore punctuation)
| | yb | Yank backward, 1 word
| | y n ) | Yank n sentences
| | y n } | Yank n paragraphs
| | yG | Yank from current line to end of editing buffer
| | ygg | Yank from current line to start of editing buffer
| | y1G | Yank from current line to start of editing buffer
|
Executing Shell Commands
| |
| :!command | Pause vi, execute specified shell command
| | :!! | Pause vi, execute previous shell command
| | :sh | Pause vi, start a shell
| | :!csh | Pause vi, start a new C-Shell
|
Reading Data Into Editing Buffer
| |
| :line r file | Insert contents of file after specified line
| | :r file | Insert contents of file after current line
| | :line r !command | Insert output of command after specified line
| | :r !command | Insert output of command after current line
| | :r !look pattern | Insert words that begin with specified pattern
|
Using Shell Commands to Process Data
| |
| n!!command | Execute command on n lines
| | !move command | Execute command from cursor to move
| | !move fmt | Format lines from cursor to move
|
Writing Data
| |
| :w | Write data to original file
| | :w file | Write data to specified file
| | :w>> file | Append data to specified file
|
Changing the File While Editing
| |
| :e file | Edit the specified file
| | :e! file | Edit the specified file, omit automatic check
|
Abbreviations
| |
| :ab short long | Set short as an abbreviation for long
| | :ab | Display current abbreviations
| | :una short | Cancel abbreviation short
|
|