The Linux text editor

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

One of the most powerful editors VI

1. The difference between VI and VIM

They are multi-mode editor, the difference is that vim is the upgrade version of VI , it is not only compatible with all VI directives, but also some new features inside.

These advantages of vim are mainly reflected in the following aspects:

1. Multilevel undo
We know in VI, press u can only undo the last command, and in Vim can be unlimited undo.

2. Ease of Use

VI can only run on Unix, and vim not only runs on Unix,windows, Mac and other multi-operating platforms.

3. Syntax highlighting
Vim can use different colors to highlight your code.

4. Visual operation
This means that VIM can be run not only at the terminal, but also in X window, Mac OS, Windows.

5. Fully compatible with VI
In some cases, you can use Vim as VI.
VI and VIM are all editors in Linux, the difference is that vim is more advanced, can be regarded as the upgrade version of VI. VI is used for text editing, but Vim is more suitable for coding.

2, VI has 3 modes: insert mode, command mode, low line mode.
Insert mode : Only characters can be entered in this mode, and pressing ESC will return to command mode. (Press "I", "a", "O"in 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 in the command mode) by pressing ":", "/", "?" Enter low-line mode .

3. VI Common commands

Open, save, or close the file (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! Forces the editor to exit without saving

: Wq//Exit editor, and save file

: X//With WQ, save and exit

Insert text or lines (used in VI command mode, enter insert mode after executing the command below, press ESC to exit insert 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)

Last Command Introduction (the low-line mode can also be seen as the commands mode, in order mode, press ":", "/", "?" Enter low-line mode. )

1. Column Travel number
Set Nu: After entering "set Nu", the line number is listed before each line of the article.
2. Jump to a line in an article
#: The pound sign represents a number, enter a number before the last line mode prompt symbol ":", and then press ENTER to jump to the row, such as: 15[enter] will jump to the 15th line of the article. Common
3. Searching for strings
/keywords: first press/, and then enter the word you want to look for, if the first keyword is not as you as possible, you can always press N will look down to the keyword you want.
? Keyword: press first? , then enter the word you want to look for, if the first keyword is not what you want, you can press N to look forward to the keyword you want.
4. Replace string
1, $s/string/replae/g: "1, $s/string/replace/g" will replace the full-text string string with the replace string, where 1, $s means the search interval is the meaning of the article from the beginning to the beginning. , G is an indication that all substitutions do not have to be confirmed.
%S/STRING/REPLACE/C: Similarly, the full-text string string is replaced with the replace string, and the above instruction is different,%s and 1, $s is the same function, and C is to indicate that the substitution must be confirmed again before being substituted.
1,20s/string/replace/g: Replaces a string between 1 and 20 rows with the Relpace string.
5. Save File
W: Press W before the last line mode hint symbol ":" To save the file. [Exceptional]
#,# w FileName: If you want to extract a section of an article and save it as another file, you can use this command # to represent the line number, for example, 30,50 W Nice, to save the 30th to 50th line of the article you are editing into a nice file.
6. Leave
Q: Press Q to leave, sometimes if you cannot leave VI, can be paired with "! : Strong leave VI, such as "q! ”
QW: Generally recommended to leave, with the use of W, so when leaving the file can be saved. Common

VI Command:

command to enter VI
VI FileName: Opens or creates a new file and places the cursor at the beginning of the first
VI +n FileName: Opens the file and places the cursor at the beginning of nth
VI + FileName: Opens the file and places the cursor at the beginning of the last line
VI +/pattern FileName: Opens the file and places the cursor at the first string that matches the pattern
Vi-r FileName: The last time you were editing with VI, a system crash occurred, restoring filename
VI filename....filename: Open multiple files, edit them sequentially

Move Cursor class command
H: The cursor moves left one character
L: Cursor moves right one character
space: Cursor moves right one character
Backspace: Move the cursor left one character
K or ctrl+p: Move the cursor up a line
J or CTRL + N: Move the cursor down one line
Enter: Move the cursor down a line
W or w: Move the cursor to the top of the word
B or B: Move the cursor left one word to the beginning of the word
E or E: Cursor moves right one word j to end
): Cursor moves to end of sentence
(: cursor to top of sentence
}: Cursor moves to beginning of paragraph
{: Cursor moves to end of paragraph
NG: Cursor moves to nth line
n+: Cursor moves down n rows
N: Cursor up n line
n$: Cursor moves to nth line end
H: Cursor moves to top line of screen
M: Cursor moves to middle line of screen
L: The cursor moves to the last line of the screen
0: (note is the number 0) the cursor moves to the current line
$: Cursor moves to the end of the current row


Screen tumbling class command
Ctrl+u: Flip to file half screen
Ctrl+d: Flip to file half screen
Ctrl+f: Flip a screen to the end of the file
Ctrl+b; turn one screen to the top of the file
NZ: Rolls line N to the top of the screen and scrolls the current line to the top of the screen when n is not specified.


Insert text Class command
I: Before cursor
I: At current start of
A: After cursor
A: At end of current line
O: New line below current line
O: New line above current line
R: Replace the current character
R: replaces the current character and its subsequent characters until the ESC key
S: Starts at the current cursor position and replaces the specified number of characters with the entered text
S: Deletes the specified number of lines and replaces them with the text entered
NCW or NCW: Modify the specified number of words
NCC: Modify the specified number of rows


Delete command
NDW or NDW: Delete the n-1 characters at the beginning and after the cursor
Do: Delete to the beginning of the line
d$: Delete to end of line
NDD: Deletes the current line and its subsequent n-1 rows
X or x: Deletes a character, x deletes the cursor, and x deletes the cursor before the
Ctrl+u: Delete text entered under input mode

Search and Replace commands:

/pattern: Search for pattern from the beginning of the cursor to the end of the file
? Pattern: Searches from the beginning of the cursor at the top of the file pattern
N: Repeat the previous search command in the same direction
N: Repeats the last search command in the opposite direction
: s/p1/p2/g: Replaces all P1 in the current row with P2
: n1,n2s/p1/p2/g: N1 overrides all N2 in the P1 to P2 line
: g/p1/s//p2/g: Replace all P1 in the file with P2


option setting
All: List all option settings
Term: Set terminal type
Ignorance: Ignoring case in search
List: Display tab stops (Ctrl+i) and end of line flag ($)
Number: Display line number
Report: Displays the amount modified by the line-oriented command
Terse: Displays a brief warning message
Warn: Displays no write message if the current file is not saved when you go to another file
Nomagic: Allows the use of special characters without "\" in the search mode
Nowrapscan: Prohibit VI when the search reaches the end of the file and starts at the other end
MESG: Allow VI to display information that other users write to their terminal


last-line command
: N1,N2 CO N3: Copy the contents of the N1 line to the N2 row below the N3 line
: n1,n2 m N3: Move the contents of the N1 line to the N2 line below the N3 line
: n1,n2 d: Delete the contents of the N1 row to the N2 row
: w: Save the current file
: E filename: Open file filename for editing
: x: Save the current file and exit
: Q: Exit VI
: q!: Do not save the file and Exit VI
:!command: Execute shell command Commands
: n1,n2 W!command: The contents of the N1 line to the N2 line in the file as input to the command and executed, if not referred to as
N1,n2, the entire file content as input to the command
: r! Command: Place the output of the commands on the current line.

Linux Text editor

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.