7

I need to be break it to you guys, I use emacs. But just for one little thing.

Recently I've been working with a good deal of Japanese people (the company is Japanese) and I got some idea of the language, moreover sometimes I need to write something in Japanese. I do not have a Japanese keyboard and I need to convert some form of "romaji" (Japanese written in latin letters). At first I used google translated but then I learned about emacs's japanese mode. Here is a screenshot of it:

enter image description here

(forgive my Japanese please)

emacs does this with the help of the skk dictionary with some customisations for the actual typing (lisp/international/ja-dic-cvn.el, lisp/international/ja-dic-utl.el and lisp/international/kkc.el in emacs code). Everything happens in UTF-8, the above screenshot is emacs running inside a UTF-8 terminal.


Is there a viable way to perform this in Vim? I'm hoping someone wrote an interface to SKK already, since my Japanese is definitely not good enough to read its documentation.

Or maybe, is there a different method to write Japanese text in Vim?

  • I am not aware of japanese input methods in vim, but it might exist. You may map keys in insert mode for Japanese characters and use. – SibiCoder Jul 12 '16 at 3:25
  • 4
    Perhaps like this? – Sato Katsura Jul 12 '16 at 5:20
  • @SatoKatsura - Wow, yeah. That is actually a super simple to install plugin. Now my only issue is usage. I can get the hiragana input to work out of the box but i'm struggling to use the SKK conversion. I'm literally struggling to read the documentation. Can I have a "dumb westerner" explanation? – grochmal Jul 12 '16 at 19:36
5

OK, this took several days of struggle against the skk.vim plugin mentioned by @SatoKatsura. All the documentation is in Japanese therefore I still do not know of most of its features, and, certainly, there are better ways to accomplish SKK conversion ("Henkan" in Japanese) in Vim than the one presented here. Yet, it works well enough to be comparable to emacs' SKK mode.

First of all you need to donwload the SKK dictionary. Any of them would be enough but I suggests the large dictionary for the sake of completeness. The dictionary comes in the EUC-JP encoding, therefore we need to convert it:

gunzip SKK-JISYO.L.gz
iconv -f euc-jp -t utf-8 SKK-JISYO.L > skk-jisyo-utf-8.l

If your Vim has the +iconv feature the iconv utility should be available on your machine.

The SKK dictionary is in the correct format to be used as a thesaurus, therefore we will set that in Vim and use <c-x><c-t> to perform thesaurus completion. Every line in the SKK dictionary looks as follows:

<kana entry> / <kanji entry> / <kanji entry> / ...
わきでy / 湧き出 / 涌き出 /

Now, we only need to write the <kana entry> part and Vim will be capable of completing the rest for us.

skk.vim can write in Kana in insert-mode. It can write in both Hiragana and Katakana but the SKK dictionary has entries in Hiragana only. Therefore we add a Toogle function wrapper around skk.vim to use either Hiragana or Katakana when in insert-mode. When we want SKK completion we must be in Hiragana mode (this is analogous to emacs's SKK mode).

Here is what I wrote in my .vimrc to wrap skk.vim and use the SKK dictionary as a thesaurus:

let g:skk_initial_mode = 'hira'
let g:skk_script = '~/vim/skk/skk.vim'

set completeopt=menuone,preview
set thesaurus=~/vim/skk/skk-jisyo-utf-8.l

function! ToogleMode()
  if 'hira' ==# g:skk_initial_mode
    let g:skk_initial_mode = 'kata'
  else
    let g:skk_initial_mode = 'hira'
  endif
  execute "source " . g:skk_script
endfunction

To enter Kana mode you press <c-j> to complete a Kanji you need to press <c-j> to exit Kana mode and then <c-x><c-t> to bring up thesaurus completion.

And here is how it looks (the text is exactly the same as in the question):

enter image description here

Disadvantages and quirks:

  • Since we are using Vim's thesaurus we need to add spaces between words. This is not needed in emacs's SKK becuase it keeps a selection trailing behind (see the screenshot in the question).

  • This code is terribly hacky, I just cannot understand about 70% of skk.vim because I'm unable to read the documentation. There certainly are better ways to perform this.

  • You need to exit the Kana mode to perform the thesaurus completion, in Kana mode <c-x><c-t> does not work as expected.

| improve this answer | |
4

Since I was in search for a good way to input unicode Japanese characters in VIM, this post was really helpful. I tried using skk.vim but found it really difficult, because contrary to the OP, I couldn't understand the documentation at all, because I have just started learning Japanese. However, I managed to find an alternative plugin, which seems to be a continuation of skk.vim by the same author.

eskk.vim has English documentation and is well maintained, what is more, it also going to support neovim with this PR. Thanks to @shougo for this feature!

For anyone as new to Japanese as me, you basically need to know a few things on how to write your Japanese easily:

  • Hiragana mode is enabled in the INSERT mode by pressing <C-j>.

  • When you are in the hiragana mode, you can press <q> to toggle the katakana mode.

  • If you want to convert hiragana to kanji, in insert mode start the word you want to convert with ; and then at the end press <C-x><C-o> in order to trigger the omni-completion.

    Note, for the conversion functionality, you will need to have a large JISYO dictionary and it is enough to just download it with the following commands:

    touch "~/.local/share/nvim/skk/skk-jisyo.s"
    target="~/.local/share/nvim/skk/SKK-JISYO.L"
    rm -rf "${target}"{,.gz}
    curl \
      --create-dirs \
      --output "${target}.gz" \
      https://skk-dev.github.io/dict/SKK-JISYO.L.gz
    gunzip "${target}.gz"
    

I am using neovim for this and below is the minimal init.vim (or .vimrc as it should be compatible with vim as well):

let s:data_dir = $HOME . '/.local/share/nvim'

call plug#begin(s:data_dir . '/plugged')
Plug 'tyru/eskk.vim', { 'branch': 'neovim' }
call plug#end()

let g:eskk#directory = s:data_dir . '/skk'
let g:eskk#dictionary = {
    \   'path': s:data_dir . '/skk/skk-jisyo.s',
    \   'sorted': 0,
    \   'encoding': 'utf-8',
    \}
