VI senior command highlights http://www.chinaunix.net Author: jazy Posted: 2002-09-17 09:41:00
In view of the fact that everyone has a certain strange when using VI, I will give birth to Buddha from the brothers [shell]. I hope that I will help you learn Unix, and I hope everyone can use HPUX. The experience is further extended to these experiences.
1. Exchange two character locations
XP
2. Convert two lines
DDP
3. Inverted the contents of the file
: g / ^ / m0 / (not passed)
4. Merge from two lines
J
5. Delete all lines
DG
6. Remove from the current location to the end
D $
7. Copy from the current location to the end
Y $ If you want to paste it to other places, you can
Since VI is built on EX, when typing: When it is typed:
8.
: Ab String Strings
For example, ": AB USA United States of America,
When you insert USA in the text
United State of America is coming out of America
9.
: Map Keys New_SEQ
Define your current keyboard command
10.
: set [all]
VI or EX editing status
As shown in each line: SET NU
11.
In the command state, NYY indicates that the copy from the lower N row content from the cursor row, and P represents the Paste, the content that can be copied is pasted at the cursor.
the following.
12.
Single characters are replaced with R, overwrite multiple characters with r, replacing a character with multiple characters with S, replace S
13.
:% S / OLD_WORD / New_WORD / G
This instruction is to replace a specific string throughout the file.
14. Cursor control
K: Move NK on NK
J: Move NJ downward N line
Move the cursor to the Nth line, press MK
Move the cursor to Mth, press "AY'K
The row n to m will be launched to the A register, and B, C ........ register, etc.
This allows you to paste the content you usually reuse into different registers in alternate
I want to paste to somewhere, move the cursor to a certain place, press the 'AP, in this type, B, c ........ register, etc.
In the current screen
H jumps to the first line
M jumps to the middle line
L Jump to the last line
15.
Table 8-2 Delete command
Delete command operation
D l Delete the current character (same as the x command function)
D 0 deletes the beginning of a row
D ^ Delete the first character position to a certain line (excluding spaces or ta b characters)
D w Deletes the end of a word
D 3 W Delete the end of the third word
D b Deletes the beginning of a word
D w Deletes the end position of a word that is spaced as a separator
D B deletes the start position of a word that is spaced as a separator
D 7 B Delete 7 of the previous seven in the start position of the word as a separator
d) Delete the end of a statement
D 4) Delete the end position of the fourth statement
d (Delete the start position of a statement
D} deletes the end of a certain paragraph
D {Delete the start position of a certain paragraph
D7 {Delete the 7th segment position before the current paragraph start position
D D Delete the current line
D / T E X T Delete the position of the words specified in "TE E X T" in the text, until the next word appears forward until the next word
Location (but does not include this word)
D fc deletes the position of the character "c" from the text, has been forward until the next character appears (including
The content between this character)
D TC Deletes the content between the current line until the next character "c" appears
D Delete the end of a certain line
D $ deletes the end of a certain line
5 D D Deletes the 5 line content D l from the current line until the content of the last line on the screen
D h deletes until the contents of the first line on the screen
D g Deletes the content ending until the work cache area
D 1 g Delete until the content started by the workbox
Modify command operation
C l Change the current character
C w Modified to a word of a word
C 3 W Modified to the end of the third word
C B modified to a word start position
C w Modified to a space with a space as a separator
C B modified to a single word as a separator as a separator
C 7 b Modify the start position of the word that is spaced as a separator as a separator
C 0 modified to a line of end position
c) Modify the end position of a statement
C 4) Modify the end position of the fourth statement
c (modify the start position of a statement
C} Modified to a certain paragraph
c {Modify to a paragraph start position
C 7 {Modified to the 7th paragraph position before the current paragraph start position
C TC Modify the content between the current line until the next character c
C Modified to the end of a certain line
C C Modify the current line
5 C C Modify the 5 line content starting from the current line
Repeat the last revision!
Table 8-4 Replace command
Replace command operation
s replaced the current character to one or more characters
S replaced the current line to one or more characters
5 s will replace 5 characters starting from the current character to one or more characters
VI replacement rules:
: g / s1 / s / s2 / s3 / g
The first G indicates that each of the rows including S1 are replaced, and the second G represents all S2 to replace all the rows including S1.
S indicates that S2 is a string to be replaced, he can be the same as S1 (if the same is used // instead), S3 is a replacement string
16.
FX
Move right to X characters
FX
Move left to the X character
TX
Move the right to the X character
TX
After moving to the left to the x character
(Note: In the above four commands, where x is typed.)
;
Sequel, matching F and T, repeat once
,
Comb, mixed with f and t, repeated in the opposite direction
17. VI Environmental Options Solaris Ksh
Noautoindent Nomodelines NoshowMode
AutoPrint Nonumber NoProwopen
Noautowrite nonovice tabstop = 8
Nobeautify nooptimize taglength = 0
Directory = / var / tmp paragraphs = iplppqppqpplplpiPnpbtags = tags / usr / lib / tags
NOEDCOMPATIBLE PROMPT Tagstack
NoerrorBells Noreadonly Term = VT100
NoExrc Redraw Noteerse
Flash Remap Timeout
Hardtabs = 8 report = 5 TTYTYPE = VT100
Noignorecase Scroll = 11 Warnnolisp Sections = NHSHH Huuhsh C Window = 23
nolist shell = / bin / ksh wrapscan
Magic shiftWidth = 8 wrapmargin = 0
Mesg NoshowMatch Nowriteany
For c-shell:
SetENV EXINIT "Set Nu"
For bourne or korn shell:
Exinit = "set nu"; export exinit
For Korn Shell Only:
Typeset -x exinit = "set nu"
Set up the environment options of VI in .profile,
18. Tag text
MCHAR tag the current cursor with alphabet char
`CHAR moved to CHAR Script
'char moves to the beginning of the CHAR mark
"Move to the current line in the location (after the cursor movement) - a double quotation number
'' The beginning of the line of the first location in the current line (after the cursor movement) - two single quotes
19.
At the same time Vi multiple files, Ctrl-Shift-6 returns to the previous file, switch between this VI file and the last VI file.
But I found a bug: After switching to the previous file with Ctrl-Shift-6, use: args to view the multi-file VI status,
The current VI is still displayed at the bottom of the screen.
(By HP-UX, Solaris, AIX passed)
You can also use:
: e #
Switch
20.
SCO's VI should be added to the same character before text
% s / ^ / to add content / g to add the same characters after text
% s / $ / to add content / g
twenty one.
How to remove the text in the text? It is not necessary to use binary to pass back to ASCII back, and implement it with the shell or UNIX statement.
Cat filename | TR -D '15> Newfile
Different UNIX systems have some other different commands, such as DOSCP
SED can also achieve this feature.
Dos2Unix filename filename2
on the contrary
UNIX2DOS filename filename2
Use in VI: $ S / ^ m //g
^ Is CRTL-V CRTL-M
22. How to change a string of a file with another string under the "UNIX command line"
SED 'S / STRING1 / STRING2 / GP' FILE1> File2
23. Ping all the addresses under / etc / hosts 2 times
1 # / usr / bin / sh
2 #grad / etc / hosts and ping each address
3 CAT / ETC / HOSTS | GREP -V '^ #' | While Read Line
4 DO
5 addr = `awk '{print $ 1}'` `
6 for machine in $ Addr
7 do
8 ping $ machine -n 2
9 DONE
10 DONE