Japanese text in vim?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Japanese text in vim?

c.lina
Hi all,

sorry if part (or all) of this email is off-topic.

* I am trying to learn Japanese.
* I am using vim 6.3 on linux in an xterm.

I can copy-paste japanese text from an internet page into a
text file edited with vim; the
text ist correctly displayed, also after the file with the
Japanese fonts is closed and opened again. Now, how can I
input Japanese text myself? I have tried to read a bit in
the vim help but I understand probably less then half of
what is described there.

Another related, but even more off-topic: I am using
sylpheed with vim as external editor to write emails. When
copy-pasting text into and email edited with vim and then
saving, I can see the japanese fonts in sylpheeds's
mail-window. After I sent the email to myself and opened it,
the kanjis were gone, and only ______ is left where the
Japanese text should be.

Any help is appreciated.
Regards, Catherine.
Reply | Threaded
Open this post in threaded view
|

Re: Japanese text in vim?

Matthew Huggett
Hi,

 > Now, how can I input Japanese text myself?

This is how I do it (for what it's worth):

1) Compile vim with
        --enable-multibyte
        --enable-xim
        --enable-fontset
        --enable-gui=gtk2
2) I use SCIM to input Japanese.  SCIM starts when I start X and
    I launch vim from a shell script containing:
        ,-------------------------
        | export LC_CTYPE=en_US.UTF-8
        | export XMODIFIERS=@im=SCIM
        | export GTK_IM_MODULE=xim
        `-------------------------
    And then vim can take input from SCIM.
3) I know absolutely nothing about fonts, and I didn't need to to get
    Japanese and Chinese with vim.  I have 2 unicode fonts installed (Arial
    Unicode MS and Code2000).  With gtk2, unicode glyphs seem to be
    substituted from those fonts as needed.  All my latin text is still
    displayed in a fixed-width font.

If you haven't already, you might want to do
        ,-------------------------
        | :h encoding
        `-------------------------

Matt

[hidden email] wrote:
 > Hi all,
 >
 > sorry if part (or all) of this email is off-topic.
 >
 > * I am trying to learn Japanese.
 > * I am using vim 6.3 on linux in an xterm.
 >
 > I can copy-paste japanese text from an internet page into a
 > text file edited with vim; the
 > text ist correctly displayed, also after the file with the
 > Japanese fonts is closed and opened again. Now, how can I
 > input Japanese text myself? I have tried to read a bit in
 > the vim help but I understand probably less then half of
 > what is described there.
 >
 > Another related, but even more off-topic: I am using
 > sylpheed with vim as external editor to write emails. When
 > copy-pasting text into and email edited with vim and then
 > saving, I can see the japanese fonts in sylpheeds's
 > mail-window. After I sent the email to myself and opened it,
 > the kanjis were gone, and only ______ is left where the
 > Japanese text should be.
 >
 > Any help is appreciated.
 > Regards, Catherine.
 >
 >
Reply | Threaded
Open this post in threaded view
|

Re: Japanese text in vim?

A.J.Mechelynck
In reply to this post by c.lina
----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Thursday, August 25, 2005 11:07 AM
Subject: Japanese text in vim?


> Hi all,
>
> sorry if part (or all) of this email is off-topic.
>
> * I am trying to learn Japanese.
> * I am using vim 6.3 on linux in an xterm.
>
> I can copy-paste japanese text from an internet page into a
> text file edited with vim; the
> text ist correctly displayed, also after the file with the
> Japanese fonts is closed and opened again. Now, how can I
> input Japanese text myself? I have tried to read a bit in
> the vim help but I understand probably less then half of
> what is described there.
>
> Another related, but even more off-topic: I am using
> sylpheed with vim as external editor to write emails. When
> copy-pasting text into and email edited with vim and then
> saving, I can see the japanese fonts in sylpheeds's
> mail-window. After I sent the email to myself and opened it,
> the kanjis were gone, and only ______ is left where the
> Japanese text should be.
>
> Any help is appreciated.
> Regards, Catherine.

