Full text collection of vimrc file configuration (most complete in history, with Chinese explanation)

I. differences between vi and vim
VI is similar to the notepad of windows, which is more suitable for editing ordinary text, but it is not suitable for writing script code, lack of highlight code, automatic indentation and other important functions; while vim is similar to the Advanced Editor under windows, in order to improve the development efficiency, vim needs to be used instead of vi.
Therefore, first make the following adjustments so that only vim can be used as a functional tool for developing scripts:

[root@dabiaoge ~]# echo 'alias vi=vim' >> /etc/profile
[root@dabiaoge ~]# tail -1 /etc/profile
alias vi=vim
[root@dabiaoge ~]# source /etc/profile
After the above adjustment, the vi When the command is given, the vim Replace.

II. Configuration files and important parameters of vim
Global path / etc/vimrc
User's personal path: $HOME/.vimrc
Suggestion: put it under the user's personal path $HOME/.vimrc.
Configuration of. vimrc file (almost all)

"vim config file
"date 2018-12-26
"Created by bert 
"""=>Global configuration<="""
"Close vi Compatibility mode"
set nocompatible

"Set history steps"
set history=1000

"Open related plug-ins"
"filetype on "
filetype on
"Load file type plug in"
filetype plugin on
"Load related indented files for a specific file type"
filetype indent on

"Automatically update a file when it is modified externally"
set autoread

"Activate mouse use"
set mouse=a
set selection=exclusive
set selectmode=mouse,key

"Save global variables"
set viminfo+=!

"Do not break words with the following symbols"
set iskeyword+=_,$,@,%,#,-

"through the use of: commands Command, tell us which line of the file has been changed"
set report=0

"Display blank space between divided windows for easy reading"
set fillchars=vert:\ ,stl:\ ,stlnc:\

"""=>Font and color<="""
"Automatically turn on syntax highlighting"
syntax enable

"Set font"
"set guifont=dejaVu\ Sans\ MONO\ 10
set guifont=Courier_New:h10:cANSI

"Set color"
"colorscheme desert

"Highlight the current row"
set cursorline
hi cursorline guibg=#00ff00
hi CursorColumn guibg=#00ff00

"Highlight normal txt Documentation (required txt.vim Script)"
au BufRead,BufNewFile *  setfiletype txt

"""=>Code folding function<="""
"Activate fold function"
set foldenable
"set nofen(This is to turn off the folding function.)"

"Set to collapse in syntax (shorthand set fdm=XX)"
"There are six ways to fold:
"manual   Manually define folding"
"indent   More indents indicate a higher level of folding"
"expr     Using expressions to define folds"
"syntax   Using syntax highlighting to define folding"
"diff     Collapse text without changes"
"marker   Fold the logo in the text"
set foldmethod=manual
"set fdl=0(Do not use any folding method)"

"Set the width of the folded area"
"If not 0, a collapse ID column is displayed on the left side of the screen
"Respectively, "-"And "+"To represent open and closed folds
set foldcolumn=0

"Set the number of folded layers to 3"
setlocal foldlevel=3

"Set to auto close fold"
set foldclose=all

"Use the space bar instead zo and zc Fast key to realize switch folding"
"zo O-pen a fold (Open fold)
"zc C-lose a fold (Close folding)
"zf F-old creation (Create folds)
"nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

"""=>word processing<="""
"Replace with spaces Tab"
set expandtab

"Set all Tab And indent to 4 spaces"
set tabstop=4

"Set up<<and>>Command move width is 4"
set shiftwidth=4

"Make it possible to delete four spaces at a time when pressing backspace"
set softtabstop=4
set smarttab

"Indent, auto indent (inherit indent from previous line)"
"set autoindent Command to turn on auto indent, which is the abbreviation of the following configuration
"May use autoindent Short for command, i.e“:set ai"And ":set noai"
"You can also use“:set ai sw=4"Turn indent on in a command and set the indent level
set ai
set cindent

