Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple digraphs in vim

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 "さよなら".

like image 962
user1094249 Avatar asked Oct 21 '25 04:10

user1094249


1 Answers

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.

like image 118
Benoit Avatar answered Oct 24 '25 21:10

Benoit