This record vim how this text editor is used and how it is used.
Basic Concepts
In the Linux environment, the configuration file is very important for the whole system, and it is all in ASCII plain text, and the text editor can be used to make the configuration easy to modify.
VI is the most common full-screen plain text editor in Unix operating systems and UNIX like operating systems. The VI editor in Linux is called Vim, which is the enhanced version of VI (VI improved), is compatible with the VI editor, and implements many enhancements.
What are the features of vim:
1. All Unix like systems will have a built-in text editor, and other text editors will not necessarily exist
2. Many of the software's editing interfaces will invoke it actively
3. With the ability to edit the program, can be active in font color to identify the correctness of the grammar, convenient programming
4. The program is simple, the editing speed is quite fast
Vim's working mode
Vim works in three modes, namely General mode, edit mode and command mode.
W General mode (input mode)
Vim opens a file directly into the mode (the default mode), in this mode, you can use the next key to move the cursor, delete characters or delete the whole line, you can also copy, paste your file data.
W edit mode
The file contents cannot be edited in general mode. Usually in Linux, when you press the "I, I, A, A, O, O, R, R" keys, an INSERT or replace word appears at the bottom left of the interface for editing.
w Command mode (last line mode)
In the general mode, enter ":,/,?" , you can move the cursor to the bottom line of the current screen. In this mode, you can provide operations to find data, while reading, saving, bulk substitution characters, leaving vim, displaying line numbers, and so on, are also performed in this mode.
vim three modes of switching mode
1. General Mode –> edit mode (Insert mode or Replace mode)
I a o r I a o r
2. Edit mode –> General mode
"ESC"
3. General Mode –> Command mode
: ? /
4. Command mode –> General mode
Double-click "ESC"
The general mode and the edit mode and the command mode can be switched to each other, but the editing mode and the command mode cannot switch to each other.
VIM General operating instructions
1. Turn on VIM
Vim/path/to/somefile
Note that the file name must be appended to the VIM, regardless of whether the filename exists or not.
Vim +#/path/to/somefile
#代表行号, indicates that the cursor navigates directly to the first line after the file is entered.
Vim +/pattern/path/to/somefile
pattern is specified as a string, indicating that the cursor navigates directly to the line where the pattern is located after entering the file
2. Turn off VIM
Enter the relevant command in command mode to exit Vim.
: Q exit
: q! Do not save exit
: Wq save Exit (same as x, ZZ)
VIM General mode operating instructions
w Cursor jump
1. Jump between characters
H: The cursor moves one character to the left
L: The cursor moves one character to the right
J: Move the cursor down one character
K: The cursor moves up one character
#COMMAND #代表数字
2. Jump between words
W: The next word in the position of the cursor
B: The first word in the position of the cursor
E: The next word ending at the cursor position
#COMMAND #代表数字
3. In-line jump
^: jumps to the first non-whitespace character at the beginning of a line
0: Jump to the beginning of the line (function home button)
$: Jump to end of line (function End key)
4. Move between rows
GG: Jump to the first line (same as 1G)
G: Jump to the last line
N[enter]: The current cursor is positioned down n rows (n is a number)
#G
w Edit command
1. Delete command:
X: Delete the character (#x) where the cursor is located
XP: Swap adjacent characters
DD: Delete the entire line where the cursor is located (#dd)
DW, DE, DB, etc.
2. Copy the command:
YY: The entire line where the cursor is copied (#yy)
Y1G, YG, y0, etc.
3. Paste the command:
1) If this copied or deleted content is not a full line
P: Paste until the current cursor is positioned
P: Paste at the front of the current cursor
2) If the contents of this copy are full lines
P: Paste below the line where the current cursor is located
P: Paste above the line where the current cursor is located
4. Change the command:
CC: Deletes the entire line where the cursor is located and waits for the user to type in new content
C $, C0, CW, etc.
5. undo the command:
U: Restore previous action (#u)
[Ctrl]+r: Redo Last Action
. : Repeats the previous action
6. Turn screen operation:
[Ctrl]+[f]: one screen backward
[Ctrl]+[b]: one screen ahead
[Ctrl]+[d]: Back half screen
[Ctrl]+[u]: Forward half screen
operating instructions in vim edit mode
I:insert inserted from the front of the current cursor
A:append inserted from the next Word prompt the current cursor
O:new Line inserts a new row from the next line where the current cursor is located
R:replace replaces the character of the cursor once
I: Inserted in front of the first non-null character in the line where the current cursor is located
A: Inserted from the last word of the line where the current cursor is prompt
O: Insert a new row from the previous line where the current cursor is located
R: Always replace the text of the cursor until the [ESC] key is pressed
operating instructions in the VIM command mode
1. Address delimitation Scope
: Start_pos,end_pos
#: Move the cursor to the current # line (can be with +-sign)
#,#: From start line to end line range
#,+#: Moves backward from the specified line # line ends
. : When moving forward
$: Last line
%; Full text, equivalent to 1,$
/PAT1/: Navigates to the first row that is matched by this pattern (#,/pat1/)
/PAT1/,/PAT2/: From the first match PAT1 line to the first match PAT2 end
After you can follow the edit command: D, y, W, R
2. Find
/pattern: Finds from the current cursor position to the trailer
? PATTERN: Finding from the current cursor position to the header
N: Same direction as command
N: Opposite direction of command
3. Find Replacements
S: To complete the find and replace operation within the bounds of the address
s/what to look for/replace with content/modifiers
What to look for: Available modes
Replace with: You cannot use a pattern, but you can use a back reference symbol to refer to what the grouping brackets in the preceding pattern match to
\1, \2, ...
&: Reference the entire content to which the "what to find" matches
Modifier:
I: Ignore case
G: Global Substitution
/: Used for delimiters, so, to find the content or replace with the content that appears in this symbol, to use \ to escape it, use format: \/
Separators can be replaced with other characters: @, #等
: N1,n2s/word1/word2/g the string between N1 and N2, and replaces the string with Word2.
4. Save and Exit commands
: Wq writes edited data to hard disk file and exits (same as X)
: wq! If the file property is read-only, force the write and exit after saving
: Q Quit Vim
: q! If you have modified a file and do not want to store it, use "! "Do not save files for forced leave
ZZ If the file is not changed, do not save leave. If the file is changed, save and leave
: W[filename] Save edited data to a file (N1,n2w[filename])
: R[filename] In the edited data, read the data from another file, adding the contents of this file to the line following the cursor
:! command to leave vim in the command line mode to perform command display results
operating instructions in the VIM multi-file mode
1. multiple Files open
Vim FILE1 FILE2 ...
: Next goes to the next file
: First to go to file one
:p rev into the previous file
: Last enters the final file
: Files lists all the files that are currently open by this vim
: Wqall Save All Files exit
: Q!all does not save force all files to exit
2. Multi-File window segmentation
Vim–o|-o FILE1 FILE2 ...
-O: Horizontal split
-O: Vertical split
[CTRL+W], arrow keys indicate file direction
3. Single File window segmentation
[Ctrl+w], S: Split horizontally
[Ctrl+w], V: Vertical split
Customizing the working characteristics of vim
1. Line number
Display: Set number
Disabled: Set Nonumber
2. Matching brackets
Display: Set SM
Disabled: Set NOSM
3. Auto Indent
Display: Set AI
Disabled: Set Noai
4. Highlight Search
Display: Set Hlsearch
Disabled: Set Nohlsearch
5. Syntax Coloring
Display: Syntax on
Disabled: Syntax off
6. Ignore character case
Display: Set IC
Disabled: Set Noic
How the Vim feature is permanently enforced
Global configuration file:/ETC/VIMRC
User's personal Profile: ~/.VIMRC (default does not exist)
This article is from the "Craft Life" blog, so be sure to keep this source http://allenh.blog.51cto.com/481430/1693499
Linux Learning: Vim program Editor