"General Settings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Set default decoding
Set Fenc=utf-8
Set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
"Do not use VI keyboard mode, but vim own
Set nocompatible
"Number of rows in the history file that need to be logged
Set history=100
"Eject confirmation when processing unsaved or read-only files
Set confirm
"Share clipboard with Windows
Set clipboard+=unnamed
"Reconnaissance file type
FileType on
The Load file type plug-in
FileType plugin on
"Load a related indent file for a specific file type
FileType indent on
"Save Global variables
Set viminfo+=!
"Words with the following symbols should not be separated by line breaking
Set iskeyword+=_,$,@,%,#,-
The syntax highlights
Syntax on
"Highlight character so that it is not subject to the 100 column limit
: Highlight overlength ctermbg=red ctermfg=white guibg=red guifg=white
: Match overlength '/%101v.* '
The status line Color
Highlight Statusline Guifg=slateblue Guibg=yellow
Highlight Statuslinenc Guifg=gray Guibg=white
The File Settings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Do not back up files (depending on your needs)
Set Nobackup
"Do not generate a swap file, hide it when the buffer is discarded
Setlocal Noswapfile
Set Bufhidden=hide
"Character Fu the number of pixel rows inserted
Set linespace=0
Automatic command line completion in enhanced mode
Set Wildmenu
"Displays the line and column numbers at the position of the cursor on the status line
Set ruler
Set Rulerformat=%20 (%2*%
The height of the command line (under the status line), defaults to 1, here is 2
Set cmdheight=2
"Make The Back Space bar (BACKSPACE) normal processing indent, EOL, start, etc.
Set backspace=2
"Allows backspace and cursor keys to cross line boundaries
Set Whichwrap+=,h,l
"You can use the mouse anywhere in the buffer (similar to double-clicking the mouse in the workspace in office)
Set Mouse=a
Set selection=exclusive
Set Selectmode=mouse,key
"By using: Commands command, tell us which line of the file has been changed
Set report=0
"Displays whitespace between partitioned windows for easy reading
Set fillchars=vert:/, stl:/, stlnc:/
The Search and match
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Highlight matching brackets
Set Showmatch
"Match the time of the brace highlighting (in a very second)
Set matchtime=5
"Ignore case when searching
Set ignorecase
"Do not highlight the searched sentence (phrases)
Set Nohlsearch
"When searching, enter words verbatim Fugauliang (similar to Firefox search)
Set Incsearch
"Input: The set list command should show something."
Set listchars=tab:/|/, Trail:.,extends:>,precedes:set scrolloff=3
"Do not blink
Set Novisualbell
"The content that my status line displays (including file types and decoding)
Set Statusline=%f%m%r%h%w/[pos=%l,%v][%p%%]/%{strftime (/"%d/%m/%y/-/%h:%m/")}
"Always Show status line
Set laststatus=2
"Text formatting and typesetting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
The Automatic formatting
Set FORMATOPTIONS=TCRQN
"Inherits the indentation of the previous line, especially for multiline annotations
Set Autoindent
"Provides automatic indentation for C programs
Set Smartindent
"Use C-style indentation
"Set Cindent
"tab is 4 Unified indent to 4
Set tabstop=4
Set softtabstop=4
Set shiftwidth=4
"Replace tabs with spaces
Set Expandtab
"Do not change lines
Set nowrap
"Ctags's setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Sort by name
Let Tlist_sort_type = "name"
The display window on the right
Let Tlist_use_right_window = 1
The compression method
Let Tlist_compart_format = 1
"If there's only one Buffer,kill window, kill the buffer.
Let Tlist_exist_onlywindow = 1
"Do not close tags for other files
Let Tlist_file_fold_auto_close = 0
"Do not show the collapse tree
Let Tlist_enable_fold_column = 0
"Autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Displays line numbers only when the following file types are detected, normal text files are not displayed
If has ("Autocmd")
Autocmd FileType Xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby Set number
Autocmd FileType xml,html vmap ' <em>o ' >o-->
Autocmd FileType java,c,cpp,cs vmap ' >o*/
Autocmd FileType Html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100
Autocmd Filetype html,xml,xsl Source $VIMRUNTIME/plugin/closetag.vim
Autocmd Bufreadpost *
/If Line ("'/") > 0 && Line ("'/")/exe "normal g '/" "|
/endif
endif "has (" Autocmd ") </em>
"F5 compiles and runs C programs, F6 compiles and runs C + + programs
"Note that the following code is used under Windows to give an error
"Need to be removed./These two characters
"C's compilation and running
Map:call COMPILERUNGCC ()
func! COMPILERUNGCC ()
Exec "W"
Exec "!gcc%-o% exec"!./% Endfunc
"C + + compile and run
Map:call COMPILERUNGPP ()
func! COMPILERUNGPP ()
Exec "W"
Exec "!g++%-o% exec"!./% Endfunc
"Can be beautifully displayed. NFO file
Set Encoding=utf-8
function! Setfileencodings (Encodings)
Let B:myfileencodingsbak=&fileencodings
Let &fileencodings=a:encodings
Endfunction
function! Restorefileencodings ()
Let &fileencodings=b:myfileencodingsbak
Unlet B:myfileencodingsbak
Endfunction
Au bufreadpre *.nfo call setfileencodings (' cp437 ') |set ambiwidth=single au bufreadpost *.nfo call restorefileencodings ()
"Highlight plain TXT file (requires Txt.vim script)
Au bufread,bufnewfile * Setfiletype txt
"Use the space bar to switch folding
Set foldenable
Set Foldmethod=manual
Nnoremap @= (foldclosed (Line (')) < 0)? ' Zc ': ' Zo ')
The general settings for the MINIBUFEXPL plug-in
Let G:minibufexplmapwindownavvim = 1
Let G:minibufexplmapwindownavarrows = 1
Let G:minibufexplmapctabswitchbufs = 1
Let G:minibufexplmodseltarget = 1
Vim shortcut key:
Cursor Movement: Four Directions
K
H 0 L
J
Ctrl+f, ctrl+b Page DOWN, PAGE up
Ctrl+d, ctrl+u down half page, up half page
$ move end of line
0 moving the beginning of the line
W Move Next word
b move to the previous word
GG jumps to the beginning of the document
G jumps to the end of the document
% jumps to matching brackets ("{}" [] "()")
Ctrl+i,tab jumps to the next jump point
Ctrl+o jumps to the previous jump point
23gg, 23G,: 23 Jump to line 23rd
Ctrl+i, tab jumps to the next hop (Jump point)
Ctrl+o jumps to the previous hop point
Find Replacement:
# Search the entire keyword backwards from the cursor
* Search the entire keyword forward from the cursor
g# Search for keywords from the cursor backwards
g* Search for keywords from the cursor forward
Fx,tx,fx,tx find characters on current line
Find Replacement Example:
: S/search/replace
: S/if/since Replace the next "If" with "Since"
:%s/if/since will replace All "If" with "Since"
: 1,3 s/if/since/g only valid for 1, 3 lines, such as no prefix, only valid for current line
An expression:
. Instead of one character
* Represents the repetition of one or more characters
/d.*an can match Dan, Divan, Debian
Word boundaries:
Specify a word boundary:/
such as:///Match to start with D, include any lowercase letters in the middle, and the word ending with an
$[0-9]*/. [0-9] [0-9] Match lookup $XX ... X.XX, there are only two decimal digits.
Common editing commands:
A, I insert after the cursor, insert in front of the cursor
DD Deletes a row
Cc,s after deleting a row and entering insert mode
DW Delete a Word
CW enters insert mode after deleting a word
X,DL Delete a character
S,CL Delete a character and enter insert mode
P Paste
XP swap two characters
DDP Exchange Two Lines
Y replication
YY Copy Row
U undo
Ctrl+r Redo.
. Repeat last Modification
Ctrl+r Redo.
. Repeat last Modification
Divide panes:
: Split/vsplit Separates a window
: New/vnew to create a new window
: SF {filename} opens filename in a new window
: Close closes the current window
: Only close all windows except the current window
: Ctrl-w h to the left window
: Ctrl-w J to the window below
: Ctrl-w K to the above window
: Ctrl-w l to the right window
: Ctrl-w T to the top of the window
: Ctrl-w B to the bottom of the window
Repeat action (macro action):
Q[A-Z] starts recording operations, logging to registers [A-z]
Q Stop Recording operations
@[a-z] Perform operations in registers
@@ 执行 The actions recorded in the most recent registers
Example: A buffer has two lines:
Sys/types.h
Stdio.h
–> to read:
#i nclude
#i nclude
The operation is as follows:
QA #开始记录
^ #移动行首
I #进入insert模式
#i nclude #输入内容
Q #停止记录
To move another line:
@a can perform the same operation
Visual mode operation:
CTRL + V enters a block based visual mode
V into a character-based visual mode
V into a line based visual mode
C Delete the selected block
I{string} when the block is selected, capitalize I, enter the string, and then press ESC to insert the same content in each row of the block
Skip to Declaration:
[[Jump forward first ' {' of the top pane]
[] jumps forward to the first "}" of the top grid
[Jump back to the top of the first "{"
]] jumps back to the first "}" of the top grid
[{Skip to the beginning of this code block (defined by {})
[} Skip to the end of this code block
Shell:
: Ctrl+z/suspend under the shell is suspended vim; Minimized window under GUI
:! {command} executing shell commands
: Shell opens a new shell
Save Vim status (suspend?) :
: mksession Session.vim Save current vim state
: Source Session.vim back to vim state
Vim-s Session.vim Resume session when starting VIM
Some of the commonly used commands (motion):
FX: Moves the cursor to the next X at the current line. Obviously, X can be any letter, and you can use it to repeat your last F command.
TX: Similar to the above command, but is moved to the left of X position. (This is really useful)
FX: Similar to FX, but looking backwards.
W: The cursor moves one word forward.
B: The cursor moves one word backward.
0: Move the cursor to the current beginning of the line.
^: Moves the cursor to the first letter position of the current line.
$: Move the cursor to the end of the line.
): Move the cursor to the next sentence.
(: Move the cursor to the previous sentence.)
Effectively move the cursor throughout the file
Vim has a lot of commands that you can use to get where you want to go in the file. Here are some commands to move within a file:
: Move down one screen.
: Move up one screen.
G: To the end of the file
NUMG: Moves the cursor to the specified line (num). (for example, 10G is to line 10th)
GG: To the top of the file
H: Move the cursor to the top of the screen
M: Move the cursor to the middle of the screen
L: Move the cursor to the bottom of the screen
*: Reads the string at the cursor and moves the cursor to where it appears again.
#: Similar to the above, but looking in the opposite direction.
/text: Searches the string text from the current cursor and arrives where text appears. You must use ENTER to start this search command. If you want to repeat the last search, press N.
。 Text: Similar to the above, but in the opposite direction.
MA: Marks a bookmark at the position of the current cursor, named A. A book signature can only be a lowercase letter. You can't see the bookmark, but it's already there.
' A: to bookmark a. Note that this is not a single quote, it is generally located on the left side of 1 of most keyboards.
'.: To the place where you last edited the file. This command is useful, and you don't have to mark it yourself.
I: Inserts to the left of the current character
I: Inserts at the beginning of the current line
A: Inserts to the right of the current character
A: Inserts at the end of the current line
O: Inserts a new row below the current line
O: Inserts a new row above the current line
C{motion}: Deletes the characters spanned by the motion command and enters insert mode. For example: C $, this will remove the character from the cursor position to the end of the line and enter insert mode. Ct. , this deletes from the cursor position to the next exclamation mark (but not included), and then enters insert mode. The deleted characters are present inside the Clipboard and can be pasted again.
D{motion}: Similar to above, but not into insert mode.
Effectively move large segments of text
Using Visual Selection (visual selections) and the appropriate selection mode
Don't want the initial vi,vim to allow you to highlight (select) some text and to do the operation. There are three types of visual selection modes:
V: Select by character. Always use the pattern, so try it yourself.
V: Select by line. This is especially useful when you want to copy or move a lot of lines of text.
: Select by block. Very powerful, only in a very small number of editors to have such a function. You can select a rectangular block, and the text inside the rectangle will be highlighted.
Use the arrow keys and commands described above when selecting a mode (motion). For example, VWWW will highlight the three words in front of the cursor. VJJ will highlight the current row and the following two lines.
Cut and copy in Visual selection mode
Once you highlight a selection, you may want to do something:
D: Clip selected content to Clipboard.
Y: Copy selected content to Clipboard.
C: Clip selected content to clipboard and enter insert mode.
Cut and copy in non-visual selection mode
If you know exactly what you want to copy or cut, you don't need to go into visual selection mode at all. This will also save time:
D{motion}: Cuts the motion command across the characters to the Clipboard. For example, DW cuts a word and DFS cuts the characters from the current cursor to the next s to the Clipboard.
Y{motion}: Similar to above, but copy.
C{motion}: Similar to D{motion}, but finally into insert mode.
DD: Cut the current line.
YY: Copies the current line.
CC: Cut the current line and enter insert mode.
D: Cut from the cursor position to the end of the line to the Clipboard.
Y: Copies the current line.
C: Similar to D, and finally into insert mode.
X: Cut the current character to the Clipboard.
S: similar to X, but finally into insert mode.
Paste
Paste is simple, press p.
Using multiple clipboard
Many editors provide only one clipboard. Vim has a lot. The Clipboard is called a register (registers) inside VIM. You can list all the currently defined register names and their contents, and the command is ": Reg". It is best to use lowercase letters as the name of the register, because some of the capitalization is consumed by vim.
Use the registers command for double quotes ".
For example: We want to copy the current line to register K. You should press "Kyy." (You can also use V "Ky.) Why is this possible? Now the current line should already exist in register K until you copy something into register K. Now you can use the command "KP to paste the contents of the Register K to where you want it."
Avoid duplication
It's amazing. Command
Inside VI, enter. (decimal symbol), will repeat the previous command you have given. For example, your last command was ' DW ' (delete a word), vi will then delete a word.
Working with numbers
Using numbers is also one of the most powerful and time-saving features of Vim. A number can be used before a lot of Vim's commands, and this number will tell vim how many times this command needs to be executed. Like what:
3J will move the cursor down three lines.
10DD will delete 10 rows.
Y3 "will copy the content from the current cursor to the third occurrence of the quotation mark to the Clipboard.
Numbers are a very effective way to extend the scope of the motion command.
Record macros
Sometimes you will find yourself repeating the same sequence of actions in each paragraph or line of the article. Vim allows you to record a macro to fulfill your special needs.
Qregister: Record macro to register register, where register is any name of your register. QA, for example, will record and place the macro in register a.
Q: End the macro record.
@register: Use macros that exist register registers. For example, @a will use macros that exist in register a.
It's important to keep in mind that macros only record your series of keystrokes and execute them repeatedly. They are not magic. Because there are a lot of ways to accomplish this in vim, there are times when you have to carefully select commands to record your macros. Because they will be executed wherever you want to execute it.
Write code with VIM
Vim is an excellent editor for writing code because it has features that are specifically designed for programmers. Here are some of the common:
]p: Similar to the function of P, but it automatically adjusts the pasted text to fit the current code position. Try it.
%: Matching curly braces, square brackets, brackets, etc. At the top of a bracket, and then by%, the mouse will appear in the other half of the matching brackets.
>>: Indent All selected code