vim 中的多个二合字母

发布于 2024-12-27 12:16:20 字数 171 浏览 6 评论 0原文

您可能知道,可以使用二合字母在 vim 中输入某些特定字符(例如,在输入模式下 Ctrl+K Rg 会生成 ®)。

有没有办法定义热键,进入允许我输入多个二合字母的模式?例如,写“sayon​​ara”而不是“Ctrl+K sa Ctrl+K yo Ctrl+K na Ctrl+K ra”即可得到“さよなら”。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

年华零落成诗 2025-01-03 12:16:20

我不知道。不过您可以想象一下:

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

nr2char(11) 是一个 CTRL-K 字符。

如果您想要为此进行映射(例如,在可视模式下,在选择上按 F1 对其进行转换;仅在单行字符选择上使用此选项):

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

可能有更合适的方法来做到这一点(无需擦除默认的内容)注册)但今天我太懒了。我怀疑一些 Stackers 可能想用更清晰的代码发布另一个答案,他们会得到我的支持。

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.

乖乖兔^ω^ 2025-01-03 12:16:20

这是一个老问题,但给出的答案似乎不必要地复杂。

iab sayon​​ara さよなら

在你的 .vimrc 中意味着每次你输入 sayon​​ara 你都会得到 さよなら

看< code>:help abbreviations - iab 是“插入缩写”,我广泛使用它来表示错误拼写、二合字母替换等

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文