简体   繁体   English

AutoHotKey Hotstring 不会在 Windows 上的 gvim 或 WSL Ubuntu 中的 vim 中触发

[英]AutoHotKey Hotstring Won't Trigger in gvim on Windows or vim in WSL Ubuntu

I use AHK to autoconvert a string like ]dd to the current date (see code below).我使用 AHK 将像]dd这样的字符串自动转换为当前日期(见下面的代码)。 When using this in most Windows text editors/areas, it works fine.在大多数 Windows 文本编辑器/区域中使用它时,它工作正常。 But when I'm using gvim for Windows or vim in Ubuntu on WSL, I often have to type a "priming" character or try the hotstring a couple times for it to work.但是当我在 WSL 上为 Windows 使用gvim或在 Ubuntu 中使用vim时,我经常需要输入一个“启动”字符或尝试几次热字符串才能使其工作。 Searching the forum didn't return any hits on this particular issue.搜索论坛没有返回有关此特定问题的任何点击。

#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

These work practically flawlessly in Notepad or other modeless text editors/areas I've used, but I really enjoy vim.这些在记事本或我使用过的其他无模式文本编辑器/区域中几乎完美无缺,但我真的很喜欢 vim。

I'm guessing AHK is keying off of the space character and not CR/LF, so entering insert mode in a vim-mode editor (including the likes of PyCharm using the IdeaVim plugin) and hitting Enter doesn't let AHK know to start looking for muh hawtstrangs.我猜 AHK 正在关闭空格字符而不是 CR/LF,因此在 vim 模式编辑器中进入insert模式(包括使用 IdeaVim 插件的 PyCharm 之类)并按Enter不会让 AHK 知道开始寻找 muh hawtstrangs。 I have to hit Space , and sometimes hit it a few times, to get the hotstring to be recognized.我必须点击Space ,有时还要点击几次,才能识别出热字串。

I suppose I could just create hotkeys instead but I use this approach in Keyboard Maestro on macOS and keyboard settings in *NIXes and I value the muscle memory.我想我可以只创建热键,但我在 macOS 上的键盘大师和 *NIXes 中的键盘设置中使用这种方法,我很重视肌肉记忆。

Is there a configuration somewhere that I'm overlooking, or is this just an edge case?是否有我忽略的配置,或者这只是一个边缘情况?

To make it work reliably and consistently in Vim, in the hotstring option, include both question mark and asterisk ( :*?:... ) instead of just asterisk or empty option.为了使其在 Vim 中可靠且一致地工作,在 hotstring 选项中,包括问号和星号( :*?:... ),而不仅仅是星号或空选项。 This workaround is only thing that worked for me on Vim on Windows.此解决方法仅适用于我在 Windows 上的 Vim 上。 Otherwise, Autohotkey would not expand when it enters the insert-mode for the first time.否则第一次进入插入模式时,Autohotkey 不会展开。

So, it might look like:所以,它可能看起来像:

...

:*?:]dd::
FormatTime, TimeString, , yyMMdd ; LongDate
Send, %TimeString%
Return

:*?:]t::
FormatTime, TimeString, , HHmm
Send, %TimeString%
Return

:*?:]dt::
FormatTime, TimeString, , yyMMdd HHmm
Send, %TimeString%
Return

However, this will change the behavior slightly since it will trigger the hotstring inside a word, so Hello]dd will trigger ]dd .但是,这会稍微改变行为,因为它会触发单词内的热字符串,因此Hello]dd将触发]dd But I could live with this and avoid the frustration of always checking if it triggered the hotstring or not.但我可以忍受这一点,避免总是检查它是否触发了热字符串的挫败感。

Alternatively, in order to perfectly match the initial behavior, I'd recreate the text expansion in vim using UltiSnips plugin, but that'd be a little more work than necessary.或者,为了完美匹配初始行为,我会使用UltiSnips插件在 vim 中重新创建文本扩展,但这会比必要的工作多一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM