Vim Editor
Our computer's editor is divided into two categories
1, Text editor
The text editor edits the pure ASICLL document without any extra modifiers
2, Word Processor
Word processors include Word documents, word processing tools inside WPS, with many modifiers, but modifiers are not related to file content, but modifiers are an effective part of document data.
One of the important philosophical ideas of Linux: Use plain text files to save configuration information for the software, all files.
The Linux editor has the Nano Full screen editor, the SED line editor, and the most commonly used Vi/vim editor.
VI (Visual interface-> visual Interface) editor
Vim Editor->vi improved: syntax coloring feature.
Vim is a full-screen editor with a modal editor (different modes correspond to different functions).
Vim mode (with up to three main modes):
Edit mode (Command mode): The default mode in which the editor is opened and the entire document can be edited at this time.
Input mode: The mode of entering content into a file
End-of-line mode: At the bottom of the entire screen (not the last line of the file), type some mode for editing commands.
Usage of VIM
1. Open File
Usage format: VIM filename
->vim/path to/somefile: Open a single file, the file's parent directory must exist, the file's base name does not matter, the existence of open, does not exist is equivalent to a new file.
->vim +# FileName: Immediately after opening the file, leave the cursor on line # of the file.
->vim + FileName: Immediately after opening the file, leave the cursor in the last line of the file.
->vim also supports the use of patterns when opening files:
Vim +/pattern FileName: Navigates to the beginning of the line that was first matched to the pattern.
When the file is opened, it is in edit mode by default, and the mode and mode can be converted to each other.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/84/91/wKioL1eVcfSSo1yEAAA4T35mPVs140.png "title=" 1ssx0) (%h93ennr4}6p]b6q.png "alt=" Wkiol1evcfsso1yeaaa4t35mpvs140.png "/>
Mode conversion:
Edit mode--Input mode:
I (insert): Indicates that the character before the current cursor is converted to input mode.
I: Indicates that the line at the beginning of the current cursor is converted to input mode.
A (Append): Represents the conversion to input mode after the character of the current cursor.
A: Indicates that the end of the line at the current cursor is converted to input mode.
O: Create a new line below the current cursor line and convert to input mode.
O: Creates a new row above the line where the cursor is currently positioned and converts to input mode.
Input mode--edit mode:
ESC key
Edit mode--and last-line mode:
You only need a colon: you can.
In the last line mode:
->10D: Delete line 10th
->10,20d: Delete lines 10th through 20th
->set nu: Display line number
Also can execute shell command directly, format:! Shell command, and then press ENTER again to return to the previous interface.
Last-line mode--edit mode:
ESC key
The input mode and the last line mode cannot be converted to each other, and must be converted through edit mode.
2. Close File
The ability to close files is generally done in edit mode or in the last line mode.
(1) in the last line mode:
->q: Do not save exit if file is not changed
->WQ: Save and launch
->q!: Do not save, forcibly quit
->w: Save files, saved, read-only file changes cannot be saved (this is not effective for administrators)
->w!: Force save (only administrators can do this)
->x: Save exit, equivalent to Wq
(2) Edit mode:
->zz: Save and exit
3, move cursor
Move the cursor in edit mode
(1) Move the cursor character by word:
->H: Move cursor to the left
->L: Move the cursor to the right
->J: Move Cursor down
->K: Move Cursor up
Support # Features: #h, l,j,k
(2) Move the cursor by word
W-> move to the beginning of the next word
E-> If the cursor is not at the ending of the current word, move to the ending of the current word and then to the ending of the next word
B-> If the cursor is not at the beginning of the current word, move to the beginning of the current word and move to the beginning of the next word.
Support # Features: #w, e,b
(3) in-line movement
0-> move to beginning of line (absolute beginning)
^-> the first non-whitespace character moved to the beginning of a line
$-> move to absolute end of line
(4) Moving between rows
Move directly to Line # #G
G-> move to the last line
Move between rows in the last line mode:#-> move directly to line #
4, turn screen operation
(1) CTRL+F: Flip one screen down
(2) Ctrl+b: Turn up one screen
(3) Ctrl+d: Flip Down half screen
(4) Ctrl+u: Flip up half screen
5, Edit command
(1) Delete or single character
->x: Delete A single character at the cursor location
#x: Remove the total # characters from the cursor and backwards
(2) Delete command D
To be used in combination with the Move command, you can specify how much content to delete
#d跳转符: Delete the # items specified by the jump character
->DD: Deletes the current cursor in the row
-#dd: Delete the # line that includes the line where the current cursor is located
In the last row mode: startaddress,endaddress Delete all rows in the range
(3) .-> said that when the forward
$-> indicates the last line
+#-> Down # line
Vim's recently deleted n content is not immediately emptied, but is stored in the memory buffer, can be restored, and can undo previous edits, and vim can also be cut.
6, Paste command p (paste)
p-> If you delete or copy an entire line of content, paste to the bottom of the line where the cursor is located, and if the copied or pasted content is a non-full row, paste it after the character that contains the cursor.
p-> If you delete or copy the entire line, paste to the top of the line where the cursor is located, and if the copied or pasted content is a non-full row, paste it in front of the contents of your cursor.
7, copy command y
Usage with delete command d
8, modify command C
Delete content first, then convert to input mode
Usage with delete command d
9, replace command R
Function: Replace the specified content with a character directly
R-> directly into replace mode: replaces the character directly with what the user has typed.
10, Undo Edit Operation Command U
->u (undo): Undo the previous edit operation
Continuous press U to undo the previous N operations
The VIM editor typically saves only the last 50 operations in its memory buffer, undoing most of the last 50 edits, and also supports #u operations.
Restore the most recent undo action (Prevent do not undo): Ctrl+r
11, repeat the previous edit Operation command.
12, Visualization mode
->v or v command
V: Select by character, select the character where the cursor is located
V: Select by Rectangle block, select the row where the cursor is located
13, find function (regular expression support)
In the last line mode
->/pattern: Search from file header to end of file
->?pattern: Looking at the file header from the cursor location
N: Move to the next matching character
N: Move the first match to a character
14, find and replace
Can only be used in the last line mode.
Usage: identical to sed command
s command, first bound and then replaced
Format: Addr1,[email protected]@[email protected]
->g: Represents a global substitution
->i: Indicates ignoring character case
G and I can be used simultaneously
1,$: Indicates full-text lookup and replace
%: Indicates full-text find and replace
15, use Vim to edit multiple files
Usage format: Vim file1 file2 ...
In the last line mode:
next-> to switch to the next file
Prev-> means to switch to the previous file
Last-> means to switch to the last file
First-> means to switch to the first file
Qa-> means to exit all files
16, how to display a file in a window
->ctrl+w,s: Represents a horizontal splitter window
->ctrl+w,v: Represents a vertical splitter window
To switch between windows:
Ctrl+w,arrow
:qa-> close all windows in last-line mode
17. How to display multiple files in a window
->vim-o: Horizontal Split Display file
->vim-o: Vertical Split Display file
18, how to save part of the current file as a different file
Use the W command in the last row mode
Usage Format->->addr1,addr2w/path to/somewhere
19, how to populate the contents of another file into the current file
Use the R command in the last row mode
Usage Format->r/path to/somefile
20, how to interact with the shell
Usage format, using the last line mode:! Command
21, Advanced Topics
(1) Display or suppress line numbers
In the last line mode:
Set number = Set Nu-Displays line numbers
Set Nonu, suppress line numbers
All methods, similar to this one, are only valid for the current process and must be changed to the Vim configuration file for permanent operation.
(2) display ignores or distinguishes character case
In the last line mode:
Set ignorecase = Set IC Ignore character case
Set Noic character case
(3) Set auto indent
In the last line mode:
Set autoindent = set AI-Auto indent
Set Noai, Cancel Auto Indent
(4) Check the found text highlighting or canceling
In the last line mode:
Set Hlsearch, highlighting
Set Nohlsearch, suppress highlighting
(5) Syntax coloring
In the last line mode:
Sytax on--syntax coloring
Syntax off syntax coloring
22,vim configuration file
The vim configuration file is divided into two categories
Global:/ETC/VIMRC, changing this configuration file will take effect for all users.
-A non-global: ~/.VIMRC, changing this profile only takes effect for the current user, and if not, you can create a new one yourself.
Vimtutor->vim Tutor, teach us how to use VIM, the system comes with.
When vim exits a file illegally, a. swap file with the same name as the file is generated in the current user's home directory, so long as the file exists, the system will definitely get an error when the user wants to open the file again, and the workaround is to vim-r open the file, Either delete the. swap file directly or select the option you want in error mode.
This article is from the "Novice Technical Documents" blog, please be sure to keep this source http://zhubo.blog.51cto.com/11395641/1829567
Rookie of the Linux hard Road 4 Vim editor