0

Where in the rcmdnk/vim_ahk AutoHotkey package (which file) should I try to remap the caps lock to esc?

I know little about AutoHotkey, and for the longest time my entire AHK script consisted of:

#IfWinActive ahk_class Vim
  CAPSLOCK::ESC
return

Now that I'm using vim_ahk to implement Vim-like editing in applications like Word and OneNote, I have no idea where (and how) I should add the caps lock mapping to limit the effect to only the intended applications.

A user of vim_ahk on this forum said using AHK to remap the caps lock caused him problems (he didn't say in general or just with the package). Since the remapping has been working for me in Vim, I'd like to use it with vim_ahk, too, if possible.

Update Sorry if the question as posted wasn't clear. Vim (the editor) uses Esc for escaping from the insert mode (a Vim concept) but I have been able to use caps lock instead thanks to AutoHotkey.

But such a mode doesn't exist in most other programs, so vim_ahk was created to implement it in some of them (as enumerated in the customizable variable VimGroup). Like Vim, vim_ahk uses Esc for escaping from its pseudo-insert mode, but because this mode is entirely a creation of vim_ahk's AHK script, the naive, global CAPSLOCK::ESC doesn't work. For what works, see my answer, which got from vim_ahk's creator.

1
  • @Destroy666 I'm afraid not. I didn't try it until just now because I didn't expect it to work, and it didn't.
    – bongbang
    Commented Apr 15 at 9:34

3 Answers 3

0

There is no problem running multiple AHK scripts in parallel. Except for conflicts, they will all work correctly.

Therefore, you do not need to modify vim_ahk in order to make your script and vim_ahk work together.

Small notes :

  • As your script disables CapsLock, you could add at its beginning the line:

    SetCapsLockState, AlwaysOff
    
  • The return command in your script is superfluous.

2
  • Thanks, but perhaps I didn't make myself clear. My original script affects only Vim, while vim_ahk affects other applications (defined in the VimGroup valuable). I want to apply the caps lock remapping to vim_ahk's VimGroup. That the two scripts (without modification) can run simultaneously doesn't give me what I want, as they are not working together. Each is limited to its specified application(s).
    – bongbang
    Commented Apr 8 at 13:31
  • Could you add an example of the contents of VimGroup to your post? Because that part is not very clear.
    – harrymc
    Commented Apr 8 at 16:21
0

Since the code is open sourse on GitHub, which you linked, you can trace how the VimGroup variable is verified.

There's IsVimGroup function defined in this file which is a member of VimAhk class.

Now with that knowledge you can use Vim.IsVimGroup() in your vim.ahk for any sort of code. E.g. you could use #If directive to verify it:

#If Vim.IsVimGroup()
CAPSLOCK::ESC
2
  • That didn't work. And I didn't expect it to work because even remapping CapsLock::ESC globally in a separate script as @harrymc suggested didn't work. It works for everything else, including for escaping from the search box in OneNote (which is in the VimGroup), but it didn't work for escaping from vim-ahk's pseudo-insert mode. That functionality, I believe, is handled by the part of vim-ahk's code, which is unaffected by the remapping.
    – bongbang
    Commented Apr 15 at 9:33
  • I'm not quite sure I understand what you're trying to do now. Could you make the question more detailed and e.g. answer harrymc's question or describe what functionality you're going for exactly? E.g. "X should happen in these apps, but Y in other apps"
    – Destroy666
    Commented Apr 15 at 10:45
0

This solution from vim_ahk's creator works for me. Just add this code after loading vim_ahk.

#If Vim.IsVimGroup()
CapsLock::Vim.State.HandleEsc()
#If

You must log in to answer this question.

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