Home  >  Article  >  Backend Development  >  VIM7.3 settings (for Windows)

VIM7.3 settings (for Windows)

WBOY
WBOYOriginal
2016-08-08 09:31:59907browse

Solution to GVIM garbled code problem

Vim has four options related to character encoding methods, namely: encoding, fileencoding, fileencodings, termencoding (for possible values ​​of these options, please refer to Vim online help: help encoding-names), they Their respective meanings:
* encoding: The character encoding used internally by Vim, including Vim's buffer, menu text, message text, etc. The user manual recommends changing its value only in .vimrc, and in fact it seems that it only makes sense to change its value in .vimrc.
* fileencoding: The character encoding of the file currently edited in Vim. When Vim saves the file, it will also save the file in this character encoding (regardless of whether it is a new file or not).
* fileencodings: When Vim starts, it will detect the character encoding of the file to be opened one by one according to the character encoding it lists, and set fileencoding to the final detected character encoding. Therefore it is best to put the Unicode encoding at the top of the list and the Latin encoding latin1 at the end.
* termencoding: The character encoding method of the terminal (or Console window in Windows) where Vim works. This option is not valid for our commonly used GUI mode gVim under Windows, but for Console mode Vim it is the code page of the Windows console, and usually we do not need to change it.
Since Unicode can contain characters from almost all languages, and Unicode’s UTF-8 encoding is a very cost-effective encoding, the encoding value is set to utf-8. At the same time, when the encoding is set to utf-8, Vim will automatically detect the encoding method of the file more accurately. For files edited in Chinese Windows, in order to take into account compatibility with other software, it is more appropriate to set the file encoding to GB2312/GBK, so it is recommended that the fileencoding be set to chinese (chinese is an alias, which means gb2312 in Unix and cp936 in Windows) , which is the code page of GBK).
                                                                                                                                     The final solution to the problem of garbled characters displayed in files, garbled menus, garbled right-click menus, and garbled Conlse output, is to modify the configuration file _vimrc corresponding to the Vim editor and add the following configuration:

"Close the upper toolbar
set go -=T
"Turn off the right scroll bar
"set go-=r

"Always show labels. 0: Not displayed; 1: Displayed when there is more than 1
set showtabline=2

"Turn on line number
set number
" Turn on automatic indentation, version 7.3 or above has been turned on automatically
"set autoindent
"The indent width is 4 characters
set shiftwidth=4
"The tab width is 4 characters
set tabstop =4
"Replace all tabs with spaces when editing
set et
"Click Backspace once to delete 4 spaces
set smarttab
"Color scheme
colo desert
"Turn on syntax highlighting, version 7.3 has been turned on automatically
"syntax on
"Font setting
set guifont=courier_new:h10
"Turn off compatibility mode
set nocompatible
"The following three lines simulate Windows operations, such as Ctrl-C copy
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
"Do not generate a backup file. The following sentence must be written under behave mswin, otherwise a backup will still be generated. I don’t know why~
set nobackup
"GVIM internal encoding
set encoding=utf-8
"The currently edited file Encoding
set fileencoding=utf-8
"GVIM supports open file encoding
set fileencodings=utf-8,gbk,gb2312,big5,latin1
"Solve menu and right-click menu garbled code
source $VIMRUNTIME/delmenu.vim
source $ VIMRUNTIME/menu.vim
"Solve garbled output from console
language messages zh_CN.utf-8
"Set the Linux terminal to GVIM internal encoding. You don't need to set it under Windows
let &termencoding=&encoding
"To prevent special symbols from being displayed normally, such as five-pointed stars Wait
set ambiwidth=double
set diffexpr=MyDiff()
function MyDiff()
let opt ​​= '-a --binary '
if &diffopt =~ 'icase' | let opt ​​= opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt ​​= opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ ' let cmd = '""' . $VIMRUNTIME . 'diff"'
let eq = 'S else
let cmd = substitute ($ vimruntime,' ',' "',' ').' Diff" '
Else
Let CMD = $ vimruntime. ecute '! ' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > 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

The above introduces the VIM7.3 settings (for Windows), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:silent_songsNext article:silent_songs