1

Sublime Text is by far the best text editor I've ever seen, and AutoHotKey is the scripting program I can't live without, especially the hotstrings feature, which allows me to create abbreviation-expansion pairs, speeding up the typing significantly. These two human inventions boost my day-to-day productivity in an unimaginable way. Recently I've been learning how to use Vim, and I'm getting comfortable enabling the "Vintage mode" in Sublime Text.

However, there is a major problem: the Vim commands can interfere with AutoHotKey's hotstrings. Let's say I have this hotstring:

::xeno::xenófobo

...which means, if it type "xeno" then it will expand to "xenófobo". However, in Vim, "xeno" would, sequentially, delete current line, then jump to end of word, then search for next occurence of input string, then open a new line. This is unwanted.

Even worse is it when the expansion part itself contains a meaningful Vim sequence:

::eve::Eddie Vedder

...which would jump to end of word, delete current line, switch to insert mode, insert "e Vedder". Absolutely catastrophic.

But AutoHotKey is powerful, and we can set it to ignore some windows. Example: if the active window has a string like " - Sublime Text" in its title, we can have it ignore the hotstrings input. As for Sublime Text with Vim mode enabled, it will display "COMMAND MODE" or "INSERT MODE" in the status bar, not in the title bar! So AutoHotKey is unable to tell whether Sublime Text's Vim is currently on COMMAND or INSERT mode.

Is it possible to write a very simple plugin/package to Sublime Text just to have it display the words "COMMAND mode" or "INSERT mode" on the title bar when Vim is enabled? This could make AutoHotKey aware of the current mode and turn of the hostrings.

1 Answer 1

1

I don't know how to implement this in Sublime, but a few thoughts/observations

  1. The status bar is not a separate control, it appears to be part of the general PX_WINDOW_CLASS for the entire window, so that's no good for reading the text value directly (straight from AutoHotkey).
  2. You could use polling in AutoHotkey combined with OCR to read the status bar (using GDIP or something similar). This would probably work with some minimal amount of processing but would always require a delay between the time it changes mode vs. the time the mode change is detected. Not really ideal. Getting the OCR to work can be a little tricky also (but is doable).
  3. You could write your own sublime package to read the status bar text, and process what to do based on that kind of polling. For example, see here: https://forum.sublimetext.com/t/copy-text-from-the-status-bar/20714/8
  4. It may be worth considering other types of interaction (besides using AutoHotkey #IfWinActive and setting the window title. In other words, setting the window title might be difficult, but it might not be as difficult to run a separate exe or ahk script directly from sublime. Say you were able to poll the correct lookup key for the status text to determine if it is INSERT or COMMAND, and then execute a shell command (exe or ahk script)--this could feed your hotstring script to enable/disable various key combos. There is a sublime package that does something like this to set the window transparency (runs an external utility to modify the window), so maybe that's something you could look into.
  5. This link shows how you can detect mode changes. Perhaps you could use this in combination with the last item. https://stackoverflow.com/questions/20514563/change-appearance-in-sublime-text-3-when-switching-mode-in-vintage#39805889
  6. You don't mention in your post how the transition occurs between Insert mode and Command mode--I installed Sublime and looked all over the place and can't figure it out myself, but one possibility to consider is whether or not it's a key combination. If so, you could detect the keystrokes used to switch between modes and track which mode is in use separately in AutoHotkey. This type of setup can be less than desirable since it's an inferred state that's being tracked (and it also has to be initialized once to work properly). As an initial implementation however it might be quite easy to get something that works most of the time, until you get something more robust running in Sublime.
1
  • Thanks for your input JJohnston2! I was about to post a comment to your answer here, but the lenght is too limited, so I posted here: Pastebin comment
    – Da Rossa
    Commented Feb 25, 2017 at 6:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .