Vim Basic Configuration

Vim is a powerful editor, which can even rival IDE with the help of various plug-ins, but it can not rely too much on various plug-ins and forget the original functions and operations of Vim. Vim itself is very powerful, learning curve is very tortuous, we need to learn slowly, more use. Vim itself has many configuration options, which can be configured in ~/.vimrc to facilitate our operation. Vim has also been used for some time, but also has a set of their own habits. To configure Below is my basic configuration.

General

Some basic configurations

syntax on "keyword coloring"
syntax enable "syntax highlighting"
Setnu "Display line number
 set nocp "incompatible vi"
set hidden "Allows switching buffer not to be saved"
set splitright "The new splitting window is on the right
 set splitbelow "New splitting window is below
 set autoread "The file has been modified outside Vim and readed automatically
 set timeoutlen=350 "wait time, such as input after the < leader > key"
set helpheight=999 "View Help Document Full Screen
 Setscrolljump = 3 "Number of rows sliding when the cursor leaves the screen
 set scrolloff=1 "Keep the minimum number of rows above and below the cursor
 Set show match "short echo matching parentheses"
set hlsearch                    " Highlighting Matches in Retrieval
set incsearch                   " Search while input
set ignorecase                  " Search ignores case
set smartcase                   " Intelligent case search

set wildmenu                    " Completions in command mode are displayed as menus
set wildmode=list:longest,full  " Command mode completion mode
set foldenable                  " Start folding
set foldmethod=marker           " Set folding mode
set encoding=utf-8              " Encoding to make Chinese normal display
set termencoding=utf-8
set fileencodings=utf-8,gb2312,gbk,gb18030

There are also related coding issues for reference. VIM File Code Recognition and Random Code Processing.

Formatting

On indentation

Set expandtab "tab = Space
 Settabstop = 4 "tab indents 4 spaces
 Setshift width = 4 "Auto indentation space number
 Set soft tabstop = 4 "backspace deletion indentation
 Setbackspace = indent, start "Backspace can delete indentation and original characters
 set autoindent "indented at the same level as the previous row

When the cutting window displays multiple files, if the window size changes, the original evenly distributed window will not be resized and become ugly. You can add the following to configure the automatic resizing.

au VimResized * exe "normal! \<c-w>="

When pasting, if the front line has annotation symbols, such as #, //, etc., the back line will automatically add annotation symbols, which is very troublesome. The following can be configured not to automatically add annotations.

au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "no rm $"|endif|endif
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o

Key (re)Mappings

Some key remapping, many used is really addictive, and a lot of convenience, such as < Esc > replaced by jj, and some often wrong command correction, such as Q, W and so on.

let mapleader=","           " mapping<leader>Keyboard to ___________,
nmap j gj
nmap k gk
inoremap jj <ESC>
nnoremap <silent> J :bp<CR>
nnoremap <silent> K :bn<CR>
noremap <silent><space> :set hls! hls?<CR>
noremap <silent><Leader>s :set rnu! rnu?<CR>
noremap <silent><Leader>l :set list! list?<CR>
nnoremap <Leader>c @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

" More convenient to move between windows
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" Command mode key mapping
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>

" Tab operation
nnoremap <Leader>tc :tabc<CR>
nnoremap <Leader>tn :tabn<CR>
nnoremap <Leader>tp :tabp<CR>
nnoremap <Leader>te :tabe<Space>

" Correcting Error-prone Commands
command -bang -nargs=* Q q<bang>
command -bang -nargs=* Wa wa<bang>
command -bang -nargs=* WA wa<bang>
command -bang -nargs=* -complete=file W w<bang> <args>
command -bang -nargs=* -complete=file Wq wq<bang> <args>
command -bang -nargs=* -complete=file WQ wq<bang> <args>

Vim UI

Because I mainly use Vim on terminals, some UI configurations are for terminals. GUI words are basically similar, just replace ctermbg and others with guibg and so on.

set t_Co=256                    " Terminal display 256 colours
set tabpagemax=15               " Up to 15 Tab
set showmode                    " Display the current mode
set cursorline                  " Highlight the current line
set list                        " Display special symbols
set listchars=tab:›\ ,trail:•,extends:#,nbsp:.

hi clear SignColumn             " Markup Column Background and Topic Background Matching
hi clear LineNr                 " Current row and column background matching with topic background matching

hi CursorLineNr ctermfg=red
hi VertSplit ctermbg=Grey ctermfg=Grey cterm=none
hi Visual ctermbg=81 ctermfg=black cterm=none
hi Comment ctermfg=blue
hi Statement ctermfg=cyan
hi DiffAdd ctermbg=blue ctermfg=white
hi DiffDelete ctermbg=green ctermfg=none
hi DiffChange ctermbg=red ctermfg=White
hi DiffText ctermbg=yellow ctermfg=black

if has('cmdline_info')
    set showcmd                 " Show the current operation in the lower right corner
    set ruler                   " Display status description in lower right corner
    set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " Format
endif

if has('statusline')
    set laststatus=1
    set statusline=%<%f\                     " Filename
    set statusline+=%w%h%m%r                 " Options
    set statusline+=\ [%{&ff}/%Y]            " Filetype
    set statusline+=\ [%{getcwd()}]          " Current dir
    set statusline+=%=%-14.(%l,%c%V%)\ %p%%  " Right aligned file nav info
endif

Keywords: vim encoding Windows

Added by AshtrayWaterloo on Fri, 21 Jun 2019 00:44:56 +0300