在 vim 中创建不会造成太多延迟的 imap

Creating imaps in vim that don't cause to much of a delay

我正在为一种新语言开发一个 vim 小插件。我目前正在研究一些很酷的效果,将一些字符和单词更改为坏蛋 unicode 字符,例如 \ 变成 λ.

我现在想让 not 变成 ¬ 但这会导致一些并发症,因为我不能只匹配 not 因为那会导致像 nottingham 这样的词变成 ¬tingham 所以我创建了 imap:

inoremap <space>not<space> ¬

但这会在每次按下 space 时造成烦人的延迟。有办法解决这个问题吗?

注意: 我没有使用 conceal,因为它会导致字符向后和第四翻转,并且会干扰突出显示。

您可以使用

iabbrev not ¬

这使用了更快的内置缩写系统 比带空格的 inoremap。

为此使用缩写:

:abbrev not ¬

对于"space before 'not' part":
来自:help abbreviations('not'是full-id的缩写,所有缩写类型见帮助):

The characters before the cursor must match the abbreviation.  Each type has
an additional rule:

full-id   In front of the match is a non-keyword character, or this is where
          the line or insertion starts.  Exception: When the abbreviation is
          only one character, it is not recognized if there is a non-keyword
          character in front of it, other than a space or a tab.

对于"space after 'not' part":

An abbreviation is only recognized when you type a non-keyword character.
This can also be the <Esc> that ends insert mode or the <CR> that ends a
command.

timeouton 时,超时延迟由 timeoutlen=1000 控制,默认值为 on

因此,要将当前超时值减半,:set timeoutlen=500

更多内容在 :h timeout。 不确定,这是否是您正在寻找的但比 abbr 方法更灵活。