21

I don't know why, but this topic seems to be badly documented and is covered with controversies as nobody knows the real answer (except for maybe Mr. Moolenaar, who rarely answers anyway).

So basically I've raised a discussion here, and it went dead pretty quickly, probably because there are not too many people using Vim in terminal mode on Windows.

My encoding settings look as follows:

if has('multi_byte')
  if empty(&termencoding)
    let &termencoding = &encoding
  endif
  let &encoding     = 'utf-8'
  let &fileencoding = 'utf-8'
endif

Of course, I have no problems running under GVim: can type any characters, and my patched Consolas for Powerline works just fine. The problems start when I try to run Vim in terminal mode. I use ConEmu, a feature-rich terminal emulator for Windows. It claims to officially support Unicode out of the box. For example, I can run the following test script:

chcp 65001 & (cmd /c type "%~dpn0.cmd") & pause & goto :EOF

English:     texts, web pages and documents
Graves,etc:  à á â ã ä å æ ç è é ê ë ì í î ï
Greek:       ΐ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο
Arabic:      ڠ ڡ ڢ ڣ ڤ ڥ ڦ ڧ ڨ ک ڪ ګ ڬ ڭ ڮ گ
Full width:  @ A B C D E F G H I J K L M N O
Romanian:    texte, pagini Web şi a documentelor
Vietnamese:  văn bản, các trang web và các tài liệu
Russian:     тексты, веб-страницы и документы
Japanese:    テキスト、Webページや文書
Yiddish:     טעקסץ, וועב זייַטלעך און דאָקומענטן
Hindi:       पाठ, वेब पृष्ठों और दस्तावेज
Thai:        ข้อความ หน้า เว็บ และ เอกสาร
Korean:      텍스트, 웹 페이지 및 문서
Chinese:     文本,網頁和文件

and I can see all the symbols correctly in ConEmu. Yes, the test script turns on the 65001 codepage. I've already discovered that Vim cannot work with the 65001 codepage at all, so this seems not to be an option anyway. The default codepage in the terminal is 437, and I can also type something like Russian in ConEmu with this default codepage, and it is displayed correctly.

Reading through :h termencoding, I see that Windows uses Unicode by default to pass symbols. Then, I don't understand why when I type anything non-ANSI in terminal Vim, I see ? symbols? Airline does not display fancy symbols from patched Consolas as well. How to configure true Unicode for terminal Vim on Windows? By the way, &termencoding reports 437 as well.

Could somebody, once and for all, please, explain to me is Unicode support for terminal Vim on Windows there (and how to configure it) or not?

5
  • 1
    I think probably another reason your thread went dead so quick is you're asking the small subset of (the small subset of (the small subset of Windows users who use Vim) who use Vim in a terminal) who use ConEmu instead of the built-in Windows cmd.exe terminal.
    – Ben
    Nov 18, 2013 at 0:02
  • 1
    @Ben: Actually, I've never restricted topic to ConEmu. There is no "ConEmu" in the title, there is only "Windows". I've added information about the terminal because this is particularly relevant, as this is the first question anyone would ask you, if you don't specify it explicitly. And trust me, if someone knows how to make it work at least in Command Prompt (aka cmd.exe), then it's like a piece of cake to make it work in ConEmu. Nov 18, 2013 at 1:50
  • 1
    I will just chime in my difficulties and investigations so far. Consolas does not by have the necessary glyphs to display some of the characters. The reason it can do so is due to font linking/fallback (msdn.microsoft.com/en-us/goglobal/bb688134.aspx). For me it fails to display unicode characters on some windows and not for others and I am still trying to determine what makes the difference. There are many oddities in the way terminal settings are read. For example, it can either get its settings from the shortcut or the registry.
    – RJ-
    Jan 15, 2014 at 1:17
  • Shortcut normally gets priority. Modification of the shortcut adds a registry entry but if the registry entry is deleted, the settings are read from the shortcut.
    – RJ-
    Jan 15, 2014 at 1:18
  • @RJ-, I sometimes it also depends on the program, for example since .NET 4.5 the Console.WriteLine can be used with UTF-16, then on a cmd.exe started with /U it will support Unicode Output
    – Sebastian
    Feb 1, 2014 at 22:41

2 Answers 2

22

I've wondered about this myself too and in the past tried ConEmu and gave up after struggling to get console vim with 256 colors and fancy fonts working on it.

So today I tried out for sometime again and surprise, surprise - things seem to be working. Given all the extreme sensitiveness to versions, I'm going to try and list down versions of everything

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug  1 2014 09:38:34)
MS-Windows 32-bit console version
Included patches: 1-389
Compiled by raghuramanr@ADITI

ConEmu

140723 Alpha

Windows: Win 7x64

ConEmu settings in .vimrc:

" ConEmu
if !empty($CONEMUBUILD)
    echom "Running in conemu"
    set termencoding=utf8
    set term=xterm
    set t_Co=256
    let &t_AB="\e[48;5;%dm"
    let &t_AF="\e[38;5;%dm"
    " termcap codes for cursor shape changes on entry and exit to
    " /from insert mode
    " doesn't work
    "let &t_ti="\e[1 q"
    "let &t_SI="\e[5 q"
    "let &t_EI="\e[1 q"
    "let &t_te="\e[0 q"
endif

Steps:

chcp 65001
vim.exe

I still can't get a blinking cursor in vim which is confusing. Still better than before when stuff would be messed up.

3
  • 4
    This works! Also, comment the echom line, and you get your blinking cursor.
    – Adam L. S.
    Dec 16, 2014 at 12:11
  • Oh, and don't forget to set the encoding settings as well, that also important for this to work.
    – Adam L. S.
    Dec 16, 2014 at 12:18
  • This comment is probably one of the most important pieces of information regarding this issue, I have been trying to get vim to display colors correctly for the past week and a half. Thank you.
    – guychouk
    Oct 26, 2016 at 21:22
1

There was recently a patch for "Windows 8 IME in console Vim". It was cleaned up by mattn and posted here: https://gist.github.com/mattn/8312677

It was included with 7.4.142. Does that version fix your issue?

2
  • 1
    From now on, I can type chcp 1251 to change to cyrillic codepage and then start terminal Vim. As a result, now I can see Russian symbols as I type them, i.e. no more question marks (?) instead. Nevertheless, it is still not possible to see such fancy symbols as ones coming from Powerline. The problem is likely that codepage 1251 simply does not include them. If so, then the only way to truly support Unicode with terminal Vim is to support the 65001 codepage, the true UTF-8 codepage. Mar 11, 2014 at 15:07
  • @Haroogan If you have any advice on how Vim could better handle things, you may want to create a ticket on the neovim project: github.com/neovim/neovim Mar 12, 2014 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.