let g:eskk#large_dictionary = {
    \   'path': s:data_dir . '/skk/SKK-JISYO.L',
    \   'sorted': 1,
    \   'encoding': 'euc-jp',
    \}
| improve this answer | |
2

I'm trying to summarize here the experience of the other two users, while trying to keep it simple. Some issues were resolved (e.g. eskk now supports nvim). Also, I'm using pathogen which somewhat affects the exact steps needed:

  1. Install the plugin:

    $ git clone https://github.com/tyru/eskk.vim \
        ~/.vim/bundle/eskk.vim
    
  2. Install the dictionaries.

    Arch Linux. pacman -S skk-jisyo

    Ubuntu. apt install skkdic skkdic-extra

    In case your OS doesn't come with skk dictionaries, you can download them by hand:

    $ curl -o /usr/local/share/skk/SKK-JISYO.L.gz \
        --create-dirs \
        https://skk-dev.github.io/dict/SKK-JISYO.L.gz
    $ gunzip /usr/local/share/skk/SKK-JISYO.L.gz
    
  3. Specify the path to the dictionary (in .vimrc before execute pathogen#infect()):

    let g:eskk#large_dictionary = {
    \   'path': '/usr/share/skk/SKK-JISYO.L',
    \   'sorted': 1,
    \   'encoding': 'euc-jp',
    \ }
    

After that:

  • <C-j> enables processing (eskk). Toggles to be precise. The alpha characters you type get converted to hiragana. Insert mode is indicated as INSERT (lang) when eskk is enabled. E.g. a<C-j>nihonn.

  • When eskk is enabled press q to switch (toggle) it to converting to katakana. E.g. a<C-j>qbasu.

  • When eskk is enabled type ; (displayed as ), a word, then press <Space> to convert it to kanji E.g.a<C-j>;nihonn<Space>.

  • When eskk is enabled type ; (displayed as ), a word, then press <C-x><C-o> to display a list of kanji conversions. E.g.a<C-j>;nihonn<C-x><C-o>. By default orks for 3- or more kana words.

You might want to change the default mappings:

imap <Leader>j <Plug>(eskk:toggle)
cmap <Leader>j <Plug>(eskk:toggle)
lmap <Leader>j <Plug>(eskk:toggle)

In case you want to enable logging:

let g:eskk#log_file_level = 4

By default the logs are written to ~/.eskk/log. In case you want to log additional information you can use: call eskk#logger#debug('...')

We also maintain skk.vim (|skk|, if you have installed). But we decided to create eskk, because skk.vim is mostly unmaintainable due to Vim 6 compatible code.

https://github.com/tyru/eskk.vim/blob/a679ddb9d114d83af0fad7902fae0147feafb628/doc/eskk.txt#L51

With this plugin YY@" doesn't execute the command, you need to additionally press Enter. E.g. a:!ls<Esc>YY@" -> a:!ls<Esc>YY@"<Enter>. And after that eskk remains enabled. The reason for that is the default mappings (<C-j>) getting triggered. YY copies :!ls^J into the " register, which then gets executed with @". But instead of processing ^J literally (running the command), it enables eskk. So you might want to disable the default mappings (let g:eskk#no_default_mappings = 1), or do cmap <Leader>j <Plug>(eskk:toggle).


You most likely need set completeopt+=menuone or set completeopt-=menu completeopt+=menuone (the default being menu,preview). Because if there's only one option, and vim doesn't display the menu, eskk misbehaves. UPD Fixed in 064c6e0

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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