Vi Editor, vi editor download

Source: Internet
Author: User
Tags first string linux text editor

Vi Editor, vi editor download

Vi Editor

I. Introduction

Vi is a standard Linux text editor.

Vi is not window-based. Therefore, this multi-purpose editing program can be used to edit various files on any type of terminal.

Ii. vi details

1. Create a file

Vi filename

If filename already exists, vi will open the existing file

If it is a new file, vi will create it

The last line on the screen is called a status line. It is used to display the file name and the number of rows and characters in the file.

2. Three vi Modes


(1) input mode:

When vi is running, it is usually in command mode. type the following command to exit the command mode and enter the input mode:

I

A

O o

(2) command mode

In this mode, you can enter commands to execute many functions. Most vi commands are composed of one or two letters and one optional number.

Command starting with Colon: w: wq: x: q!

(3) Save and exit vi

Save

: W followed by the Enter key

Save and exit

Enter: Enter the Enter key after wq

Exit but not save

Enter q followed by the Enter key

Use q! Force exit

(4) move the cursor in the file

Move one character to the left: Press h

Move one character to the right: press l

Move one row down: Press j

Move one row up: Press k

Move to the beginning of the current row: Press ^ (Shift-6)

Move to the end of the current row: Press $ (Shift-4)

Move to top: Press H (uppercase) to move the cursor to the top of the screen

Move to center: press M (uppercase) to move the cursor to the center of the screen

Move to bottom: press L (uppercase) to move the cursor to the bottom of the screen

Move to the end: Press G (uppercase) to move the cursor to the end of the text

Page up

Scroll back to half screen: page up

Move the cursor up, down, left, and right

(5) Insert text

Add:

After entering a, insert text to the right of the cursor

Enter A and add text at the end of A line

Insert:

Input I in command mode to insert text to the left of the cursor

Input I in command mode to insert text at the beginning of the line

Insert a new row:

Input o to open a line under the current cursor position

Input O to open a line above the current cursor position

(6) undo changes

Undo the previous command:

Enter u immediately after the last command to undo the command.

Repeat a command.

Undo changes to a row:

Enter U to cancel all your changes to a row.

This command takes effect only when you do not move the cursor beyond this line.

(7) delete text

Delete A character:

To delete a character

Place the cursor anywhere in the row and enter dd

Delete multiple rows: ndd

(8) copying and moving text

Copy a line of command: yy

Paste command: p

Move text: delete the part to be moved with the DELETE command, and then paste it.

Copy the content of a specified file
: R filename

(9) Search for a string

Enter/and enter the string to be searched after/, and press ENTER

• Enter "n" to jump to the next appearance of the string

• Enter "N" to jump to the previous appearance of the string

(10) replace a string

Replace the first string in one line with the old string as the new string.

•: S/old/new

Replace all the old strings in one line with the new string new

•: S/old/new/g

Replace all the old strings in the two rows as the new string.

•: #, # S/old/new/g

Replace all the old strings in the file with the new string new

•: % S/old/new/g

When performing full-text replacement, ask the user to confirm that c is required for each replacement.

•: % S/old/new/gc

3. Set vi

Show row number
: Set nu

Cancel row number display
: Set nonu

Set Display User Mode
: Set showmode

Set File Read-Only
: Set readonly

 


Vi editor commands in linux