"smart indent"
set si

"Wrap "
set wrap

"Set soft width"
set sw=4

"Inline substitution"
set gdefault

"""=>Vim Interface<="""
"Command line autocomplete in enhanced mode"
set wildmenu

"Display scale"
set ruler

"Set the height of the command line"
set cmdheight=1

"Display row number"
set nu

"Do not use graphic buttons"
set go=

"Do not redraw , when running macros.. lazyredraw"
set lz

"Backspace key( backspace)Normal processing indent, eol, start etc."
set backspace=eol,start,indent

"Allow space and cursor keys to cross line boundaries"
set whichwrap+=<,>,h,l

"Set magic"
set magic

"Turn off the sound prompt when an error is encountered"
"Turn off error message ring"
set noerrorbells

"Turn off use of visual ring instead of call"
set novisualbell

"Highlight matching brackets([{and}])"
set showmatch

"Time (in tenths of a second) to match bracket highlighting"
set mat=2

"Cursor moves to buffer 3 lines at the top and bottom of"
set scrolloff=3

"Search character by character highlight"
set hlsearch
set incsearch

"Case insensitive search"
"You can also use shorthand(“:set ic"And ":set noic")"
set ignorecase

"Highlight the current line in light color"
autocmd InsertLeave * se nocul
autocmd InsertEnter * se cul

"The input command is displayed clearly"
set showcmd

"""=>Encoding settings<="""
"Set encoding"
set encoding=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936

"Set file encoding"
set fileencodings=utf-8

"Set terminal code"
set termencoding=utf-8

"Set language encoding"
set langmenu=zh_CN.UTF-8
set helplang=cn

"""=>Other settings<="""
"Use smart auto indent when opening new lines"
set smartindent
set cin
set showmatch

"When processing unsaved or read-only files, pop-up confirmation"
set confirm

"hide the toolbar"
set guioptions-=T

"Hide menu bar"
set guioptions-=m

"Terminal code of setting error ring tone"
set vb t_vb=

"Display status bar (the default is 1, which means the status bar cannot be displayed)"
set laststatus=2

"What the status line shows"
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}

"The solution to paste without line break"
set pastetoggle=<F9>

"Set background color"
set background=dark

"Automatic detection of file type and intelligent completion of code"
set completeopt=longest,preview,menu

"Shared clipboard"
set clipboard+=unnamed

"Never backup"
set nobackup
set noswapfile

"Automatic preservation"
set autowrite

"Show help in Chinese"
if version >= 603
        set helplang=cn
            set encoding=utf-8

"Set highlighted dependencies"
highlight Search ctermbg=black ctermfg=white guifg=white guibg=black

"""=>stay shell Add interpreter, author and other copyright information automatically at the beginning of the script<="""
"Newly build.py,.cc,.sh,.javp Files, automatically inserting file headers"
autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()"
"Defined function SetTitleļ¼ŒAuto insert header"
func SetTitle()
    if expand ("%:e") == 'sh'
        call setline(1, "#!/bin/bash")
        call setline(2, "#Author:bert")
        call setline(3, "#Blog:http://blog.51cto.com/zpf666")
        call setline(4, "#Time:".strftime("%F %T"))
        call setline(5, "#Name:".expand("%"))
        call setline(6, "#Version:V1.0")
        call setline(7, "#Description:This is a production script.")

Four, explain
Readers and friends can copy and paste directly for use, just modify the copyright information at the beginning and end of the code
V. conclusion
I'm a big cousin. I bring salt for myself, and I will update it from time to time. Please support the genuine. It's shameful to steal the chain
My blog is: http://blog.51cto.com/zpf666
If you don't understand and think there are any mistakes, please leave a message below, thank you!

Tags: Linux vim encoding Windows shell

Posted on Wed, 04 Dec 2019 05:58:54 -0500 by sspatel82