Vim Fails to Honor Keyboard Maestro's Type-String-Trigger's Simulated Deletes

Hi all!

I have a "This string is typed" option with simulated deletes which works great in most apps. But in vim, deletes don't seem to be taking effect. So I'm ending up with the trigger text followed by the insertion.

Have ya'll figured out a way to get that working with vim?

I found a post that seems to discuss this:

You can always add your own actions to the start of the macro to delete the typed characters in whatever method works in vim (I don't use vim, so I couldn't say what that is).

1 Like

Since the %TriggerValue% returns the string that triggered the macro, could he just use a REPEAT action, repeating a DELETE key for as many times as the length of the triggering string? Like this...?



I think what I need is a condition to detect if I'm in vim, then I can simulate the proper actions.

But vim is a program that runs in a Terminal program...

Is there a native way for KM to know which program is running within a Terminal and is at the front?

If there's no direct way then maybe I can setup vim to set some env var on entry and unset it on exit, but that might not be that simple since I usually have several vim sessions running.


You can use a KM "Execute AppleScript" action. This AS will return the text "vim" if vim is running in tab 1 of the frontmost Terminal window -- do note that it will also return "vim" if you've somehow backgrounded vim in that window:

tell application "Terminal"
	if processes of tab 1 of window 1 contains "vim" then return "vim"
end tell

You can even check which mode you are in when vim is running. For example:

tell application "Terminal"
	if paragraph -2 of (get contents of tab 1 of window 1) is "-- INSERT --" then return "insert mode"
end tell

Those, in conjunction with @Sleepy's "Repeat -- Type a Keystroke" suggestion, should get you most of the way there. If not, post your macro along with examples (including vim mode) of what you want to do.

1 Like