LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   vim can't display Chinese but gvim can (http://www.linuxquestions.org/questions/slackware-14/vim-cant-display-chinese-but-gvim-can-4175469511/)

narke 07-13-2013 09:33 AM

vim can't display Chinese but gvim can
 
Hi,

I usually like use vim to edit source code, even in my X (fluxbox). One problem is, if in gvim I can see Chinese characters (as comments in some of my source code), but in vim (open in konsole terminal program), the same Chinese characters only displayed as unrecognized strange string.

In both gvim and Konsole, I configured to use the same font, Bitstream Versa Sans Mono. I don't understand, with the same font setting, why gvim can display Chinese but konsole+vim can not.

Where should I to check the error?

Thanks in advance.

-
woody

jostber 07-13-2013 02:20 PM

Try to set another font?

http://superuser.com/questions/14195...racters-in-vim

Kallaste 07-13-2013 06:46 PM

I've heard of a lot of problems with Konsole and unicode characters. I could be wrong, but I'm not sure that Konsole has full unicode support. If you don't know otherwise, you might want to try another terminal that we know does have it, such as rxvt-unicode.

guanx 07-13-2013 09:23 PM

1 Attachment(s)
I don't think there is something wrong with konsole. The OP may want to post an example file to demonstrate the problem if he really can't get rid of multi-byte characters from his source code.

narke 07-13-2013 09:25 PM

Quote:

Originally Posted by BloomingNutria (Post 4989855)
I've heard of a lot of problems with Konsole and unicode characters. I could be wrong, but I'm not sure that Konsole has full unicode support. If you don't know otherwise, you might want to try another terminal that we know does have it, such as rxvt-unicode.

Hi, Blooming. I just tried rxvt-unicode, it works! A Vim run in it can display Chinese!

Another thing, then how do I change the (English) font used by rxvt-unicode? I prefer Bitstream Versa Sans Mono.

T3slider 07-13-2013 10:00 PM

Quote:

Originally Posted by narke (Post 4989904)
Another thing, then how do I change the (English) font used by rxvt-unicode? I prefer Bitstream Versa Sans Mono.

That's the font I use too. I have this in ~/.Xdefaults:
Code:

URxvt*font: xft:Bitstream\ Vera\ Sans\ Mono:style=roman:pixelsize=13:antialias=true:hinting=true
You will probably have to run
Code:

$ xrdb -merge
and restart urxvt to see the new font (or restart X).

Kallaste 07-13-2013 10:58 PM

Quote:

Originally Posted by guanx (Post 4989903)
I don't think there is something wrong with konsole. The OP may want to post an example file to demonstrate the problem if he really can't get rid of multi-byte characters from his source code.

From what I see on Google, Unicode font rendering is a common problem in Konsole. I think it is supposed to work, but isn't quite ironed out yet. Here is a bug report:

http://kde.6490.n7.nabble.com/Bug-74190-Console-Unicode-support-not-100-there-td1251526.html


Quote:

Hi, Blooming. I just tried rxvt-unicode, it works! A Vim run in it can display Chinese!

Another thing, then how do I change the (English) font used by rxvt-unicode? I prefer Bitstream Versa Sans Mono.
Good news. :) I'm glad that was the only problem. You can read this to learn more about how to configure your ~/.Xresources file to change fonts, colors, and other settings:

https://wiki.archlinux.org/index.php/Rxvt-unicode

narke 07-13-2013 11:44 PM

3 Attachment(s)
Quote:

Originally Posted by guanx (Post 4989903)
I don't think there is something wrong with konsole. The OP may want to post an example file to demonstrate the problem if he really can't get rid of multi-byte characters from his source code.

Guanx, interesting in see your screenshot. It seems your vim can display Chinese. I'd already set my localte to GBK, but don't know why I can't see the Chinese welcome screen of vim -- I just get English.

Below are some screenshots related to the topic. Do you have a clue about the problem? Thanks.

narke 07-13-2013 11:51 PM

1 Attachment(s)
Quote:

