Skip to content

Commit

Permalink
Merge pull request #101 from rcmdnk/ahk_v2
Browse files Browse the repository at this point in the history
Ahk v2
  • Loading branch information
rcmdnk authored Oct 1, 2024
2 parents 08b735f + 3cae41c commit 52a6edc
Show file tree
Hide file tree
Showing 33 changed files with 888 additions and 843 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
uses: actions/checkout@v4
- name: Install AutoHotkey with Chocolatey
uses: crazy-max/ghaction-chocolatey@v3
with:
Expand Down
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ This is vim emulation for Windows.
If you are interested in the same settings for Mac,
try Vim emulation for [Karabiner - Software for macOS](https://pqrs.org/osx/karabiner/): [Karabiner-Elements complex_modifications rules by rcmdnk](https://rcmdnk.com/KE-complex_modifications/).

## AutoHotkey v1 or v2

This script is for AutoHotkey v2.

If you are using AutoHotkey v1, please use release [v0.13.1](https://github.com/rcmdnk/vim_ahk/tree/v0.13.1).

## Installation

### Scripts
Expand Down Expand Up @@ -82,13 +88,14 @@ Example line:

Multiple applications can be written by a comma-separated.

Note: This will overwrite the default applications. If you want to **add**
these applications to the default applications, add following applications
after your applications:

ahk_exe notepad.exe,ahk_exe explorer.exe,ahk_exe wordpad.exe,ahk_exe TeraPad.exe,作成,Write:,ahk_exe POWERPNT.exe,ahk_exe WINWORD.exe,ahk_exe Evernote.exe,ahk_exe Code.exe,ahk_exe onenote.exe,OneNote,ahk_exe texworks.exe,ahk_exe texstudio.exe

Or you can use GUI option setting menu described below.
> [!NOTE]
> This will overwrite the default applications. If you want to **add**
> these applications to the default applications, add following applications
> after your applications:
>
> ahk_exe notepad.exe,ahk_exe explorer.exe,ahk_exe wordpad.exe,ahk_exe TeraPad.exe,作成,Write:,ahk_exe POWERPNT.exe,ahk_exe WINWORD.exe,ahk_exe Evernote.exe,ahk_exe Code.exe,ahk_exe onenote.exe,OneNote,ahk_exe texworks.exe,ahk_exe texstudio.exe
>
> Or you can use GUI option setting menu described below.
The default setting of `VimSetTitleMatchMode` is 2,
which makes matching methods as `Contain`.
Expand All @@ -97,7 +104,7 @@ If you set `OneNote`, all windows with a title containing `OneNote`
(e.g. `XXX's OneNote`) will be included.
If you set `VimSetTitleMatchMode` as 3, only the exact title of `OneNote` will be included.

Note: It may not work on OneNote. OneNote may have a window name like
It may not work on OneNote. OneNote may have a window name like
**User's Notebook - OneNote**, instead of **OneNote**.

In that case, you need to check OneNote's window title with Window spy.
Expand Down Expand Up @@ -156,6 +163,12 @@ in the auto execute section like:
If you want to change them directly in the vim.ahk script,
add these variable before `Vim := new VimAhk()`.

> [!NOTE]
> These Vim variables will overwrite the default values and initial values.
> After checking these variables, the configuration file is read.
> If you have already run vim_ahk, the configuration file was created and all the settings were saved.
> To reflect the new settings, try `Reset` in the GUI option setting window.
> [!NOTE]
> VimIconCheckInterval example
>
Expand Down Expand Up @@ -248,6 +261,10 @@ and a long press will change the mode to the normal mode.

If using a custom two-letter hotkey to enter the normal mode, the two letters must be different.

> [!WARNING]
> A character can be used only for one two-letter hotkey. If you specify `ab` and `bc`, `ba` (push `b` first and then `a`) does not work. If you push `a` first, then `ab` will work, though.

## Available commands in the normal mode

### Mode Change
Expand Down Expand Up @@ -275,7 +292,8 @@ If using a custom two-letter hotkey to enter the normal mode, the two letters mu
|Space| Right.|
|Enter| Move to the beginning of the next line.|

Note: Enter works only for editor applications (for other than Explorer, Q-dir, it works as Enter even in the normal mode).
> [!NOTE]
> Enter works only for editor applications (for other than Explorer, Q-dir, it works as Enter even in the normal mode).
In addition, `Repeat` is also available for some commands.

Expand Down
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
SET AHKPath=C:\Program Files\AutoHotkey
SET AHKPath=C:\Program Files\AutoHotkey\v2
REM Takes a simple optional command parameter, /t, which starts testing before build.
SET Param1=%1

Expand Down
41 changes: 23 additions & 18 deletions lib/bind/vim_command.ahk
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal"))
#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal"))
:::Vim.State.SetMode("Command") ;(:)
`;::Vim.State.SetMode("Command") ;(;)
#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command"))
#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command"))
w::Vim.State.SetMode("Command_w")
q::Vim.State.SetMode("Command_q")
h::
Send, {F1}
{
SendInput("{F1}")
Vim.State.SetMode("Vim_Normal")
Return
}

#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_w"))
Return::
Send, ^s
#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_w"))
Enter::
{
SendInput("^s")
Vim.State.SetMode("Vim_Normal")
Return
}

q::
Send, ^s
Send, !{F4}
{
SendInput("^s")
SendInput("!{F4}")
Vim.State.SetMode("Insert")
Return
}

Space::
Send, !fa
{
SendInput("!fa")
Vim.State.SetMode("Insert")
Return
}

#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_q"))
Return::
Send, !{F4}
#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_q"))
Enter::
{
SendInput("!{F4}")
Vim.State.SetMode("Insert")
Return
}

#If
#HotIf
15 changes: 8 additions & 7 deletions lib/bind/vim_disable.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("ydc") or Vim.State.StrIsInCurrentVimMode("Command") or (Vim.State.IsCurrentVimMode("Z")))
#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("ydc") or Vim.State.StrIsInCurrentVimMode("Command") or (Vim.State.IsCurrentVimMode("Z")))
*a::
*b::
*c::
Expand Down Expand Up @@ -66,10 +66,11 @@ _::
.::
>::
Space::
{
Vim.State.SetMode("Vim_Normal")
Return
}

#If Vim.IsVimGroup() and Vim.State.StrIsInCurrentVimMode("Vim_") and (Vim.Conf["VimDisableUnused"]["val"] > 1)
#HotIf Vim.IsVimGroup() and Vim.State.StrIsInCurrentVimMode("Vim_") and (Vim.Conf["VimDisableUnused"]["val"] > 1)
a::
b::
c::
Expand Down Expand Up @@ -163,9 +164,9 @@ _::
.::
>::
Space::
Return
{}

#If Vim.IsVimGroup() and Vim.State.StrIsInCurrentVimMode("Vim_") and (Vim.Conf["VimDisableUnused"]["val"] > 2)
#HotIf Vim.IsVimGroup() and Vim.State.StrIsInCurrentVimMode("Vim_") and (Vim.Conf["VimDisableUnused"]["val"] > 2)
*a::
*b::
*c::
Expand All @@ -192,6 +193,6 @@ Return
*x::
*y::
*z::
Return
{}

#If
#HotIf
31 changes: 18 additions & 13 deletions lib/bind/vim_enter_insert.ahk
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
#If Vim.IsVimGroup() && (Vim.State.IsCurrentVimMode("Vim_Normal"))
#HotIf Vim.IsVimGroup() && (Vim.State.IsCurrentVimMode("Vim_Normal"))
i::Vim.State.SetMode("Insert")

+i::
Send, {Home}
{
SendInput("{Home}")
Vim.State.SetMode("Insert")
Return
}

a::
{
if(! Vim.CheckChr("`n")){
Send, {Right}
SendInput("{Right}")
}
Vim.State.SetMode("Insert")
Return
}

