1. Press V to enter the visual state, select multiple rows, and use> or <indent or contract
2. generally, auto indent layout is used based on language features: In the command status, the current row is used = (two connections by =), or N = (N is a natural number) indicates that N rows are automatically indented from the current row. You can try to unindent the code and use n = for typographical layout, which is equivalent to the code format in the general ide. You can use Gg = g to typeset the entire code. 3. gg SHIFT + G head and end 4. replace % S/source/Dist/g or: 1, $ S/source/Dist/G: S/Vivian/sky/with the first Vivian in the current line as sky
: S/Vivian/sky/g replace all Vivian in the current row with sky
: N, $ S/Vivian/sky/Replace the first Vivian from row n to row N as sky
: N, $ S/Vivian/sky/g replace all Vivian values from row n to row n
N is a number. If n is., it indicates starting from the current row to the last row.
: % S/Vivian/sky/(equivalent to: G/Vivian/S // sky/) Replace the first Vivian of each row with sky
: % S/Vivian/sky/g (equivalent to: G/Vivian/S // sky/g) replace all
You can use # As the separator. The/in the middle will not be used as the separator.
: S # Vivian/# Sky/# Replace the first Vivian/in the current line with Sky/
: % S +/oradata/apras/+/user01/apras1 + (replace with +/):/oradata/apras/Replace with/user01/apras1/
*************************************
1.: S/Vivian/sky/Replace the first Vivian in the current row with sky
: S/Vivian/sky/g replace all Vivian in the current row with sky
2.: N, $ S/Vivian/sky/Replace the first Vivian from row n to row N with sky
: N, $ S/Vivian/sky/g replace all Vivian values from row n to row n
(N is a number. If n is., it indicates starting from the current row to the last row)
3. Replace % S/Vivian/sky/(equivalent to: G/Vivian/S // sky/) with the first Vivian of each row as sky
: % S/Vivian/sky/g (equivalent to: G/Vivian/S // sky/g) replace all
4. You can use # As the separator. The/in the middle will not be used as the separator.
: S # Vivian/# Sky/# Replace the first Vivian/in the current line with Sky/
5. Delete ^ m from the text
Problem description: For line breaks, use the carriage return line break (0a0d) in the window, and the carriage return (0a) in Linux. In this way, when you copy files on Windows to Unix, there will always be a ^ m. Please write a shell or C program that is used in UNIX to filter Windows files (0d.
· Use the command: CAT filename1 | tr-D "^ V ^ m"> newfile;
· Run the following command: sed-e "s/^ V ^ m/" FILENAME> outputfilename. Note that in methods 1 and 2, ^ V and ^ m indicate Ctrl + V and CTRL + M. You must enter the file manually instead of pasting it.
· Processing in VI: First open the file using vi, Press ESC, and then enter the command: % S/^ V ^ m //.
·: % S/^ m $/g
If the above method is useless, the correct solution is:
· Tr-d "/R" <SRC> dest
· Tr-d "/015" dest
· Strings A> B
6. Others
Use the S command to replace strings. The specific usage includes:
: S/str1/str2/use string str2 to replace str1 that appears for the first time in the line
: S/str1/str2/g replace all the str1 strings in the row with str2
:., $ S/str1/str2/g replace string str1 from the current row to the end of the body with string str2
: 1, $ S/str1/str2/g replace str1 with string str2
: G/str1/S // str2/g functions are the same as above
From the above replacement command, we can see that G is placed at the end of the command, which means to replace each appearance of the search string; without g, it means to only search
String is replaced for the first time. G is placed at the beginning of the command to replace all rows containing the search string in the body.
[Excellent] vi advanced commands |
|
|
|
In view of the strangeness of Vi, I am here to explain the following advanced skills on VI programming from the [Shell] of my brother edition. I hope this will help you learn UNIX, we hope that you can use HPUX to further expand your experience. 1. Swap two character locations XP 2. Change the upper and lower lines DDP 3. Reverse the File Content : G/^/M0/(not passed) 4. Merge the upper and lower rows J 5. Delete all rows DG 6. delete from the current position to the end of the row D $ 7. copy from the current position to the end of the row Y $ if you want to paste it to another place, P will do. Because VI is built on ex, when you type:, it comes to the ex command status. 8. : AB string strings For example, & quot;: AB USA United States of America & quot ;, When you insert USA into the document United States of America came out. 9. : Map keys new_seq Define your current Keyboard Command 10. : Set [all] VI or ex editing status Show each line: Set nu 11. In the command state, nyy indicates copying the content of the next n lines starting from the cursor line, P indicates paste, and the copied content can be pasted at the cursor Below. 12. Replace a single character with R, replace multiple characters with R, replace one character with S, and replace the whole line with S. 13. : % S/old_word/new_word/g This command replaces a specific string in the entire file. 14. cursor control K: Move up NK move up n rows J: Move Down NJ move down n rows Move the cursor to line N and press mk Move the cursor to line m and Press & quot; ay 'K Store row n to m in register a, and so on. Register B, c... In this way, you can paste the frequently used content that needs to be reused into different registers for backup. To paste it somewhere, move the cursor directly to a certain place, and press 'ap, and so on. B, C... registers, etc. In the current screen H jump to the first line M jumps to the middle row. L jump to the last line 15. Table 8-2 delete commands DELETE command operation D l Delete the current character (same as the X command) D 0: Delete to the starting position of a row D ^ Delete to the first character position of a line (excluding spaces or ta B characters) D w: delete it to the end of a word D 3 W Delete to the end of the third word D B. Delete it to the start position of a word. D w is deleted to the end of a word with a space as the separator. D B: delete it to the start position of a word with a space as the separator. D 7 B is deleted to the start position of the first seven words with spaces as separators D) Delete to the end of a statement D 4) Delete to the end of the fourth statement D (delete to the start position of a statement) D} Delete to the end of a paragraph D {Delete to the beginning of a paragraph D 7 {Delete the first 7th paragraph positions before the start position of the current paragraph D. Delete the current row. D/t e x T Delete the position specified in "t e x T" from the text until the next Content between locations (but not including the words) D FC deletes the position where the character "C" appears from the text until the next character appears (including Between characters) D TC deletes the content from the current row until the next character "C" appears D. Delete it to the end of a row. D $ Delete to the end of a row D. Delete the contents of the five rows starting from the current row. D l Delete the content until the last line on the screen D H Delete the content until the first line on the screen D G deletes the content until the end of the work Cache D 1g content deleted until the beginning of the work Cache Modify command operation C l change the current character C w to the end of a word C 3 W to the end of the third word C B is changed to the start position of a word. C w is changed to the end position of a word with a space as the Separator C B is changed to the start position of a word with spaces as the separator. C 7 B is changed to the start position of the first seven words with spaces as separators C 0: change to the end of a row C) modify to the end of a statement C 4) modify to the end of the fourth statement C (modify to the starting position of a statement) C} modify to the end of a paragraph C {modify to the start position of a paragraph C 7 {change to the first 7th paragraph positions before the start position of the current paragraph C TC modifies the content between the current row and the position where the next character C appears C. modify it to the end of a row. C. modify the current row 5 C: modify the content of the 5 rows starting from the current row . Repeat the previous modification! Table 8-4 replacement commands Replace command operation S replaces the current character with one or more characters S replaces the current row with one or more characters 5 s Replace the 5 characters starting from the current character with one or more characters VI replacement rules: : G/S1/S/s2/S3/g The first G indicates that each row including S1 is replaced, and the second G indicates that all S2 of each row including S1 are replaced by S3. S indicates replacement. S2 indicates the string to be replaced. It can be the same as S1 (use // If the string is the same), and S3 indicates replacement string. 16. FX Move to the right to x characters FX Move to the left to X characters TX Move to the right before X TX Move to the left behind x characters (Note: X indicates the characters in the preceding four commands) & #59; Semicolon, used with F and t, repeat once , Comma (,), used together with F and t, and repeated in the opposite direction 17. VI environment option Solaris KSh Noautoindent nomodelines noshowmode Autoprint nonumber noslowopen Noautowrite nonovice tabstop = 8 Nobeautify nooptimize taglength = 0 Directory =/var/tmp paragraphs = iplpppqpp lipplpipnpbtags = tags/usr/lib/tags Noedcompatible prompt tagstack Noerrorbells noreadonly term = VT100 Noexrc redraw noterse Flash remap timeout Hardtabs = 8 report = 5 ttytype = VT100 Noignorecase scroll = 11 warn Nolisp sections = nhshh huuhsh + C window = 23 Nolist shell =/bin/KSh wrapscan Magic shiftwidth = 8 wrapmargin = 0 Mesg noshowmatch nowriteany For C-shell: Setenv exinit & quot; Set nu & quot; For Bourne or Korn shell: Exinit = & quot; Set nu & quot; & #59; export exinit For Korn shell only (alternate method ): Typeset-x exinit = & quot; Set nu & quot; Set VI environment options in. profile. All the above tests have been performed. 18. Mark text Mchar: Mark the position of the current cursor with a letter char 'Char moves to the position marked by char 'Char moves to the beginning of the row where the char mark is located & Quot; move to the last position of the current row (after the cursor moves)-a double quotation mark ''Move to the beginning of the row where the first row is located (after the cursor moves)-two single quotes 19. At the same time when vi multiple files, the CTRL-SHIFT-6 back to the previous file, in the VI file and the last VI file switch. But I found a bug: when I switched to the previous file with a CTRL-SHIFT-6 and checked the multi-file VI Status with: ARGs, The current VI file is still displayed at the bottom of the screen. (Via HP-UX, Solaris, AIX) You can also use: : E # Switch 20. Under SCO, VI should be added with the same characters before the text % S/^/content to be added/G must be added with the same character after the text % S/$/content to be added/g 21. How do I remove the ^ m hard carriage return in the text? You do not need to use binary to pass back and then use ASCII to pass back. It is implemented using shell or Unix statements. Cat filename | tr-D'/015 '>; newfile Different UNIX systems also have some different commands, such as doscp. Sed can also implement this function. Dos2unix filename filename2 Otherwise Unix2dos filename filename2 In VI: $ S/^ m/g ^ Is crtl-V crtl-m 22. How to replace a string of a file with another string in the Unix Command Line Sed's/string1/string2/GP 'file1>; file2 23. Ping all the addresses in/etc/hosts twice. 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
|
|