4

I often see that fonts intended to be used on Windows are defined with :cANSI.

set guifont=Consolas:h11:cANSI

The help is, of course, provide some explanation, but I don't really understand it.

cXX - character set XX. Valid charsets are: ANSI, ARABIC, BALTIC, CHINESEBIG5, DEFAULT, EASTEUROPE, GB2312, GREEK, HANGEUL, HEBREW, JOHAB, MAC, OEM, RUSSIAN, SHIFTJIS, SYMBOL, THAI, TURKISH and VIETNAMESE. Normally you would use "cDEFAULT".

Examples:

  • :set guifont=courier_new:h12:w5:b:cRUSSIAN
  • :set guifont=Andale_Mono:h7.5:w4.5

Here is my vimrc:

if has('multi_byte')
  if &encoding !~? '^u'
    if &termencoding == ''
      let &termencoding = &encoding
    endif
    set encoding=utf-8
  endif
  setglobal fileencoding=utf-8
  set fileencodings=ucs-bom,utf-8,cp1251,latin1
endif

" set guifont=Consolas:h11:cANSI
" set guifont=Consolas:h11
" set guifont=Consolas:h11:cRUSSIAN

I can use :h11:cANSI, just :h11, or :h11:cRUSSIAN, and I don't see any difference.

What is the reason to use :cANSI or :cRUSSIAN? Maybe this is something that was necessary in older versions of Vim only?

7
  • 1
    Charsets are not used with Unicode.
    – Matt
    Sep 16, 2021 at 18:11
  • @Matt Well, I expected something like this. But could you show or describe a case where their use is required? Using set guifont=Consolas:h11:cRUSSIAN with a clean vimrc, for example, doesn't provide a possibity to see Russian characters, such as д or ф.
    – user90726
    Sep 16, 2021 at 18:57
  • 1
    I think the charset is more or less vaguely explained by microsoft here: docs.microsoft.com/en-us/windows/win32/gdi/… Sep 16, 2021 at 19:08
  • 3
    @jsv Charset is only needed if &encoding is not Unicode one. For example, until very late Vim for Windows used default charset (i.e. set enc=cp1251 for Russian locale). Then cRUSSIAN charset for guifont will be required.
    – Matt
    Sep 17, 2021 at 4:25
  • @Matt I just tested set encoding=cp1251 guifont=Consolas:h11 with Vim 8.2.2824 and this works perfectly fine even without charset. (Thanks anyway.)
    – user90726
    Sep 17, 2021 at 22:43

1 Answer 1

5
+250

Historically "Charset" denoted a set of glyphs used for the codes 128-255 (i.e. 1-byte chars except those standartized by ASCII 0-127). Now with Unicode everywhere it is of little value and use.

If you need an illustrative example, here it is

  1. Running GVim 9 on Windows 11 Russian. Everything looks right for the default font.
> gvim --cmd "set enc=cp1251" --clean

GVim #1

  1. Set new font and show intro again. What's this?!
set guifont=Consolas
intro

GVim #2

  1. Force cRUSSIAN charset and it's back!
set guifont=Consolas:cRUSSIAN
intro

GVim #3

Of course, if &encoding is UTF-8 then all this stuff does just nothing.

3
  • I have recently made fonts (nerdfonts) that seem to have cANSI in the font name string, on Windows. Are there any others that are still in use?
    – paradroid
    Nov 25, 2023 at 22:02
  • @paradroid Encoding is not "a font feature" but rather "a parameter request". So I cannot make sense out of your question.
    – Matt
    Nov 26, 2023 at 4:36
  • I've made a gvim plugin which changes font size using key mappings or mousewheel. I've covered qDRAFT, b, Wxxx and cANSI in the regex to match any possible attributes in the font string, but I am not sure if there could be any others that I haven't encountered.
    – paradroid
    Nov 26, 2023 at 4:40

Your Answer

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

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