LINUX Vim Editor

Source: Internet
Author: User
Tags class definition save file

VI has 3 modes: insert mode, command mode, low line mode.

Insert mode: You can enter characters in this mode and press ESC to return to command mode.

Command mode: You can move the cursor, delete characters, and so on.

Low-line mode: can save files, exit VI, set VI, Find and other functions (low-line mode can also be seen as a command mode).

One, open file, save, close file (used in VI command mode)

VI filename//open filename File
: w//Save File
: w vpser.net//Save to Vpser.net file
: Q//Exit editor, if the file has been modified please use the following command
: q! Exits the editor without saving
: Wq//Exit editor, and save file

Second, insert text or lines (vi command mode to use, after executing the following command will enter the insertion mode, press ESC to exit the insertion mode)

A//Add text to the right of the current cursor position
I//Add text to the left of the current cursor position
A//Add text at the end of the current line
I//Add text at the beginning of the current line (the beginning of a non-empty character)
O//Create a new row above the current line
O//Create a new row below the current line
R//replace (overwrite) the current cursor position and several subsequent text
J//Merge cursor row and next line of behavior (still in command mode)

Third, move the cursor (used in the VI command mode)

1, use the upper and lower left and RIGHT arrow keys

2, Command mode: H left, J down, k up, l to the right.

Spacebar to the right, Backspace left, Enter to the next line,-move to the top of the line.

Iv. Delete, restore characters or lines (used in VI command mode)

X//Delete current character
NX//delete n characters starting from the cursor
DD//Delete when moving forward
NDD//Down Delete the current row, including n rows
U//Undo Previous action
U//Undo all operations on the current line

V. Search (used in the VI command mode)

Special characters (five, ix):

^: Beginning of line indicator $: Trailing indicator.: Any character indicator

\<: Character start indicator \>: Character End indicator *:0 this or multiple occurrences

[]: Character class definition

/vpser//Search for Vpser strings under cursor
? vpser//Searching for vpser strings on the cursor
N//down searches for previous search action
N//Up search previous search action

Six, jump to the specified line (vi command mode use)

n+//Jump down N rows
N//Jump up N rows
NG//jumps to rows with line number n
G//Jump to the bottom of the file

Seven, set the line number (vi Command mode use)

: Set nu//Display line number
: Set Nonu//Suppress line numbers

Eight, copy, paste (used in the VI command mode)

YY//Copy the current line to the buffer, you can also use "Ayy copy," A is a buffer, a can also be replaced by any letter A to Z, you can complete multiple replication tasks.

Nyy//Copy the current row down n rows to the buffer, or you can use "Anyy copy," A is a buffer, a can also be replaced with any letter A through Z, you can complete multiple replication tasks.

YW//Copy the character from the beginning of the cursor to the ending.

NYW//Copy n words starting from the cursor.

y^//Copy the contents from the cursor to the beginning of the line. VPS Detective

y$//Copy the contents from the cursor to the end of the line.

P//Paste the contents of the Clipboard after the cursor, if the previous custom buffer is used, it is recommended to use the "AP to paste."

P//Paste the contents of the Clipboard before the cursor, if the previous custom buffer is used, it is recommended to use the "AP to paste."

Ix. replacement (used in the VI command mode)

: S/old/new//Replaces the first occurrence of old in a row with new
: s/old/new/g//Replace all old in line with new
: n,m s/old/new/g//Replace all old from N to M with new
:%s/old/new/g//Replace all old in current file with new

X. Editing other documents

: E otherfilename//edit file named Otherfilename.

Xi. Modifying file formats

: Set Fileformat=unix//modify the file to UNIX format, such as win below the text file under Linux will appear ^m.

12, vim-read the file

The Read (: R) Read command reads the file into the work buffer. The new file does not overwrite any text in the work buffer, but is positioned after the address specified in the command (if no address is specified, it is the current row). Use address 0 to read a file into the beginning of the work buffer.

The read command syntax format is as follows:

: [address]r [filename]

1. If you omit address and filename, Vim reads from disk to the file that the user is editing, and the text content is on the next line of the current cursor.

2. Insert the contents of another file MyFile.txt in the current file Hello.txt:

Hello.txt its content is: Hello world!

MyFile.txt its contents are: This is a file.

#vim Hello.txt

#:r myfile.txt

The contents of the Hello.txt file are as follows:

Hello world!

This is a file.

3. Insert the contents of another file at the beginning of the current file:: 0r filename

We can use numbers to specify after which line to start inserting the contents of another file, for example: #vim hello.txt#:3r myfile.txt Inserts the contents of MyFile.txt into the 3rd line of the current file. Similarly, 0r myfile.txt inserts the contents of the myfile.txt into the No. 0 line of the current file, which is where the file first begins (although there is no real No. 0 line in the file, but we can take advantage of it). 13 vim-Write FilesWrite (: w) write command to write some or all of the contents of the work buffer to the file. The address can be used to write part of the work buffer to a file specified by the file name. If you do not specify an address or file, Vim writes the contents of the entire work buffer to the file being edited and updates the files on the disk.

The read command syntax format is as follows:

: [address]w [filename]

: [address]w[!] [FileName]

:[address]w>> [FileName]

Example:

: w MyFile.txt writes the contents of the current file to MyFile.txt if the file

Existing, the error will not modify the original content. : w! MyFile.txt writes the contents of the current file to MyFile.txt, overwriting the original content if the file already exists. : w >>myfile.txt appends the contents of the current file to the end of the file myfile.txt.

LINUX Vim Editor

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.