VI advanced commands

Source: Internet
Author: User
VI advanced commands
Http://www.chinaunix.net
Author: Jazy
Posted on: 09:41:00

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, "AB USA United States of America ",
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 Row M and press "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)
;
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 "set nu"
For Bourne or Korn shell:
Exinit = "set nu"; export exinit
For Korn shell only (alternate method ):
Typeset-x exinit = "set nu"
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
"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 '15'> 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.