Академический Документы
Профессиональный Документы
Культура Документы
www.techrepublic.com
STARTING VI (page 1/1 total) (VI is CaSe SEnsItiVe!!! So make sure Caps Lock is OFF.)
Command Result
vi filename Edits filename.
vi -r filename Edits last saved version of filename after a crash.
vi + n filename Edits filename and places the cursor at line n.
vi + filename Edits filename and places cursor on the last line.
vi filename file2 ... Edits filename and then edits file2 and so on. After saving file1 enter :n for the next file.
vi +/string file Edits file and places cursor at the first line containing string.
MOVING (1/2) (These will tell you how to get the cursor where you want itfast.)
MOVING THE CURSOR
Command (ESC exits all modes except the initial Command Mode.) Result
arrow keys These do work, but they may be too slow on big files.
hjkl Left, down, up, and right, respectively.
CTRL-d Moves forward screenful.
CTRL-f Moves forward one entire screenful.
CTRL-u Moves backward screenful.
CTRL-b Moves backward one entire screenful.
nG Moves to line n in the file.
G Moves to the end of file.
H Moves to the top of the screen.
nH Moves to line n from the top of the screen.
M Moves to the middle of the screen.
L Moves to the bottom of the screen.
nL Moves to line n from the bottom of the screen.
w or W Moves to the start of the next word in the line; W ignores punctuation.
b or B Moves to the start of the previous word in the line; B ignores punctuation.
e or E Moves to the end of the next word in the line; E ignores punctuation.
0 (zero) or | Moves to the first column in the current line.
n| Moves to the column n in the current line.
^ Moves to the first non-blank character in the current line.
$ Moves to the last character in the current line.
+ or <CR> Moves to the first character in the next line.
- Moves to the first non-blank character in the previous line.
( Moves back to the beginning of sentence.
) Moves forward to the beginning of the next sentence.
{ Moves back to the beginning of the paragraph.
} Moves forward to the beginning of the next paragraph.
MOVING (2/2) (These will tell you how to get the cursor where you want itfast.)
MOVING THE SCREEN
Command (ESC exits all modes except the initial Command Mode.) Result
CTRLe Moves screen up one line.
CTRLy Moves screen down one line.
CTRLu Moves screen up page.
CTRLd Moves screen down page.
CTRLb Moves screen up one page.
CTRLf Moves screen down one page.
CTRLI Redraws screen.
z <CR> zcarriage return makes the current line the top line on the page.
nz <CR> Makes the line n the top line on the page.
z. Makes the current line the middle line on the page.
nz. Makes the line n the middle line on the page.
z Makes the current line the bottom line on the page.
nz Makes the line n the bottom line on the page.
Command (ESC exits all modes except the initial Command Mode.) Result
% Searches to beginning of balancing ( ) [ ] or { }.
fchar Searches forward in current line to char.
Fchar Searches backward in current line to char.
tchar Searches forward in current line to character before char.
Tchar Searches backward in current line to character before char.
/str <CR> Finds forward to str.
?str <CR> Finds in reverse for str.
:set ic Ignores case when searching.
:set noic Pays attention to case when searching.
:n,ms/str1/str2/opt Searches from n to m for str1; replaces str1 to str2; using optopt can be g for global change, c to
confirm change (y to acknowledge, <CR> to suppress), and p to print changed lines.
& Repeats last :s command.
:g/str/cmd Runs cmd on all lines that contain str.
:g/str1/s/str2/str3/ Finds the line containing str1, replaces str2 with str3.
:v/str/cmd Executes cmd on all lines that do not match str.
EDITING (1/3) (Deleting, copying, placing text, joining lines, changing text, repeat command, undo command)
Command (ESC exits all modes except the initial Command Mode.) Result
CTRLh or While inserting, deletes previous character.
Backspace
CTRLw While inserting, deletes previous word
CTRLx While inserting, deletes to start of inserted text.
nx Deletes n characters starting with current; omitting n deletes current character only.
EDITING (2/3) (Deleting, copying, placing text, joining lines, changing text, repeat command, undo command)
Command (ESC exits all modes except the initial Command Mode.) Result
nX Deletes previous n characters; omitting n deletes previous character only.
xp Switches character at cursor with following character.
ndw Deletes the next n words starting with current; omitting n deletes the current word only.
ndb Deletes the previous n words starting with current; omitting n deletes the previous word only.
ndd Deletes n lines beginning with the current line; omitting n deletes the current line only.
:n,md Deletes lines n through m.
D or d$ Deletes from the cursor to the end of the line.
dcursor_cmd Deletes everything included in the cursor command (e.g., dG would delete from current position to the
end of the file, and d4 would delete to the end of the fourth sentence).
nyy or nY Places n lines in the buffercopies; omitting n copies only the current line to the buffer.
ycursor_cmd Copies from cursor to cursor_cmd (e.g., yG copies current line to the last line in the file to the buffer).
(a-z)nyy or Copies or cuts (deletes) n lines into a named buffer a through z; omitting n works on current line.
(a-z)ndd
p Pastes copied text after cursor; also prints last deleted text.
P Pastes copied text before the cursor; also prints last deleted text.
(a-z)p or Pastes text from a named buffer a through z after or before the current line.
(a-z)P
nJ Joins the next n lines together; omitting n joins the beginning of the next line to the end of the current
line.
stext ESC Substitutes text for the current character until ESC is used.
S or cc text ESC Substitutes text for the entire line until ESC is used.
cwtext ESC Changes current word to text until ESC is used.
Ctext ESC Changes rest of the current line to text until ESC is used.
ccursr_cmdtext ESC Changes to text from current position to cursr_cmd until ESC is used.
u Undoes last command.
U Restores current line to its original state.
np Retrieves the last nth delete (last 9 deletes are kept in a buffer).
1pu.u. Scrolls through the delete buffer until the desired delete is retrieved (repeat u.).
n Repeats last / or ? search command.
N Repeats, in reverse order, last / or ? search command.
; (semi-colon) Repeats last f F t or T search command.
, (comma) Repeats, in reverse direction, last / or ? search command.
. (period) Repeats last text change command.
CTRLi or TAB While inserting, inserts one shift width.
EDITING (3/3) (Deleting, copying, placing text, joining lines, changing text, repeat command, undo command)
Command (ESC exits all modes except the initial Command Mode) Result
n<< or n>> Shifts n lines left or right (respectively) by one shift width; omitting n shifts one line.
< or > Use with cursor command to shift multiple lines left or right.
MACROS, SUBS, ABBREVIATIONS (1/2) (Macro functions, substitution strings, and abbreviations)
Command (ESC exits all modes except the initial Command Mode.) Result
:[address]s/search-string/replace-string/[/g] This is the format of a substitute commanddescription below.
address One line number or two line numbers separated by a comma. A. represents the current line, $ represents
the last line, and % represents the entire file.
search-string A regular expression that can be a simple string of characters.
replace-string The replacement string.
g Indicates a global replacement (more than one replacement per line).
MACROS, SUBS, ABBREVIATIONS (2/2) (Macro functions, substitution strings, and abbreviations)
Options given are default. To change them, enter type :set option to turn them on or :set nooption to turn them off.
To make them execute every time you open VI, create a file in your HOME directory called .exrc and type the options without the colon (:) preceding the option.
Command Result Command Result
:set all Prints all options to the screen. :set nooption Turns off option.
:set ai Turns on auto indentation. :set ap Prints line after d c J m :s t u commands.
:set bf Discards control characters from input. :set eb Precedes error messages with a bell.
:set ic Ignores case when searching. :set dir=tmp Sets directory or buffer file.
:set lisp Modifies brackets for Lisp :set magic Allows pattern matching with special
compatibility. characters.
:set mesg Allows others to send messages. :set list Shows tabs (^l) and end of line ($).
:set nu Shows line numbers. :set opt Speeds output; eliminates automatic
RETURN.
:set prompt Prompts for command input with :. :set re Simulates smart terminal on dumb
terminal.
:set report Indicates largest size of changes :set ro Changes file type to read only.
reported on status line.
:set scroll=n set n lines for CTRLd and z :set sh=shell_path set shell escape (default is /bin/sh)
:set showmode Indicates input or replace mode at :set sw=n Sets shift width to n characters.
bottom.
:set term Prints terminal type. :set terse Shorten messages with terse.
:set timeout Eliminates one-second time limit for :set tl=n Sets significance of tags beyond n
macros. characters (0 means all).
:set ts=n Sets tab stops to n for text input. :set wa Inhibits normal checks before write
commands.
:set warn Warns no write since last change. :set window=n Sets number of lines in a text window to
n.
:set wm=n Sets automatic wraparound n spaces
from right margin.