Common configurations of Vim editor
- Configuration file directory (where to configure the file)
- Related configuration:
-
- remove borders
- Set color matching
- Set background color
- Set syntax highlighting
- Set line number
- Set underline
- Set indent
- Set cancel formatting when pasting
- Set up the mouse
- Set status line
- Set to display the line number and column number where the cursor is located in the lower right corner
- Settings shows that the complete command has not been entered.
- Set the matching list to be displayed in the status bar when using the Tab key to complete.
- Set backspace
- Set to use space bar instead of tab character
- Set the tab character to occupy 4 spaces
- Set the default indent size of 4 spaces
- About search
- Solve Chinese garbled characters
- Configure detection file types
- Set up different commands to be executed based on different file types
- Set to cancel search highlighting and turn off vim error bell
- Set ESC key
- Summarize
Configuration file directory (where to configure the file)
There are two methods:
- You can directly enter the : + command in the vim editing interface to set, for example:
Set the display/cancel line number
:set nu
:set nonu
- You can edit the user configuration file (.vimrc) to achieve permanent customization of Vim
Generally use the ~/.vimrc file under Linux
You can try to find it through the following code:
cd /usr/share/vim
sudo vi vimrc
Under windows, it is usually the _vimrc file in the user folder or the _vimrc file in the vim installation directory.
Related configuration:
remove borders
"The legendary removal of borders uses the following sentence
set go=
Set color matching
"Set the color scheme. Desert is selected here. There are other options. Enter: color in vim and press the tab key to view it.
color desert
Set background color
"Set the background color. There are two schemes for each color scheme, one light and one dark.
set background=light
Set syntax highlighting
"Turn on syntax highlighting
syntax on
Set line number
"Show line number
set number
Set underline
"Underline the entire line at the cursor position
This setting can save your eyesight in complex code
set cursorline
Set indent
"There are three values for setting indent: cindent (c style), smartindent (smart mode, I don’t think it is smart), and autoindent (simple and consistent with the previous line)
set cindent
Set cancel formatting when pasting
This function is usually used to prevent too many tabs when pasting using the vim editor. It is generally executed using the : + command.
set paste //取消格式
set nopaste //打开格式
Set up the mouse
The mouse is not enabled by default in the Vim editor. You can enable the mouse through this setting.
set mouse=a
set selection=exclusive
set selectmode=mouse,key
Set status line
" 1=Start displaying the status line, 2=Always display the status line.
" Set to always display the status line so that you can easily see the current file name.
set laststatus=2
" Set the content displayed on the status line. %F: Display the full path of the current file.
- " %r: If readonly, [RO] will be displayed
- " %B: Displays the encoding value of the character under the cursor, in hexadecimal.
- " %l: The line number where the cursor is located. %v: The virtual column number where the cursor is located.
- " %P: Displays the percentage of the current content in the entire file.
- " %H and %M are parameters of the strftime() function to obtain the time.
set statusline=%F%r\ [HEX=%B][%l,%v,%P]\ %{
strftime(\"%H:%M\")}
Set to display the line number and column number where the cursor is located in the lower right corner
" Setting the ruler will display the line number and column number where the cursor is located in the lower right corner,
" It is inconvenient to view. Change to setting the status bar to display content
set ruler
Settings shows that the complete command has not been entered.
" Shows that the complete command has not been entered. For example, if you enter the yy command, entering the first y will display y in the lower right corner.
set showcmd
Set the matching list to be displayed in the status bar when using the Tab key to complete.
" When using the Tab key to complete, the matching list is displayed in the status bar,
" It is convenient to check which commands meet the completion conditions.
set wildmenu
Set backspace
"In the Windows version, the backspace key mode of vim is compatible with vi by default, which is not in line with our usage habits. The following article can be changed.
set backspace=indent,eol,start
Set to use space bar instead of tab character
"Replace tab character with space bar
set expandtab
Set the tab character to occupy 4 spaces
"The tab character takes up 4 spaces
set tabstop=4
Set the default indent size of 4 spaces
"The default indent size is 4 spaces
set shiftwidth=4
About search
Set up incremental search
"Incremental search
set incsearch
Set highlighting of matching brackets
" Highlight matching brackets
set showmatch
Set to highlight all searched content
(highlight search)
" Highlight all searched content. Use map mapping later
" shortcut keys to facilitate closing Highlight of current search.
set hlsearch
Set the cursor to jump immediately to the searched content
(incremental search)
" The cursor immediately jumps to the searched content
set incsearch
After setting the search to the last matching position, searching again will not return to the first matching position.
" After searching for the last matching position, searching again will not return to the first matching position.
set nowrapscan
Solve Chinese garbled characters
"Sometimes Chinese characters will display garbled characters. Use a few commands to solve the problem.
let &termencoding=&encoding
set fileencodings=utf-8,gbk
Configure detection file types
"Many plug-ins will require configuration detection file types
:filetype on
:filetype plugin on
:filetype indent on
Set up different commands to be executed based on different file types
"The following is very useful. It can execute different commands according to different file types.
"For example: if it is c/c++ type
:autocmd FileType c,cpp : set foldmethod=syntax
:autocmd FileType c,cpp :set number
:autocmd FileType c,cpp :set cindent
"For example: if it is a python type
:autocmd FileType python :set number
:autocmd FileType python : set foldmethod=syntax
:autocmd FileType python :set smartindent
Set to cancel search highlighting and turn off vim error bell
You can check out this article of mine:How to cancel the search highlighting and turn off the vim error bell in the vim editor in Linux
You can also try :
" Remove the prompt sound when input errors
set noeb
Set ESC key
" By default, after pressing Esc, you need to wait for 1 second before it takes effect.
" Set the Esc timeout to 100ms and it will take effect as soon as possible
set ttimeout
set ttimeoutlen=100
Summarize
The above are a few simple and commonly used vim configurations. Using vim to type programs requires the help of some plug-ins, such as:
- omnicppcomplete c/c++ code completion
- taglist View function list
- NERD_Tree View file list
- pydiction python code completion
For specific installation methods, please refer to google, baidu or visit http://www.vim.org. I won’t go into details here.
For those who are new to vim:
Vim is very powerful. If you want to use vim well, it is worth investing a certain amount of time to learn it. Just rely on the above configurations and plug-ins. far from enough. I recommend a textbook "vimbook" written by a foreigner. It is very detailed and does not contain much content. that’s all.