Linux Default Editor Vi/vim usage __linux

Source: Internet
Author: User
Tags linux text editor

Vi/vim Basic Use Method
This article introduced the VI (VIM) basic use method, but for the ordinary user is basically enough. I/vim the difference is simple, they are multimodal editor, the difference is that vim is VI upgrade version, it is not only compatible with VI of all instructions, And there are some new features in it. For example , the syntax is highlighted, the visualization can not only run at the terminal, but also run in Xwindow, MacOS, Windows.

The VI Editor is the standard editor for all UNIX and Linux systems, and it is not as powerful as any of the newest text editors, but simply introduces its usage and a small number of instructions. Because of any version of UNIX and Linux systems, the VI editor is identical, so you can learn more about it in any other place that introduces VI. VI is also the most basic Linux text editor, learn it, you will be in the Linux world unimpeded.

[simply, you can use the arrows up and down the left and right direction andDelete,BACKSPACEkeys to move and delete positions, whether in command mode or in insert mode]

1, VI of the basic concept
Basically VI can be divided into three states, respectively, is the command mode (commandmode), insert mode (Insertmode) and the bottom row pattern (lastline mode), the functions of the various modes are distinguished as follows:
1)command-line modeCommandmode)
controls the movement of the screen cursor, the deletion of characters, words or rows, the movement of a section and the entryInsertmodedown, or tolastline Mode.
2)Insert Mode (Insertmode)
only inInsertmode, you can do text input, press "ESC"key to return to command line mode.
3)bottom Row mode (lastline Mode)
Save or exit a fileVI, you can also set an editing environment, such as finding a string, listing line numbers ... And so.


2, VI of the basic operation
a) into VI
in the system prompt symbol inputVIand the name of the file, you enterVIFull Screen editing screen:$vi myfile. But one thing to pay special attention to is that you enterVIafter that, you are in the command line mode (Commandmode", you want to switch to insert mode (Insertmode) "To be able to enter text. Initial useVIpeople will want to use the next key to move the cursor around, the result of the computer has been beep beep, to their own gas a half to death, so intoVI, don't move, switch to insert mode (Insertmode) "Say it again."

b) switch to insert mode (insertmode) Edit file
in the command line mode (Commandmode"Click the letter Below"I"You can enter" Insert mode (Insertmode", you can start typing text.

c) the toggle of Insert
you are currently in the Insert mode (Insertmode", you can only keep typing text if you find that you've lost the wrong word. Want to use the cursor key to move back, the word deleted, you need to click the first "ESCthe key go to command line mode (Commandmode) and then delete the text.

d) Exit VI and save documents
in the command line mode (Commandmode"Next, click the":"colon key to enter"lastline Mode", such as:
: w filename(enter "Wfilename"The article with the specified file namefilenameSave)
: Wq (
Enter theWq", Save and exitVI)
: q! (
inputq!, no disk forced exitVI)

3, command line mode (commandmode) function key
1). Insert mode
Press theI"switch into insert mode"Insertmode", press"i "entering the insertion mode starts the input file from the cursor's current position.
When you press "a" into insert mode, enter the text from the next position in the current cursor position.
When you press "o" into insert mode, you insert a new row and enter text from the beginning of the line.

2). Switch from insert mode to command line mode
Press the "esc" key.

3). Move cursor
VIyou can move directly up or down with the cursor on the keyboard, but the regularVIis in lowercase English letters "h","J","k","L, control the cursor to the left, bottom, top, and right, respectively.
Press "ctrl"+"b": The screen moves one page to the back.
Press "ctrl"+"f": The screen moves one page to the front.
Press "ctrl"+"u": The screen moves half a page to the back.
Press "ctrl"+"d": The screen moves half a page to the front.
"0" by number: Moves to the beginning of the article.
Press "g": Move to the end of the article.
Press "$": Moves to the end of the line where the cursor is located.
Press "^": Move to the beginning of the line where the cursor is positioned
Press "w": The cursor jumps to the beginning of the next word
Press "e": The cursor jumps to the end of the next word
Press "b": Cursor back to the beginning of the last word
Press "#l": the cursor moves to the position of the line, such as: 5l,56l.

4). Delete text
"x": Every time you click, delete the" back "character at the position of the cursor.
"#x": for example, "6x" represents the "back" 6 characters at the location where the cursor is deleted.
"x": Uppercase X, each time, deletes the "before" character in the position of the cursor.
"#X": for example, "20x" represents the "front" 20 characters where the cursor is deleted.
"dd": Deletes the line where the cursor is located.
' #dd ': Delete # line starting at the line where the cursor is located


5). Copy
"yw": Copies the character of the cursor at the end of the word to the buffer.
' #yw ': Copy # Word to Buffer
"yy": The row to the buffer where the cursor is copied.
#yy: For example, "6yy" indicates that the copy is "down" 6 lines of text from the line where the cursor is located.
"p": Pastes the characters in the buffer into the position of the cursor. Note: All copy commands related to "Y" must be matched with "P" to complete the copy and paste function.

6). Replace
"r": Replaces the character at which the cursor is located.
"r": Replaces the character where the cursor is, until the "esc" key is pressed.

7). Reply Last Action
"u": If you execute a command incorrectly, you can immediately press the"u", back to the previous operation. Press many times.U "you can perform multiple replies.

8). Change
"cw": Change the word at the end of the cursor
"c#w": For example, "c3w" represents a change of 3 words

9). Skip to the specified line
"ctrl"+"g" lists the line number of the row where the cursor is located.
"#G": "15g", for example, represents moving the cursor to the beginning of the 15th line of the article.

4, lastline mode under the command introduction
Before using "lastline mode",Just remember to press theESCThe key determines that you are already in theCommandmode"and then press":"colon to enter"lastline Mode".

A) Display Line numbers
"setnu": After entering "setnu", the line number is listed before each line in the file

B jump to a row in the file
The "#":"#" number represents a number, enter a number after the colon, and then press ENTER to jump to the line, such as entering the number 15, and then enter, will jump to the 15th line of the article.

C) Find characters
"/keyword: First press"/"key, and then enter the character you want to find, if the first time you find the keyword is not what you want, you can always press"n"will look back to the keyword you want so far.
"? keywords": Press "?" first Key, and then enter the character you want to find, if the first search keyword is not what you want, you can always press "n" will look forward to the keyword you want.


D) Save the file
"

Related Article

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.