[英]How to view UTF-8 Characters in Vim or gVim
I work on webpages involving non-English scripts from time to time, most of them are encoded using UTF-8.我不时在涉及非英语脚本的网页上工作,其中大多数是使用 UTF-8 编码的。
Vim and gVim do not display those UTF-8 characters correctly. Vim 和 gVim 不能正确显示那些 UTF-8 字符。
I'm using Vim 7.3.46 on Windows 7, 64-bit, with set guifont=Monaco:h10
in _vimrc.我在 64 位 Windows 7 上使用 Vim 7.3.46,在 _vimrc 中
set guifont=Monaco:h10
。
Is there a way to fix this?有没有办法来解决这个问题?
Update: I've googled around and found set guifontwide
acts as second fallback for regional languages.更新:我搜索了一下,发现
set guifontwide
作为区域语言的第二个后备。
I added the following lines to _vimrc and most of my problems got solved.我在 _vimrc 中添加了以下几行,我的大部分问题都得到了解决。
set enc=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf8,prc
set guifont=Monaco:h11
set guifontwide=NSimsun:h12
The above NSimsun font works for Chinese, The problem is, I don't know how they got the font name to work with Vim, Courier New
is mentioned as Courier_New
also NSimsun
is nowhere in the font directory.上面的 NSimsun 字体适用于中文,问题是,我不知道他们是如何让字体名称与 Vim 一起使用的,
Courier New
被称为Courier_New
并且NSimsun
在字体目录中也不存在。 The font I want to use is Latha
But, I don't know how to use it in the _vimrc file.我要使用的字体是
Latha
但是,我不知道如何在 _vimrc 文件中使用它。 set guifontwide=latha:h12
or set guifontwide=Latha:h12
doesn't work. set guifontwide=latha:h12
或set guifontwide=Latha:h12
不起作用。
If I successfully set the guifontwide
to latha
, then my problem will be solved.如果我成功地将
guifontwide
设置为latha
,那么我的问题将得到解决。 How to do it?怎么做?
Did you try你试过了吗
:set encoding=utf-8
:set fileencoding=utf-8
? ?
Try to reload the document using:尝试使用以下方法重新加载文档:
:e! ++enc=utf8
If that works you should maybe change the fileencodings
settings in your .vimrc.如果这样可行,您可能应该更改 .vimrc 中的
fileencodings
设置。
If Japanese people come here, please add the following lines to your ~/.vimrc
如果日本人来这里,请在你的
~/.vimrc
中添加以下行
set encoding=utf-8
set fileencodings=iso-2022-jp,euc-jp,sjis,utf-8
set fileformats=unix,dos,mac
On Microsoft Windows, gvim wouldn't allow you to select non-monospaced fonts.在 Microsoft Windows 上,gvim 不允许您选择非等宽字体。 Unfortunately Latha is a non-monospaced font.
不幸的是,Latha 是一种非等宽字体。
There is a hack way to make it happen: Using FontForge (you can download Windows binary from http://www.geocities.jp/meir000/fontforge/ ) to edit the Latha.ttf and mark it as a monospaced font.有一种破解方法可以实现:使用FontForge (您可以从http://www.geocities.jp/meir000/fontforge/下载 Windows 二进制文件)编辑 Latha.ttf 并将其标记为等宽字体。 Doing like this:
这样做:
Good luck!祝你好运!
这对我有用,不需要更改任何配置文件
vim --cmd "set encoding=utf8" --cmd "set fileencoding=utf8" fileToOpen
In Linux, Open the VIM configuration file在 Linux 中,打开 VIM 配置文件
$ sudo -H gedit /etc/vim/vimrc
Added following lines:添加了以下几行:
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
Save and exit, and terminal command:保存退出,终端命令:
$ source /etc/vim/vimrc
At this time VIM will correctly display Chinese.这时候vim就会正确显示中文了。
Is this problem solved meanwhile?这个问题同时解决了吗?
I had the problem that gvim didn't display all unicode characters (but only a subset, including the umlauts and accented characters), while :set guifont?
我遇到的问题是 gvim 没有显示所有unicode 字符(但只有一个子集,包括变音符号和重音字符),而
:set guifont?
was empty;是空的; see my question .
看我的问题。 After reading here, setting the
guifont
to a sensible value fixed it for me.阅读此处后,将
guifont
设置为合理的值为我修复了它。 However, I don't need characters beyond 2 bytes.但是,我不需要超过 2 个字节的字符。
I couldn't get any other fonts I installed to show up in my Windows GVim editor, so I just switched to Lucida Console
which has at least somewhat better UTF-8 support.我无法让我安装的任何其他字体显示在我的 Windows GVim 编辑器中,所以我只是切换到
Lucida Console
,它至少支持更好的 UTF-8。 Add this to the end of your _vimrc
:将此添加到
_vimrc
的末尾:
" For making everything utf-8
set enc=utf-8
set guifont=Lucida_Console:h9:cANSI
set guifontwide=Lucida_Console:h12
Now I see at least some UTF-8 characters.现在我至少看到了一些 UTF-8 字符。
在 Windows gvim 上,只需选择“Lucida Console”字体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.