+a::
Send, {End}
{
SendInput("{End}")
Vim.State.SetMode("Insert")
Return
}

o::
Send,{End}{Enter}
{
SendInput("{End}{Enter}")
Vim.State.SetMode("Insert")
Return
}

+o::
Send, {Home}{Enter}{Left}
{
SendInput("{Home}{Enter}{Left}")
Vim.State.SetMode("Insert")
Return
}

; Q-dir
#If Vim.IsVimGroup() and WinActive("ahk_group VimQdir") and (Vim.State.Mode == "Vim_Normal")
#HotIf Vim.IsVimGroup() and WinActive("ahk_group VimQdir") and (Vim.State.Mode == "Vim_Normal")
; Enter insert mode to quickly locate the file/folder by using the first letter
/::Vim.State.SetMode("Insert")
; Enter insert mode at rename
~F2::Vim.State.SetMode("Insert")

#If
#HotIf
17 changes: 10 additions & 7 deletions lib/bind/vim_enter_normal.ahk
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#If Vim.IsVimGroup()
#HotIf Vim.IsVimGroup()
Esc::Vim.State.HandleEsc()
^[::Vim.State.HandleCtrlBracket()

#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Insert")) and (Vim.Conf["VimJJ"]["val"] == 1)
#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Insert")) and (Vim.Conf["VimJJ"]["val"] == 1)
~j up:: ; jj: go to Normal mode.
Input, jout, I T0.1 V L1, j
if(ErrorLevel == "EndKey:J"){
SendInput, {BackSpace 2}
{
jout := InputHook("I T0.1 V L1", "j")
jout.Start()
EndReason := jout.Wait()
if(EndReason == "EndKey"){
SendInput("{BackSpace 2}")
Vim.State.SetNormal()
}
Return
}

#If
#HotIf
17 changes: 9 additions & 8 deletions lib/bind/vim_move.ahk
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
; Inner mode
#If Vim.IsVimGroup() and ((Vim.State.StrIsInCurrentVimMode("Vim_ydc")) or (Vim.State.IsCurrentVimMode("Vim_VisualChar")))
#HotIf Vim.IsVimGroup() and ((Vim.State.StrIsInCurrentVimMode("Vim_ydc")) or (Vim.State.IsCurrentVimMode("Vim_VisualChar")))
i::Vim.State.SetInner()

#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Inner"))
#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Inner"))
w::Vim.Move.Inner("w")
+w::Vim.Move.Inner("w")

; gg
#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (not Vim.State.g)
#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (not Vim.State.g)
g::Vim.State.SetMode("", 1)
#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (Vim.State.g)
#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (Vim.State.g)
g::Vim.Move.Move("g")

#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_"))
#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_"))
; 1 character
h::Vim.Move.Repeat("h")
j::Vim.Move.Repeat("j")
Expand Down Expand Up @@ -44,10 +44,11 @@ b::Vim.Move.Repeat("b")
+g::Vim.Move.Move("+g")
; Space
Space::Vim.Move.Repeat("l")
#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and not WinActive("ahk_group VimNonEditor")
#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and not WinActive("ahk_group VimNonEditor")
; Enter
Enter::
{
Vim.Move.Repeat("j")
Vim.Move.Move("^")
Return
#If
}
#HotIf
Loading

0 comments on commit 52a6edc

Please sign in to comment.