multiple digraphs in vim

414 views Asked by At

As you probably know, there is ability to enter some specific characters in vim using digraphs (In input mode Ctrl+K Rg produces ® for example).

Is there a way, to define hotkey, to enter the mode which allows me to input multiple digraphs? For example, to write "sayonara" instead of "Ctrl+K sa Ctrl+K yo Ctrl+K na Ctrl+K ra" to get "さよなら".

2

There are 2 answers

1
Benoit On BEST ANSWER

Not that I know. However you can imagine this:

exec 'normal! i' . substitute('sayonara', '\(..\)', nr2char(11) . '\1', 'g')

nr2char(11) is a CTRL-K character.

If you want a mapping for that (for example in visual mode hit F1 over the selection to transform it; use this on one-line characterwise selection only):

xnoremap <f1> d:exec 'normal! a' . substitute(@", '\(..\)', nr2char(11) . '\1', 'g')<ENTER>

There might be more proper ways to do that (without erasing the contents of the default register) but I will be too lazy for today. I suspect some Stackers might want to post another answer with cleaner code, they'll get my upvote.

0
Kev Nickells On

This is an old question but the given answer seems unnecessarily complex.

iab sayonara さよなら

In your .vimrc will mean that every time you type sayonara you'll get さよなら

See :help abbreviations - iab is 'insert abbreviation' which I use extensively for bad spellings, digraph substitution etc.