Originally Posted by T3slider (Post 4989912)
That's the font I use too. I have this in ~/.Xdefaults:
Code:

URxvt*font: xft:Bitstream\ Vera\ Sans\ Mono:style=roman:pixelsize=13:antialias=true:hinting=true
You will probably have to run
Code:

$ xrdb -merge
and restart urxvt to see the new font (or restart X).

I did the same thing, but the fonts get rendered very urgly. It looks too small, and have too much space between characters. You can check the attached screen shot. Don't know where the problem come from.

narke 07-14-2013 12:00 AM

Another very strange thing is: the urxvt can display Chinese only when it is started from Konsole! If I start it directly (from fluxbox 'run' command or from fluxbox menu), it cannot display Chinese. What's wrong? Thanks.

Kallaste 07-14-2013 01:41 AM

Did you ever edit your /etc/profile.d/lang.sh file before this? In order to support Unicode text, I believe you need to edit that file and change the line that says

Code:

# en_US is the Slackware default locale:
export LANG=en_US

to

Code:

# en_US is the Slackware default locale:
export LANG=nl_NL.UTF-8

Also, I do not use Konsole, but there should be a setting in the menu somewhere that let's you set it to use UTF-8 directly. Try Settings -> Encoding -> Unicode (utf8).

narke 07-14-2013 05:16 AM

Quote:

Originally Posted by BloomingNutria (Post 4989985)
Did you ever edit your /etc/profile.d/lang.sh file before this? In order to support Unicode text, I believe you need to edit that file and change the line that says

Code:

# en_US is the Slackware default locale:
export LANG=en_US

to

Code:

# en_US is the Slackware default locale:
export LANG=nl_NL.UTF-8

Also, I do not use Konsole, but there should be a setting in the menu somewhere that let's you set it to use UTF-8 directly. Try Settings -> Encoding -> Unicode (utf8).

Hi Blooming, many thanks for your hints! My Konsole char encoding setting is "using default: utf-8". So, in the past, I've already thinking that it is okay and never change it. After read your post, I tried to change it to GBK. On the other hand, my /etc/profile.d/lang.sh is also GBK (zh_CN.gbk). Then, after reboot X, I found Konsole works! It can display Chinese without problem! I am so happen, though I still don't understand why setting these to utf-8 did not work.

On the other hand, even urxvt can display Chinese in previous locale setting (I have to run it with 'bash -l -c urxvt'), but it font rending is really poor than Konsole. Konsole looks more nice to me.

guanx 07-14-2013 06:23 AM

Quote:

Originally Posted by BloomingNutria (Post 4989930)
From what I see on Google, Unicode font rendering is a common problem in Konsole. I think it is supposed to work, but isn't quite ironed out yet. Here is a bug report:

http://kde.6490.n7.nabble.com/Bug-74190-Console-Unicode-support-not-100-there-td1251526.html

The bug report you quoted is from Dec 05, 2011. Today is Jul 14, 2013.

guanx 07-14-2013 06:34 AM

Quote:

Originally Posted by narke (Post 4990034)
..., though I still don't understand why setting these to utf-8 did not work. ...

From your screenshot you're displaying a text file in GBK encoding as UTF-8. of course this does not work.

I think the best way to avoid encoding problems is to not use multi-byte character in C source code but use "gettext".

If you really have political problems (e.g. your boss forces you to embed Chinese in C source code), please use the UTF-8 encoding, and set your locale to zh_CN.UTF-8.

narke 07-14-2013 07:00 AM

Quote:

Originally Posted by guanx (Post 4990057)
From your screenshot you're displaying a text file in GBK encoding as UTF-8. of course this does not work.

I think the best way to avoid encoding problems is to not use multi-byte character in C source code but use "gettext".

If you really have political problems (e.g. your boss forces you to embed Chinese in C source code), please use the UTF-8 encoding, and set your locale to zh_CN.UTF-8.

I agree 'gettext' is good choice. The problem is that I have to work with a lot of legacy code, which already have embedded Chinese characters. Anyway, thanks for your advices!


All times are GMT -5. The time now is 06:31 PM.