windows - AutoHotKey Hotstring 不会在 Windows 上的 gvim 或 WSL Ubuntu 中的 vim 中触发
问题描述
我使用 AHK 将字符串自动转换为]dd
当前日期(参见下面的代码)。在大多数 Windows 文本编辑器/区域中使用它时,它工作正常。但是当我在gvim
Windows 或vim
WSL 上的 Ubuntu 中使用时,我经常需要输入一个“启动”字符或尝试几次热字符串才能使其工作。搜索论坛并没有返回关于这个特定问题的任何点击。
#NoEnv ; Recommended for performance and compatibility with future
AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; This allows me to quickly enter date and time stamps.
::]dd::
FormatTime, TimeString, , yyMMdd ; LongDate
Send, %TimeString%
Return
:*:]t::
FormatTime, TimeString, , HHmm
Send, %TimeString%
Return
:*:]dt::
FormatTime, TimeString, , yyMMdd HHmm
Send, %TimeString%
Return
这些在记事本或我使用过的其他无模式文本编辑器/区域中几乎完美无缺,但我真的很喜欢 vim。
我猜 AHK 正在关闭空格字符而不是 CR/LF,因此insert
在 vim 模式编辑器中输入模式(包括使用 IdeaVim 插件的 PyCharm 之类的)并点击Enter
不会让 AHK 知道开始寻找莫哈特斯特朗斯。我必须打Space
,有时打几次,才能使热字符串被识别。
我想我可以只创建热键,但我在 macOS 上的 Keyboard Maestro 和 *NIXes 中的键盘设置中使用这种方法,并且我重视肌肉记忆。
是否有我忽略的配置,或者这只是一个边缘情况?
解决方案
为了使其在 Vim 中可靠且一致地工作,在 hotstring 选项中,包括问号和星号 ( :*?:...
) 而不仅仅是星号或空选项。这种解决方法是唯一对我在 Windows 上的 Vim 上有效的方法。否则,Autohotkey 第一次进入插入模式时不会展开。
所以,它可能看起来像:
...
:*?:]dd::
FormatTime, TimeString, , yyMMdd ; LongDate
Send, %TimeString%
Return
:*?:]t::
FormatTime, TimeString, , HHmm
Send, %TimeString%
Return
:*?:]dt::
FormatTime, TimeString, , yyMMdd HHmm
Send, %TimeString%
Return
但是,这会稍微改变行为,因为它会触发单词中的热字串,所以Hello]dd
会触发]dd
。但我可以忍受这一点,避免总是检查它是否触发了热字符串的挫败感。
或者,为了完美匹配初始行为,我会使用UltiSnips
插件在 vim 中重新创建文本扩展,但这会比必要的工作多一点。
推荐阅读
- apache-spark - Spark Streaming、Structured Streaming 和 Kafka Streaming 是一回事吗?
- bash - 我可以使用 cut 来设置变量吗?
- google-cloud-platform - 为什么在列出 BQ 作业时使用 VM 实例中的服务帐户
- windows - 在 Windows 中设置特定于进程的权限
- reactjs - 有没有加速 React src 代码编译的工具?
- java - HTTP POST 中缺少授权标头
- android - 如何使用 RecyclerView 适配器显示来自 Firebase 存储的图片?
- git - 如何设置 vscode 以自动显示 git repo 中修改的文件而不刷新?
- javascript - Angular 和 moment.js:我应该将来自 json 字符串的字段转换为 Date 还是 moment.Moment?
- java - 什么是 com.singularity.ee.agent.appagent.kernel.spi.c java 代理?