分类:
2010-06-11 12:56:20
The vi Text Editor:
* Open a file called practice in the current directory: vi practice
* Insert text: iany text you like
* Place text from buffer: P or p
* Return to command mode: ESC
* Quit vi, saveing edits: wq or wq!
* Quit vi, without saveing edits: q or q!
Simple Editing:
* vi command general form: (number)(command)(text object)
* Insert text at current position i
* Insert text at beginning of line I
* Append text at current position a
* Append text at beginning of line A
* Open new line below cursor for new text o
* Open new line above cursor for new text O
* Join current and next line J
* Toggle case ~
* Repeat last action .
* Undo last change u
Text object Change Delete Copy
* One word cw dw yw
* One line cc dd yy or Y
* To end of line c$ or C d$ or D y$
* To beginning of line c0 d0 y0
* To first character of next line +
* To first character of previous line -
* To end of word e or E
* Backward by word b or B
* To end of line $
* To beginning of line 0
Moving Around in a Hurry:
* Scroll forward one screen ^F
* Scroll backward one screen ^B
* Move current line to center of screen and scroll z.
* Search forward for pattern /pattern
* Repeat last search n
* Move to next occurrence of x in current line fx
* Repeat previous find command in same direction ;
* Go to given line n nG
* Go to end of file G
* Return to previous mark or context ``
* Return to beginning of line containing previous mark ''
Beyond the Basics:
* Opens file at line number n: vi +n file
* Opens file at last line: vi + file
* Opens file at first occurrence of pattern: vi +/pattern file
* Get a list of any files that the system has saved: vi -r
* To recover the file practice after a system crash: vi -r practice
* Yank current line into buffer d: "dyy
* Add next sentence to buffer d: "D)
* Mark current position with x: mx
* Move the curse to marked by x: `x
* Move the curse to the first character of line marked by x: 'x
Introducing the ex Editor:
Basic Command:
* Command in vi invokes ex: Q
* Command in ex returns to vi: vi
* Delete lines 3 through 18: 3,18d
* Move lines 160 throught 224 to follow line 23: 160,224m23
* Copy lines 23 throught 29 and put after line 100: 23,29co100
Line Addressing Symbols:
* The current line: .
* The last line : $
* All lines: %
* Delete from current line to end of file: :.,$d
* Move from line 20 through the current line to the end of the file: :20,.m$
* Delete all the lines in a file: :%d
* Copy all lines and place them at the end of the file: :%t$
* Move lines 226 through the end of the file to two lines above the current line: :226,$m.-2
* Saveing file to practice.new: :w practice.new
* Saves from line 230 to end of file in newfile: :230,$w newfile
* Appending from the current line to line 600 to newfile: :.,600w >>newfile
* Read in contents of another file: r filename
* Place the read-in file after line 285 in the current file: 285r filename
Invoking vi on Multiple Files:
* Edits multiple files: vi file1 file2
* Calls in the next file: :n
* Calls in new file: :e filename
* Switch back to the previous file: ^^