Some advanced editors will contain macro functions, which are certainly not missing in vim. It is very convenient to use Macros in vim:
: Qx starts to record macros and saves the results to register x
Q exit record mode
@ X macro commands for playing records in the x register
After you enter qx in normal mode, all the edits to the text will be recorded. If you enter q again, the record mode will be exited.
And then input @ x to repeat the recorded command. This command can be followed by a number to indicate the number of times to repeat. For example, @ x20 can be repeat 20 times. This is very useful in text batch processing.
Edit multiple files at the same time
Among the many vim plug-ins, there is a plug-in called minibuffer, which is called the tab function below. You can edit multiple files at the same time.
Tag command
: Tabe fn: edit the file fn in a new tab
Gt switch to the next tab
GT switch to the previous Tab
: Tabr switch to the first tab
: Tabl switch to the last tab
: Tabm [N] Move the current tab to the nth tab
Yes, as you think, it is similar to eclipse, ue, and other tabs!
Window command
Ctrl + w s Horizontal Split Window
Ctrl + w switch window
Ctrl + w q exit the current window (because there are multiple files at the same time, this command will not affect other Windows)
Ctrl + w v Vertical Split Window
Others
Vim does not make actual changes to the file before saving, but only loads the file into the buffer. The editing of the file is actually the editing of the buffer. It will not be saved to the physical file until: w.
: E file: load the file to the new buffer.
: Bn jump to the next Buffer
: Bd Delete buffer (close file)
: Sp fn split the window and load fn to the new window
Exit Editor
: W write the buffer to a file, that is, save the modification.
: Wq: Save the modification and exit.
: X Save the modification and exit
: Q exits. If the buffer is modified, a message is displayed.
: Q! Force exit, discard Modification
Search and replace
/Pattern: returns the string pattern.
? Pattern: returns the string pattern.
N: Next match (If yes/search, it is the next one ,? Search to the next one)
N match (same as above)
: % S/old/new/g search the entire file and replace all old with new
: % S/old/new/gc search for the entire file, replace all old with new, and each time you want to confirm whether to replace
Copy and paste
Dd deletes the row where the cursor is located.
Dw deletes a word)
X Delete the current character
X Delete the previous character
D. Delete it to the end of the row.
Yy: copy a row. The command can be followed by a number to identify multiple rows. For example, 6yy indicates that six rows are copied from the current row.
Copy one word from yw
Y $ copy to the end of the row
P paste the clipboard content to the current row
P paste the clipboard content to the current row
] P is indented and vim automatically adjusts the code indent.
"A puts the content into/into register a, and supports multiple clipboard
Note: for example, a commonly used register is a system register with the name +. Therefore, the "+ p" command is pasted from the system clipboard to vim. Note that the "+" operator is not represented here, 21 registers.
Move cursor
In vim, the moving cursor is very different from other editors, but once learned, it will quickly move in the text.
H, j, k, l upper, lower, left, right
Ctrl-f ...... the remaining full text>

Vi editor commands in linux

Some advanced editors will contain macro functions, which are certainly not missing in vim. It is very convenient to use Macros in vim:
: Qx starts to record macros and saves the results to register x
Q exit record mode
@ X macro commands for playing records in the x register
After you enter qx in normal mode, all the edits to the text will be recorded. If you enter q again, the record mode will be exited.
And then input @ x to repeat the recorded command. This command can be followed by a number to indicate the number of times to repeat. For example, @ x20 can be repeat 20 times. This is very useful in text batch processing.
Edit multiple files at the same time
Among the many vim plug-ins, there is a plug-in called minibuffer, which is called the tab function below. You can edit multiple files at the same time.
Tag command
: Tabe fn: edit the file fn in a new tab
Gt switch to the next tab
GT switch to the previous Tab
: Tabr switch to the first tab
: Tabl switch to the last tab
: Tabm [N] Move the current tab to the nth tab
Yes, as you think, it is similar to eclipse, ue, and other tabs!
Window command
Ctrl + w s Horizontal Split Window
Ctrl + w switch window
Ctrl + w q exit the current window (because there are multiple files at the same time, this command will not affect other Windows)
Ctrl + w v Vertical Split Window
Others
Vim does not make actual changes to the file before saving, but only loads the file into the buffer. The editing of the file is actually the editing of the buffer. It will not be saved to the physical file until: w.
: E file: load the file to the new buffer.
: Bn jump to the next Buffer
: Bd Delete buffer (close file)
: Sp fn split the window and load fn to the new window
Exit Editor
: W write the buffer to a file, that is, save the modification.
: Wq: Save the modification and exit.
: X Save the modification and exit
: Q exits. If the buffer is modified, a message is displayed.
: Q! Force exit, discard Modification
Search and replace
/Pattern: returns the string pattern.
? Pattern: returns the string pattern.
N: Next match (If yes/search, it is the next one ,? Search to the next one)
N match (same as above)
: % S/old/new/g search the entire file and replace all old with new
: % S/old/new/gc search for the entire file, replace all old with new, and each time you want to confirm whether to replace
Copy and paste
Dd deletes the row where the cursor is located.
Dw deletes a word)
X Delete the current character
X Delete the previous character
D. Delete it to the end of the row.
Yy: copy a row. The command can be followed by a number to identify multiple rows. For example, 6yy indicates that six rows are copied from the current row.
Copy one word from yw
Y $ copy to the end of the row
P paste the clipboard content to the current row
P paste the clipboard content to the current row
] P is indented and vim automatically adjusts the code indent.
"A puts the content into/into register a, and supports multiple clipboard
Note: for example, a commonly used register is a system register with the name +. Therefore, the "+ p" command is pasted from the system clipboard to vim. Note that the "+" operator is not represented here, 21 registers.
Move cursor
In vim, the moving cursor is very different from other editors, but once learned, it will quickly move in the text.
H, j, k, l upper, lower, left, right
Ctrl-f ...... the remaining full text>

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.