Which options in the Vim editor configuration file are necessary?
伊谢尔伦
伊谢尔伦 2017-05-16 16:43:13
0
4
847

Although Vim is very smooth to operate, for a Chinese developer, Vim's default configuration often appears garbled.
The second is the issue of indentation, how to make the code layout format seen by different system platforms have the same style.
When participating in open source projects, there are many common coding standards that are worth setting as default.

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(4)
淡淡烟草味

I usually set tabs to 4 spaces, and then use the Unix standard form of <LF> for line breaks. As for the garbled code problem, I used this code to solve it

if has("multi_byte")
    set encoding=utf-8
    " English messages only
    "language messages zh_CN.utf-8

    if has('win32')
        language english
        let &termencoding=&encoding
    endif

    set fencs=utf-8,gbk,chinese,latin1
    set formatoptions+=mM
    set nobomb " 不使用 Unicode 签名

    if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
        set ambiwidth=double
    endif
else
    echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
endif
左手右手慢动作
syntax on
set tabstop=4
set shiftwidth=4
set expandtab
set fencs=utf-8,gbk
set fileencoding=utf-8
set number
nnoremap <buffer> <F5> :w<CR>:!/usr/bin/env python % <CR>
nnoremap <F2> :set nonumber!<CR>:set foldcolumn=0<CR>
nnoremap <F3> :set noautoindent!<CR>:set nosmartindent!<CR>
set autoindent
set smartindent
set vb t_vb=
set fileencodings=utf-8,gb18030,utf-16,big5
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType python set complete+=k~/.vim/syntax/python.vim isk+=.,(
set guifont=Monaco
漂亮男人

The Chinese garbled problem can be solved by setting the current encoding method (enc) and file encoding (fenc)

set encoding=utf-8 "如果是 gbk 的时候用 cp936
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

The problem with indentation lies in everyone’s tab display settings...
The most reliable way is probably to set it to spaces instead of tabs

set expandtab
set softtabstop=4 "建议在 python 的 template 里改为2

This will slightly increase the file size. Then use shift+backspace when deleting the indent. Pressing the bs key alone can only delete one space~

大家讲道理

@yanyaoer’s encoding settings are already very applicable, just add some tabs and spaces

set tabstop=4      "ts     每个 tab 显示出 4个空格的宽度
set shiftwidth=4   "sw     每次缩进的空格数
set expandtab      "et     每个 tab 自动扩展成空格
set softtabstop=4  "sts    每次按 backspace 退格 4个空格

ts/sw/... is the abbreviation

Post another configuration, just make things better

set scrolloff=3
set showmode
set showcmd
set hidden
set wildmenu
set wildmode=list:longest
set cursorline
set ttyfast
set ruler
set backspace=indent,eol,start
set laststatus=2
set nu
"set relativenumber  "vim7.3适用
set undofile
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template