Using VI operation under Linux

Source: Internet
Author: User

how to jump to the end of a file after using VI under Linux

PageDown Key Continuous Press

Even though I used it, I was too stupid. Asked the master, the method is to press SHIFT+G, in addition, to the beginning of the file is GG.

Linux VI Find commandDiv id= "article_content" class= "Article_content" >
When you edit a long file using the VI editor, you are often dizzy and cannot find what you need to change. In this case, using the Find function is particularly important. The method is as follows: www.2cto.com 1, enter "/string" in command mode, for example "/section 3". 2, if you find the next, press "N" can. To search up from the current cursor position, use the following command:/pattern Enter where pattern represents a specific sequence of characters to search for. To search down from the current cursor position, use the following command:? pattern enter when the ENTER key is pressed, vi searches for the specified pattern and positions the cursor at the first character of the pattern.
For example, to search up the word for place, type: www.2cto.com VI Find and replace DaquanYou can use the: s command to replace a string in Vi/vim. Previously, only one format was used to replace the full text, and the command was found today
There are many kinds of writing (vi is really powerful ah, there is a lot to learn), record several in this, convenient later query. : s/vivian/sky/replaces the current line the first Vivian replaces the current row for sky:s/vivian/sky/g All Vivian is sky:n, $s/vivian/sky/replaces the nth row start to the first Vivian of each row in the last row For Sky:n, the $s/vivian/sky/g replaces the nth line with the first row in each row, and all Vivian is a number for Sky N, and if N is., from the current line to the last line:%s/vivian/sky/(equivalent to: G/vivian/s//sk y/) Replace the first Vivian of each line with Sky:%s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) to replace all Vivian in each line with Sky can use # as the delimiter, at which time the middle appears/not as a delimiter: s#vivian/#sky/# Replace the current line the first vivian/is sky/:%s+/oradata/apras/+/user01/apras1+ (replace with +/):/oradata/apras/replaced with/user01/apra S1/www.2cto.com   1.:s/vivian/sky/Replace the current line the first Vivian is Sky: S/vivian/sky/g replaces the current line all Vivian are sky 2.: N, $s/vivian/sky/the first Vivian of each row in the beginning of line N to the last row is Sky: N, $s/vivian/sky/g replace the nth row to the last row in each row all Vivian are Sky (n is a number, if N is., which is the beginning of the current line to the last row) 3.:%s/vivian/sky/(equivalent to: g/vivian/s//sky/) replaces the first Vivian of each line as Sky:%s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all Vivian in each row as Sky 4. You can use # as a delimiter, at which time the middle appears/does not act as a delimiter: s#vivian/#sky/# Replace the current row the first vivian/is sky/ 5. Delete the ^m in the textProblem description: For line breaks, the window is replaced with a carriage return (0a0d) to indicate that Linux is a carriage return (0A) to represent.  This way, when you copy a file on a window to UNIX, there is always a ^m. Write a shell or C program that uses a newline character (0D) that filters Windows files under UNIX. Www.2cto.com Using the command: Cat filename1 | tr-d "^v^m" > newfile; Use command: sed-e "s/^v^m//" filename > OutputFileName. It is important to note that in 1, 22 methods, ^v and ^m refer to Ctrl + V and ctrl+m. You have to do the typing manually, not the paste. Processing in VI: First use VI to open the file, then 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. Other  Use the: s command to implement a string substitution. Specific usages include: s/str1/str2/replacing the first occurrence of a string in a string with a str2 in the line str1:s/str1/str2/g the string str2 Replace all occurrences of the string in the row str1 www.2cto.com:., $ s/str1/s Tr2/g replaces all occurrences of strings in the current line to the end of the body with a string str2 str1:1,$ s/str1/str2/g Replace all occurrences of the string str2 function in the body with a string str1:g/str1/s//str2/g the same as you can see from the Replace command above : G at the end of the command to replace each occurrence of the search string, without G, to replace only the first occurrence of the search string, and g at the beginning of the command to replace all rows in the body that contain the search string. VI Save exit

VI is a kind of text editing program that exists widely in various UNIX and Linux systems. 2.Vi is not a typesetting program, just a purely text-editing program. 3.Vi is a full-screen text editor, it has no menus, only commands.
4.Vi is not window-based, so this multi-purpose editing program can be used to edit a wide variety of files on any type of terminal.
5.Vi features are very powerful, but command a wide range of proficiency in the grasp of a certain difficulty. Inventor of 6.Vi: Bill Joy
VI Start-up
$ VI filename or $ VI
If filename already exists, VI will open the existing file if it is a new file, VI will create it
Vi. exit of VI
Enter in command-line mode: q,:q! ,: Wq or: X, you can exit VI
: W Save
: w filename saved as filename
: wq! Save and exit
: wq!                 FileName is saved with filename after you exit: q! Do not save exit
: x Save and exit, function and: wq! same
VI Mode of operation
VI has three modes of operation, namely: Command mode, insert mode (edit mode) and last line mode, three modes perform different operations respectively, they can be switched between the two. 1. Command mode: After entering VI, the first entry is the command mode, waiting for the user to enter the editing command, the letter entered at this time as an edit command to explain.
2. Insert mode: Enter insert command in command mode I, additional command A, open command O and other commands can enter the insertion mode, in the Insert mode, the user input can edit the text, any input characters are saved as the contents of the file. The "ESC" key returns to the command mode.
3. Last line mode: In command mode, press ":" Key to enter the last line mode, the VI cursor will be displayed in the final line of the window, ":" As a prompt for the last row mode, waiting for the user to enter the command. After the last command executes, VI automatically returns to the command mode.
VI command Daquan 1, moving the cursor
H or LEFT arrow: The cursor moves left one character L or right ARROW key: The cursor moves one character to the right
K or UP ARROW: The cursor moves up one character J or down ARROW key: The cursor moves down one character
"Ctrl" +f: Screen "down" to move a page, equivalent to "PageDown"
"Ctrl" +b: The Screen "up" to move a page, equivalent to "PageUp" 0: The number 0, move to the first character of this line at the end of the $: move to the last character of the line G: Move to the last line of this file GG: Move to the first line of this file
N "Enter": N is a number and the cursor moves down n rows
2. Search and replace
/STR: Starting with the cursor, look down for a string named str. STR: starts with the cursor and looks up a string named Str.
: N1,n2s/str1/str2/g:n1 and N2 are numbers, look for str1 between line N1 and N2 line, and replace the string with STR2

: 1, $s/str1/str2/g: look for the str1 string from the first line to the last line and replace the string with STR2
: 1, $s/str1/str2/gc: look for the str1 string from the first line to the last line, replace the string with str2, and confirm with the user before the replace prompt whether a replacement is required
3. Delete, copy and paste
X,x:x to remove a character backwards, X to delete a character nx:n as a number, and to remove n characters for successive backwards
DD: Delete the entire line where the cursor is located
Ndd:n is a number, starting at the cursor position, removing the down n columns, such as 20DD, to delete the 20 columns. YY: The line where the cursor is copied
Nyy:n is a number, copying the down n rows where the cursor is located, such as 20yy copying 20 rows p,p:p to paste the copied data to the next line of the cursor, p is glued to the previous line of the cursor. U: Restore previous action
"Ctrl" +r: Redo the previous action
.: decimal point, repeat the previous action, commonly used in repeated deletion, repeated paste.
4. Insert mode
I,i: Insert: Inserts the input text at the current cursor, the existing text is backward, where I is inserted from before the current cursor position, I move the cursor to the beginning of the current line, and then start inserting.
A,a:a is inserted from the next character at the current cursor, a is inserted from the last character of the line where the cursor is located
O,o: This is the case of the English letter O, O to insert a new line at the next line where the current cursor is located, O to insert a new row on the previous line where the current cursor is located.
R,r: Replace: R is the character that the replacement cursor is in, and R will always replace the text of the cursor until the ESC key is located.
5, file operation related
: w: Save File
: w filename: Save as FileName
: N1,n2 w filename!: Saves the contents of the N1 line to the N2 row in filename: n w FileName: Saves the nth row in filename
: L,. W FileName: Saves the contents from the first line to the current cursor position in filename:., $ w filename: Saves from the cursor's current position to the end of the file in filename
: R filename: Open another file filename
: E FileName: Edit new file filename instead of original: F filename: Rename the current file to filename

Using VI operation under Linux

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.