14

I want to type in different languages using (g)Vim. But when I switch to another language using language bar (Devanagari or Hindi characters), and type anything, (g)vim displays ??? ??.

What I tried:

write ++enc=utf-8 foo.txt  
set fileencoding=utf-8   
set enc=utf-8

Information:

  • GVim version: 7.4, and also its +multi_byte.
  • No changes in default vimrc file.

I have just started with (g)vim.

5
  • 5
    Might be a font thing. Which font are you using?
    – muru
    Commented Feb 17, 2016 at 16:47
  • 1
    7 fonts (consolas, 2 courier,2 lucida, fixedsys, and terminal) are listed in gvim. I tried all of them. While my system has other fonts too, but gvim displays only 7. I Also followed: stackoverflow.com/questions/3766204/vim-doesnt-support-unicode but still no luck.
    – msinfo
    Commented Feb 17, 2016 at 18:40
  • 3
    "Another language" is rather vague. What language? Polish? Hebrew? Chinese? Klingon? If you're using an obscure language it's very possible that none of those fonts support that language. Commented Mar 3, 2016 at 11:45
  • 1
    In my case, I'm trying Malayalam with GVim 7.4.800 (or thereabouts) with the Ubuntu Mono font. For sample text, see the Malayalam Wikipedia. On Linux (Ubuntu and Arch), with the terminal and GVim fonts set to Ubuntu Mono, Malayalam does show up, even if it a bit squished. I have tried the other fonts msinfo mentioned in the second comment.
    – muru
    Commented Mar 5, 2016 at 16:29
  • 1
    On Linux, gvim can display the characters you want because Pango will pull in glyphs from other fonts to be able to display all the characters. That's also why the characters look different than the rest of your text. If you try the same thing in xterm, then you won't see all the characters because a single font is used. I suspect something similar is happening on Windows.
    – jamessan
    Commented Mar 8, 2016 at 13:55

1 Answer 1

7
+50

The default encoding seems to be latin1:

:set encoding?
  encoding=latin1

When entering characters, Vim tries to convert them from the incoming character set (probably unicode) to latin-1. This fails since latin-1 doesn't have these characters. Hence the question marks.

Opening an existing file (Saved with notepad or some other program) should result in garbled text as now Vim is just trying to read bytes and interpret them according to the latin-1 character set, and not convert them to the latin-1 set.

You will want to use utf-8 or some such:

:set encoding=utf-8

After which Malayalam script seems to work.

Note that this will not make pre-existing question marks work. These really are converted to question marks (character 0x3f) on input. There is no way to get back what was entered. I suspect that this is the source of confusion of this question.

Also see :help 'encoding'.

As a sidenote, unsupported glyphs in the font are usually rendered with a distinct glyph; this varies per font, but is typically either a square block or a different styled question mark. you can see the difference between a "real" question mark and an unsupported glyph with g8, which will show the character code.

4
  • 1
    I need to type Devanagari or Hindi characters. Encoding was previously set to latin1, it was changed as per your suggestion to utf-8. But still no Devanagari or Hindi characters are visible. But when I copy those boxes (as rendered by VIM), from VIM to browser or Notepad++, they look like Unicode characters. So VIM recognizes, but can't display them.
    – msinfo
    Commented Mar 8, 2016 at 4:20
  • 1
    @msinfo Which Vim version are you using? You mentioned 7.4, but didn't mention the patch level? I used 7.4.1024 from vim.org. Commented Mar 8, 2016 at 4:28
  • 1
    It seems un-patched, as I tried to find out from one of your answer ;-) on vi.stackexchange.com/questions/2466/…. Vim --version doesn't show any patch info. I have not made any plugin or patch changes, after installation.
    – msinfo
    Commented Mar 8, 2016 at 6:14
  • 4
    @msinfo Vim 7.4 was released almost two and half years ago. Try installing the newer version. Maybe that's all that's needed? Commented Mar 8, 2016 at 6:17

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.