Vim and ASCII extended characters?

陌路散爱 提交于 2020-01-14 15:26:52

问题


I would like to know how can I set VIM 7.0 to show and work with ASCII extended characters without problem.


回答1:


Vim (which is what vi resolves to on most systems) readily supports extended character sets. You might need to tell Vim which encoding to use, though.

This is controlled by two options:

:set encoding
:set fileencoding

If you have loaded a file that displays incorrectly, you may use :set encoding=<new encoding> to force the appropriate encoding. This changes the interpretation of the characters on the fly. If you want to save the file in another encoding preserving the current interpretation of characters, use set fileencoding=<new encoding> to let Vim save the file in that encoding.

I recommend that you set utf-8 as the default encoding in your .vimrc.




回答2:


Once the the characters are "extended" it's not ASCII any more.

However: Just use vim. ":help unicode" for more details.




回答3:


The other solutions here didn't work for me. Vim told me that encoding and fileencoding were not supported options. That turned out to be because I was building from source myself, and I did not include the multi-byte feature. My two Macs are similar, but one of them enabled it by default while the other did not.

If you're building Vim from source like I was, include --enable-multibyte in your arguments to ./configure. In my case, Vim defaulted to UTF-8 and supported extended characters after that.




回答4:


I would suggest you to try the following:

  • set the terminal to utf-8 (how to do that depends on your terminal; in PuTTY it's in the Window/Translation menu)

  • set your locale to utf-8 (how to do that depends on your OS; on my Debian box it's set LC_ALL=en_GB.UTF-8 for the current session and sudo dpkg-reconfigure locales for permanent system-wide changes) -- you can check your current locale with locale.

That's how it works for me (using VIM 7.1.314 and no .vimrc).



来源:https://stackoverflow.com/questions/1921316/vim-and-ascii-extended-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!