- You need a gvim (a GUI vim, not a console Vim), with +multi_byte
compiled-in, but I believe you have this already.
- You need to set
    - 'encoding' to something that will handle Japanese, I suggest UTF-8 for
reasons that will become apparent later
    - 'termencoding' to whatever 'encoding' was set to before you changed
it.

If you don't know your default 'encoding', use a scriptlet like this one:

    if &termencoding == ""
        let &termencoding = &encoding
    endif
    set encoding=utf-8

You also need to set 'guifont' to a font with Japanese glyphs. How to do
that will vary according to your GUI version. See my tip
http://vim.sourceforge.net/tips/tip.php?tip_id=632

I have tried, without success, using "Input Methods". Here is what I do when
I want to input Chinese/Japanese/Korean characters:

- Have a "dictionary by radicals" handy. For Japanese, and even in large
part for Chinese, Nelson's "Modern Reader's Japanese-English Character
Dictionary" (Rutland, Vermont and Tokyo, Japan: Charles E. Tuttle Company,
Publishers) is IMHO the best.

Then:
Method I
========

- Avail yourself of the file "unihan.txt" from the Unicode site
http://www.unicode.org/ -- Beware: it is a _very big_ text file.
- I suggest modifying the file (using Vim's ":substitute" command). The
following will do it (once and for all):

1. Create a file with the following contents (use cut-and-paste):

function! InsertKanji()
    let line=getline(".")
    normal 3|yee
    exe 'let @@ = " \u' . @@ . '"'
    normal p
endfunction

2. Save it and source it:

    :saveas ~/InsertKanji.vim
    :source ~/InsertKanji.vim

3. Do the following in Unihan.txt:

    :1,$g/^U+\x\x\x\x/call InsertKanji()

The command may take a while to complete; once it does, every non-comment
line should have its own kanji added immediately after the U+xxxx codepoint
(with an intervening space). Note that some "additional" characters at the
beginning and end of the list may not have a glyph in your font. This is
normal. The first "normal" kanji is the "number one", described on lines
starting U+4E00 (search for /^U+4E00\>/). It uses 61 lines all by itself;
all these lines start U+4E00.

4. Add a BOM in front of the file so it will always be recognised as UTF-8:

    :setlocal bomb

5. Save the result using ":saveas Unihan1.txt" to avoid clobbering the
original Unihan.txt

- Each character has a number of lines in that file; since the lines are
sorted on Unicode codepoint, all lines relative to the same character are
together. Use Vim searching to find your character. For instance:
    - if you found it as character number 3325 in Nelson's, search on the
pattern /\<kNelson\t3325\>/ (the words kNelson and 3325 separated by a tab).
    - Or if you found it as "traditional-radical 116 + 6 additional strokes"
in any dictionary by strokes, search on /\<kRSKangXi\t116.6\>/ (in this case
there will be multiple hits). The kanji added above at step 2 will help you.
    - Or if you know that it has a kun-spelling "fusagaru" in romaji, search
on /\<kJapaneseKun\t.*\<FUSAGARU\>/ (i.e., begin word, kJapaneseKun, tab,
zero or more characters, begin word, FUSAGARU, end word). Here there may or
may not be several hits. Again, the kanji added above at step 2 will help
you.
    - And so on.
- All the above correspond to the same character, U+7A92. You can enter it
in your file either by copy-paste (yank and put, in Vim terminology) using
the kanji that we added, or by using the method described under ":help
i_CTRL-V_digit" (in this case, ^Vu7A92 where ^V means "hit Ctrl-V once"). If
you have mapped Ctrl-V to paste from the clipboard, use Ctrl-Q in its stead.

Method II
=========
Download and optionally print the "code charts" for CJK characters from the
Unicode site mentioned above (a bulky set of PDF files). The characters are
arranged in the same sequence as in a "dictionary by radicals", with
traditional-Chinese-and-Japanese and simplified-mainland-Chinese mixed
together, and with each "simplified-mainland-Chinese radical" immediately
after its "traditional" equivalent (so, all simplified characters with the
simplified 2-stroke "speech" radical follow all traditional characters with
the 7-stroke "speech" radical [No. 149], similarly for the simplified
3-stroke "gate" and the traditional 8-stroke "gate" [No. 169] etc.) For
Japanese, mostly only "traditional" characters are used. Find the part of
the charts corresponding to your character's traditional-radical, then all
characters ranked under that same traditional-radical are in ascending
number of strokes. You will find the Unicode codepoint as 4 (or rarely 5)
hex digits. See ":help i_CTRL-V_digit" about how to enter the kanji in your
Vim file.


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: Japanese text in vim?

c.lina
Thank you, Matt and Tony, for your suggestions.
For typing Japanese texts the method proposed by Matt is
more comfortable though one has to get used to it. Using
mlterm or uxterm, I can even input Japanese text in vim (not gvim).

Regards, Catherine.

On Thu, 25 Aug 2005 18:29:55 +0200
"Tony Mechelynck" <[hidden email]> wrote:

> ----- Original Message -----
> From: <[hidden email]>
> To: <[hidden email]>
> Sent: Thursday, August 25, 2005 11:07 AM
> Subject: Japanese text in vim?
>
>
> > Hi all,
> >
> > sorry if part (or all) of this email is off-topic.
> >
> > * I am trying to learn Japanese.
> > * I am using vim 6.3 on linux in an xterm.
> >
> > I can copy-paste japanese text from an internet page into a
> > text file edited with vim; the
> > text ist correctly displayed, also after the file with the
> > Japanese fonts is closed and opened again. Now, how can I
> > input Japanese text myself? I have tried to read a bit in
> > the vim help but I understand probably less then half of
> > what is described there.
> >
> > Another related, but even more off-topic: I am using
> > sylpheed with vim as external editor to write emails. When
> > copy-pasting text into and email edited with vim and then
> > saving, I can see the japanese fonts in sylpheeds's
> > mail-window. After I sent the email to myself and opened it,
> > the kanjis were gone, and only ______ is left where the
> > Japanese text should be.
> >
> > Any help is appreciated.
> > Regards, Catherine.
>
> - You need a gvim (a GUI vim, not a console Vim), with +multi_byte
> compiled-in, but I believe you have this already.
> - You need to set
>     - 'encoding' to something that will handle Japanese, I suggest UTF-8 for
> reasons that will become apparent later
>     - 'termencoding' to whatever 'encoding' was set to before you changed
> it.
>
> If you don't know your default 'encoding', use a scriptlet like this one:
>
>     if &termencoding == ""
>         let &termencoding = &encoding
>     endif
>     set encoding=utf-8
>
> You also need to set 'guifont' to a font with Japanese glyphs. How to do
> that will vary according to your GUI version. See my tip
> http://vim.sourceforge.net/tips/tip.php?tip_id=632
>
> I have tried, without success, using "Input Methods". Here is what I do when
> I want to input Chinese/Japanese/Korean characters:
>
> - Have a "dictionary by radicals" handy. For Japanese, and even in large
> part for Chinese, Nelson's "Modern Reader's Japanese-English Character
> Dictionary" (Rutland, Vermont and Tokyo, Japan: Charles E. Tuttle Company,
> Publishers) is IMHO the best.
>
> Then:
> Method I
> ========
>
> - Avail yourself of the file "unihan.txt" from the Unicode site
> http://www.unicode.org/ -- Beware: it is a _very big_ text file.
> - I suggest modifying the file (using Vim's ":substitute" command). The
> following will do it (once and for all):
>
> 1. Create a file with the following contents (use cut-and-paste):
>
> function! InsertKanji()
>     let line=getline(".")
>     normal 3|yee
>     exe 'let @@ = " \u' . @@ . '"'
>     normal p
> endfunction
>
> 2. Save it and source it:
>
>     :saveas ~/InsertKanji.vim
>     :source ~/InsertKanji.vim
>
> 3. Do the following in Unihan.txt:
>
>     :1,$g/^U+\x\x\x\x/call InsertKanji()
>
> The command may take a while to complete; once it does, every non-comment
> line should have its own kanji added immediately after the U+xxxx codepoint
> (with an intervening space). Note that some "additional" characters at the
> beginning and end of the list may not have a glyph in your font. This is
> normal. The first "normal" kanji is the "number one", described on lines
> starting U+4E00 (search for /^U+4E00\>/). It uses 61 lines all by itself;
> all these lines start U+4E00.
>
> 4. Add a BOM in front of the file so it will always be recognised as UTF-8:
>
>     :setlocal bomb
>
> 5. Save the result using ":saveas Unihan1.txt" to avoid clobbering the
> original Unihan.txt
>
> - Each character has a number of lines in that file; since the lines are
> sorted on Unicode codepoint, all lines relative to the same character are
> together. Use Vim searching to find your character. For instance:
>     - if you found it as character number 3325 in Nelson's, search on the
> pattern /\<kNelson\t3325\>/ (the words kNelson and 3325 separated by a tab).
>     - Or if you found it as "traditional-radical 116 + 6 additional strokes"
> in any dictionary by strokes, search on /\<kRSKangXi\t116.6\>/ (in this case
> there will be multiple hits). The kanji added above at step 2 will help you.
>     - Or if you know that it has a kun-spelling "fusagaru" in romaji, search
> on /\<kJapaneseKun\t.*\<FUSAGARU\>/ (i.e., begin word, kJapaneseKun, tab,
> zero or more characters, begin word, FUSAGARU, end word). Here there may or
> may not be several hits. Again, the kanji added above at step 2 will help
> you.
>     - And so on.
> - All the above correspond to the same character, U+7A92. You can enter it
> in your file either by copy-paste (yank and put, in Vim terminology) using
> the kanji that we added, or by using the method described under ":help
> i_CTRL-V_digit" (in this case, ^Vu7A92 where ^V means "hit Ctrl-V once"). If
> you have mapped Ctrl-V to paste from the clipboard, use Ctrl-Q in its stead.
>
> Method II
> =========
> Download and optionally print the "code charts" for CJK characters from the
> Unicode site mentioned above (a bulky set of PDF files). The characters are
> arranged in the same sequence as in a "dictionary by radicals", with
> traditional-Chinese-and-Japanese and simplified-mainland-Chinese mixed
> together, and with each "simplified-mainland-Chinese radical" immediately
> after its "traditional" equivalent (so, all simplified characters with the
> simplified 2-stroke "speech" radical follow all traditional characters with
> the 7-stroke "speech" radical [No. 149], similarly for the simplified
> 3-stroke "gate" and the traditional 8-stroke "gate" [No. 169] etc.) For
> Japanese, mostly only "traditional" characters are used. Find the part of
> the charts corresponding to your character's traditional-radical, then all
> characters ranked under that same traditional-radical are in ascending
> number of strokes. You will find the Unicode codepoint as 4 (or rarely 5)
> hex digits. See ":help i_CTRL-V_digit" about how to enter the kanji in your
> Vim file.
>
>
> Best regards,
> Tony.
>
>


--
==================================================
Cras vives? Hodie iam vivere, Postume, serum est.
Reply | Threaded
Open this post in threaded view
|

Re: Japanese text in vim?

adah
In reply to this post by c.lina
[hidden email] wrote:
> Another related, but even more off-topic: I am using
> sylpheed with vim as external editor to write emails. When
> copy-pasting text into and email edited with vim and then
> saving, I can see the japanese fonts in sylpheeds's
> mail-window. After I sent the email to myself and opened it,
> the kanjis were gone, and only ______ is left where the
> Japanese text should be.

Others have answered the more on-topic part of your message, and I am
trying to answer the remaining part.  Mostly likely your mail message
encoding was still set to something like ISO-8859-1, and to send
Japanese correctly, you need to find some option to set it to UTF-8 or
SJIS, which contains code points to encode Japanese characters.

If you cannot find the option to set the message encoding, the mailer
possibly is not ready for international use.  If you set the encoding
correctly and still you cannot read it, it is possibly a font problem.

Best regards,

Yongwei