Vim Common techniques:
Change the carriage return from the default 8 spaces to 4 spaces:
Command:set sw=4
Modify tab to 4 spaces:
Command:set ts=4
Set the indent length for each level:
Command: Set shiftwidth=4
Encoding of the settings file:
Set Fileencoding=utf-8
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: Move the cursor one character to the left
L: Move the cursor right one character
Space: Move the cursor right one character
Backspace: Cursor moves left one character
K or ctrl+p: Move the cursor up one line
J or CTRL + N: Move the cursor down one line
Enter: Move the cursor down one line
W: The cursor moves right one word to the beginning of the word
W: Cursor moves forward one string
B: The cursor moves left one word to the beginning of the word
B: The cursor moves backwards one string
E or E: Move the cursor right one word to the end of the word
GE: Move to the end of the previous word
): Move the cursor to the end of the sentence
(: The cursor moves to the beginning of the sentence
}: Move the cursor to the beginning of the paragraph
{: Cursor moves to end of paragraph
NG: Cursor moves to the beginning of nth
n+: The cursor moves down n rows
N: Move the cursor up n rows
n$: Cursor moves to end of Nth line
H: Move the cursor to the top row of the screen
M: Move the cursor to the middle line of the screen
L: The cursor moves to the last line of the screen
0: (note is the number 0) cursor moves to the beginning of the current line
^: Move to the first non-empty character of the current line
$: Cursor moves to the end of the current line
%: Move to curly braces, parentheses, brackets corresponding to the other half brackets.
GG: Moving to the top of the document
NG: Moving to the beginning of nth
G: Move to end of document
50%: Move to the middle of the file
H: Move to the first line of vision
M: Move to the middle of the field of view
L: Move to the end of the field.
Ctrl+g: Show file name, total number of rows, current location
CD: Displays the current working directory
Ma [A-z] mark a specific position, use ' x or ' x to jump to the marker position, use ' or ' to jump back to the location
Screen Tumbling Class command
Ctrl+u: First half screen to file
Ctrl+d: Half-screen to the end of the file
CTRL+F: Flip a screen to the end of a file
ctrl+b; Turn one screen to the top of the file
Ctrl+e: Rolling a line to the end of the question price
ZZ: Place the cursor in the middle of the screen
ZT: Move the cursor to the top of the screen
ZB: Move the cursor to the bottom of the screen
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.
Set Scrolloff=n: Place cursor at Nth row
Insert Text Class command
I: Before the cursor
I: At the beginning of the current
A: After the cursor
A: At the end of the current line
O: A new line below the current line
O: New row above the current line
R: Replace the current character
R: Replaces the current character and its characters until the ESC key is pressed
S: replaces the specified number of characters with the input text starting at the current cursor position
S: Deletes the specified number of rows and replaces them with the input text
NCW or NCW: Modifies a specified number of words
NCC: Modifying a specified number of rows
Delete command
NDW or NDW: Delete the n-1 characters at the beginning and after the cursor
DW Delete a Word
Daw Delete a word and a space character after the word
Do: Delete to the beginning of the line
d$: Delete to end of line
DN: Delete n+1 rows
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
J: Delete the newline character between the line of the cursor and the next row
Undo command:
U: Undo a previous action, such as a delete operation
Ctrl+r Redo the action you just made
. Repeat the last modification operation with dot notation
Search and Replace commands
/pattern: Searches for pattern at the end of the file from the beginning of the cursor
? pattern: Searches for pattern from the beginning of the cursor to the top of the file
N: Repeat the last 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: All P1 in line N1 to N2 are replaced with P2
: g/p1/s//p2/g: Replace all P1 in the file with P2
Set Ignorcase Ignore case when finding
Set Noignorecase case-sensitive when looking up
Set Hlsearch setting query result highlighting
Set Nohlsearch Cancel Query result highlighting
Option settings
All: List all option settings
Term: Set terminal type
Ignorance: ignoring case in search
List: Display tab stops (CTRL+I) and end-of-line flags ($)
Number: Show line numbers
Report: Displays the number modified by the line-oriented command
Terse: Displays a short 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 that are not preceded by "\" In search mode
Nowrapscan: Prohibit VI from the other end when the search reaches the end of the file
MESG: Allow VI to display information that other users write to their terminal using write
Last line mode 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 N1 rows to N2 rows
: w: Save current file
: E filename: Open file filename for editing
: x: Save current file and exit
: Q: Exit VI
: q!: Do not save file and Exit VI
:!command: Execute shell command
: n1,n2 W!command: The contents of the N1 line to the N2 line in the file are entered as command and executed, and if N1,N2 is not specified, the entire file content is entered as the command
: R!command: The output of command commands is placed in the current line
Register operation
"? Nyy: Saves the contents of the current row and its next n rows to the register?" , where? is a letter, n is a number
"? NYW: Saves the current line and its next n characters to the register?" , where? is a letter, n is a number
"? Nyl: Saves the current line and its next n characters to a register?" , where? is a letter, n is a number
"? P: Remove the Register?" and place it at the cursor position. Over here? Can be a letter, or it can be a number
NDD: Deletes the current line and its total n lines of text, and places the deleted content in the 1th delete register.
Vim Change font July 24, 2011 Sunday 3:35
Under normal vim, the font is nothing to change, because its font is limited by the terminal's settings. But in Gvim, you can change the way you want to change the font.
The main commands for changing fonts under Linux are this:
: Set Guifont=courier\ 14
You can change the courier to any font you want, and 14 is the font size you want to change (in PT).
To change the font under Windows, use the following command:
: Set guifont=courier:14
If you're not sure if you have that type of font on your computer, you can add a comma to the command above and then add another font. Such as:
: Set Guifont=courier\ new\, arial\ 10
If you have a space or comma in your font name, you need to escape it with a backslash. Such as:
: Set Guifont=courier\ new\ 12
This command is to set the font to courier New, size 12th, but is only available in this session, that is, when Gvim is turned off, it will return to its original configuration. If you want to use this font every time you edit a file, you should add a line above the same command in the GVIMRC file (but be careful not to set the preceding colon ': ').
[note] When you are in Windows, Linux (using GTK +), Mac OS, or photon, you can use the following font to open a font list: : Set guifont=*
If you want to make your font settings change based on the edited file (code, text, log, etc.), you can set vim to let it change the current font by the type of file. For example, if you want to use the Arial 12th font every time you open a text file (. txt), you can add such a piece to the VIMRC file:
Autocmd bufenter *.txt Set guifont=arial\ 12
The Gvim window changes the window size automatically at each change in the font. In other words, if you use a small font, you will get a small window by default. If you have several configurations like the ones above, several different file types, corresponding to several different fonts, you will obviously feel this change. When you open a file of another type, the font and window size change.
[note] You can find more information about changing fonts in the Vim Help system by: ' Guifont '
|
One, vim open the document:
1. Vim Document name Open document in normal way
2. Vim +n document name after opening the document, position the nth row
3. Vim, after entering the Vim interface, use the command: E document name to open the document, this way you can edit a document while opening another document
4. Display the current document directory: Press 1 First, then ctrl+g
5. CD #改变vim的当前工作路径
6.LCD #改变当前窗口的工作目录
7.pwd #查看当前的工作路径
8.set Autochdir #自动设当前编辑的文件所在目录为当前工作目录
Second, multi-document editing:
1. Vim Document 1 Documents 2 ...
2. Vim, after entering vim use: E Document name Open document
3. The commands for multi-document editing are as follows
: N edits the next document.
: 2n edit the next two documents.
: N edits the previous document. Note that this method can only be used to open multiple documents at the same time.
: E document name This is the case when you enter vim and open other documents without leaving Vim.
: e# or ctrl+ˆ edits the previous document for use when two documents are exchanged for editing. # represents a document that was edited the previous time
: Files or: buffers or: LS to list all documents in the current buffer. The Plus + indicates that the buffer has been modified. # represents the last edited document,% is currently being edited in the document
: b The document name or number is moved to the document.
: F or Ctrl+g Displays the name of the document that is currently being edited.
: F Name changes the name of the document in the edit. (file)
Third, leave Vim
: Q If the text is not modified, it exits, otherwise a warning appears and cannot be left.
: q! Discard all changes and forcibly leave.
: Wq saved and left even if the document has not been modified, it will be saved again.
: x save and leave, the document will not be saved if not modified, go directly.
: The W document name is: Save As. The non-document name is written to the original file.
: QA or qa! Leave vim in the case of multiple documents open. A is the meaning of all.
: ZZ saves and exits the current text
Add external content to a document that is already open using the following command (double quotes + plus sign +p):
"+p
Four, multi-window editing
: SP document name opens a document in a new window
Ctrl+w+n Create a new window
Two times Ctrl + W to switch windows
Ctrl+t Jump to previous window
: Q Exits the current editing window
Use CTRL +] in the help document to jump to the hyperlink, using Ctrl+t or ctrl+o to jump to the previous position.
Three ways to modify text:
Operator-action, visual mode, and text object
C2wxxx modify the distance of two words and insert xxx
CC modifies an entire line (the indentation of this line is preserved)
C $ change to end of line
X=DL Delete a character under the current cursor
X=DH Delete the character to the left of the cursor
d=d$ Delete to end of line
c=c$ Modify to end of line
S=cl Modifying a character
S=CC Modifying a whole line
P Paste the content you just deleted after the cursor
P paste what you just deleted in front of the cursor
XP first deletes, then pastes, deletes one character and then pastes it behind another character, for example, after the teh operation becomes the
X Delete the character under the cursor ("DL" abbreviation) x Delete the character before the cursor (abbreviation for "DH") D Remove from the current position to the end of the line (abbreviation for "d$") DW deletes from the current position to the beginning of the next word db removes from the current position to the beginning of the previous word DIW Delete words on the cursor (excluding whitespace characters) Daw delete words on the cursor (including whitespace characters) DG Delete to the end of the file DGG delete to the top of the file
Visual mode:
V Enter visual mode with V and select any number of text
o When the text is selected in visual mode, use O to move the cursor to the other end of the selection
Y copy
YY Copy a whole line
YW copy a word and then paste it with P
Text objects:
CIS modifies a sentence to indicate change inner sentence
CAS is a sentence that differs from the above action in that the as contains white space characters after the sentence
Das deletes a sentence, including the white space character after the sentence
Replacement mode:
R-Uppercase R commands can use a continuous substitution pattern, use lowercase r to replace only one character, and use the backspace backspace to reply to the substituted character.
~ Modify the casing of characters under the cursor
I uppercase I begins inserting in the first non-null character of the current line
A moves to the end of the line to start inserting
From for notes (Wiz)
Vim Common techniques: