gvim不识别.vim插件编码

  • 问题:前几天在win10下装了gvim,今天装了几个插件,NERDTree,minibufexpl,winmanager。运行时报错:NERDTree的69,70行错误,显示乱码。

  • 解决:百度了一下 把这段代码粘到了_vimrc里面就好了。

代码转载自雪候鸟的专栏_Gvim中文菜单乱码解决方案
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"vim7.1在windows下的编码设置。
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has("win32")
 set fileencoding=chinese
else
 set fileencoding=utf-8
endif
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"解决consle输出乱码
language messages zh_CN.utf-8
  • gvim中的encoding
    由于编码内容涉及gui/terminal,locale/gvim,read/write,以及unicode还是multi_byte等等各种问题,弄清楚的话可能要花费一些时间。这里简单记录一下。
    首先,gvim有两种界面:GUI图形化界面和console界面。
    其次,智能的编辑器应当具有猜测文件编码格式的功能,从而使用正确的编码读取并显示文件内容。gvim正是这样一种智能的编辑器。gvim配置里面有个参数fileencodings,它是一个编码集合。当打开一个文件时,gvim会遍历fileencodings中的编码,尝试对该文件解码,直到解码成功或者遍历完毕。
    然后,gvim定义了下面这样几个参数

    • encoding

      Sets the character encoding used inside Vim. It applies to text in
      the buffers, registers, Strings in expressions, text stored in the
      viminfo file, etc. It sets the kind of characters which Vim can work
      with.
      ……
      The character encoding of files can be different from ‘encoding’.
      This is specified with ‘fileencoding’.
      ……
      Normally ‘encoding’ will be equal to your current locale. This will be the default if Vim recognizes your environment settings.

      文档里写了一通,还是有点乱。大概是说xxx。vim中大部分使用的应该是encoding,貌似是gvim的系统编码,怎么个系统法….不清楚。
      encoding应当与本地系统(操作系统)编码一致。vim会识别出本地系统编码并将encoding设置为相同的值。比如,中文windows操作系统的本地编码为cp936(GBK),那么gvim中的encoding=gbk。

    • fileencodings

      This is a list of character encodings considered when starting to edit an existing file.
      When a file is read, Vim tries to use the first mentioned character encoding. If an error is detected, the next one in the list is tried. When an encoding is found that works, ‘fileencoding’ is set to it. If all fail, ‘fileencoding’ is set to an empty string, which means the value of ‘encoding’ is used.
      ……
      When the “++enc” argument is used then the value of ‘fileencodings’ is not used

      正如前面所言,fileencodings是一个编码集合。打开一个文件时,gvim用集合中的编码尝试对该文件解码。一旦解码成功,便将fielencoding设置为尝试成功的编码。若全部失败,则将fileencoding设置为空,且使用encoding解码。
      如果使用了”++enc”参数,或者fileencodings为空,则使用fileencoding。

    • fileencoding

      Sets the character encoding for the file of this buffer.
      When ‘fileencoding’ is different from ‘encoding’, conversion will be done when writing the file. For reading see below.
      When ‘fileencoding’ is empty, the same value as ‘encoding’ will be used (no conversion when reading or writing a file).
      ……
      When reading a file ‘fileencoding’ will be set from ‘fileencodings’.
      To read a file in a certain encoding it won’t work by setting
      ‘fileencoding’, use the |++enc| argument. One exception: when
      ‘fileencodings’ is empty the value of ‘fileencoding’ is used.
      For a new file the global value of ‘fileencoding’ is used.

      • 写文件时:若fileencoding与encoding不一致,会进行转换; 否则,不用转换;
      • 读文件时:如前面所述。

    • termencoding

      Encoding used for the terminal.
      This specifies what character encoding the keyboard produces and the display will understand. For the GUI it only applies to the keyboard ( ‘encoding’ is used for the display).
      In the Win32 console version the default value is the console codepage when it differs from the ANSI codepage.
      Note: This does not apply to the GTK+ 2 GUI. After the GUI has been successfully initialized, ‘termencoding’ is forcibly set to “utf-8”. Any attempts to set a different value will be rejected, and an error message is shown.
      For the Win32 GUI ‘termencoding’ is not used for typed characters, because the Win32 system always passes Unicode characters.
      When empty, the same encoding is used as for the ‘encoding’ option.This is the normal value.

      根据keyboard produces and the display will understand,姑且分成两部分:input/produce和output/understand。

      • input/produce:就是说对于键盘输入的字符,gvim会使用termencoding编码
      • output/understand:gvim如何将键盘输入的字符display到屏幕上。
        gvim有两个界面:GUI和console,分别对应gvim命令和vim命令。
        执行gvim命令,会弹出gvim的GUI图形界面;而执行vim命令时,则会像linux下面一样,console控制台将转入编辑界面。在console界面,termencoding默认设置为本地系统编码。而在GUI界面,一旦启动之后便会忽视这一参数。

    说了这么多,好像然并卵。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值