Skip to content

Commit

Permalink
add ESC/Ctrl-[ enable options, separate ESC/Ctrl-[ long press options
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmdnk committed Oct 18, 2020
1 parent f3fe527 commit a55cdff
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 31 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ All of these can be changed from setting menu, too.

|Option|Description|Default|
|:-----|:----------|:------|
|VimEscNormal|If 1, pushing ESC sets normal mode, while long press ESC sends ESC.|1|
|VimLongEscNormal|If 1, single press and long press of ESC behaviors are swapped.|0|
|VimCtrlBracketNormal|If 1, pushing Ctrl-[ sets normal mode, while long press Ctrl-[ sends Ctrl-[.|1|
|VimLongCtrlBracketNormal|If 1, single press and long press of Ctrl-[ behaviors are swapped.|0|
|VimRestoreIME|If 1, IME status is restored at entering insert mode.|1|
|VimJJ|If 1, `jj` changes mode to Normal from Insert.|0|
|VimLongEscNormal|If 1, pushing escape/Ctrl-[ sends escape to the underlying application, while holding escape sets normal mode.|0|
|VimTwoLetterEsc|A list of character pairs to press together during insert mode to get to normal mode. For example, a value of `jf` means pressing `j` and `f` at the same time will enter normal mode.|""|
|VimDisableUnused|Disable level of unused keys in normal mode (see below for details).|3|
|VimSetTitleMatchMode|SetTitleMatchMode: 1: Start with, 2: Contain, 3: Exact match|2|
Expand Down Expand Up @@ -212,10 +215,11 @@ ESC/Ctrl-[ switch off IME if IME is on.
ESC acts as ESC when IME is on and converting instructions.
Ctrl-[ switches off IME and enters Normal Mode even if IME is on.

Long press ESC/Ctrl-[ will send these original keys, if `VimLongEscNormal` is not enabled (0).
If `VimLongEscNormal` is enabled,
short press these keys will send these original
and long press these keys will change the mode to the normal mode.
Long press ESC (Ctrl-[) will send these original keys, if `VimLongEscNormal` (`VimLongCtrlBracketNormal` is not enabled (0).

If `VimLongEscNormal` (`VimLongCtrlBracketNormal`) is enabled,
single press will send original keys
and long press will change the mode to the normal mode.

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

Expand Down
39 changes: 24 additions & 15 deletions lib/vim_ahk.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

class VimAhk{
__About(){
this.About.Version := "v0.8.1"
this.About.Date := "17/Oct/2020"
this.About.Version := "v0.8.2"
this.About.Date := "18/Oct/2020"
this.About.Author := "rcmdnk"
this.About.Description := "Vim emulation with AutoHotkey, everywhere in Windows."
this.About.Homepage := "https://github.com/rcmdnk/vim_ahk"
Expand Down Expand Up @@ -70,38 +70,47 @@ class VimAhk{

; Configuration values for Read/Write ini
this.Conf := {}
this.AddToConf("VimEscNormal", 1, 1
, "ESC to enter Normal mode"
, "Use ESC to enter Normal mode, long press ESC to send ESC.")
this.AddToConf("VimLongEscNormal", 0, 0
, "Long press ESC to enter Normal mode"
, "Swap single press and long press behaviors for ESC.`nEnable ESC to enter Normal mode first.")
this.AddToConf("VimCtrlBracketNormal", 1, 1
, "Ctrl-[ to enter Normal mode"
, "Use Ctrl-[ to enter Normal mode, long press Ctrl-[ to send Ctrl-[.")
this.AddToConf("VimLongCtrlBracketNormal", 0, 0
, "Long press Ctrl-[ to enter Normal mode:"
, "Swap single press and long press behaviors for Ctrl-[.`nEnable Ctrl-[ to enter Normal mode first.")
this.AddToConf("VimRestoreIME", 1, 1
, "Restore IME status at entering insert mode:"
, "Restore IME status at entering insert mode"
, "Restore IME status at entering insert mode.")
this.AddToConf("VimLongEscNormal", 0, 0
, "Long press esc to enter normal mode:"
, "Hold esc to enter normal, allowing single press to send esc to window")
this.AddToConf("VimJJ", 0, 0
, "JJ enters Normal mode:"
, "Assign JJ enters Normal mode.")
, "JJ to enter Normal mode"
, "Use JJ to enter Normal mode.")
this.AddToConf("VimTwoLetter", "", ""
, "Two-letter to enter Normal mode:"
, "Two-letter to enter Normal mode"
, "When these two letters are pressed together in insert mode, enters normal mode.`n`nSet one per line, exactly two letters per line.`nThe two letters must be different.")
this.AddToConf("VimDisableUnused", 1, 1
, "Disable unused keys in Normal mode:"
, "Disable unused keys in Normal mode"
, "1: Do not disable unused keys`n2: Disable alphabets (+shift) and symbols`n3: Disable all including keys with modifiers (e.g. Ctrl+Z)")
this.AddToConf("VimSetTitleMatchMode", "2", "2"
, "SetTitleMatchMode:"
, "SetTitleMatchMode"
, "[Mode] 1: Start with, 2: Contain, 3: Exact match.`n[Fast/Slow] Fast: Text is not detected for such edit control, Slow: Works for all windows, but slow.")
this.AddToConf("VimSetTitleMatchModeFS", "Fast", "Fast"
, "SetTitleMatchMode"
, "[Mode]1: Start with, 2: Contain, 3: Exact match.`n[Fast/Slow]: Fast: Text is not detected for such edit control, Slow: Works for all windows, but slow.")
this.AddToConf("VimIconCheckInterval", 1000, 1000
, "Icon check interval (ms):"
, "Icon check interval (ms)"
, "Interval to check vim_ahk status (ms) and change tray icon. If it is set to 0, the original AHK icon is set.")
this.AddToConf("VimVerbose", 1, 1
, "Verbose level:"
, "Verbose level"
, "1: Nothing `n2: Minimum tooltip of status`n3: More info in tooltip`n4: Debug mode with a message box, which doesn't disappear automatically")
this.AddToConf("VimGroup", DefaultGroup, DefaultGroup
, "Application:"
, "Application"
, "Set one application per line.`n`nIt can be any of Window Title, Class or Process.`nYou can check these values by Window Spy (in the right click menu of tray icon).")

this.CheckBoxes := ["VimRestoreIME", "VimJJ", "VimLongEscNormal"]
this.CheckBoxes := ["VimEscNormal", "VimLongEscNormal", "VimCtrlBracketNormal", "VimLongCtrlBracketNormal", "VimRestoreIME", "VimJJ"]

; Other ToolTip Information
this.Info := {}
Expand Down
15 changes: 10 additions & 5 deletions lib/vim_setting.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}

MakeGui(){
global VimRestoreIME, VimJJ, VimLongEscNormal
global VimRestoreIME, VimJJ, VimEscNormal, VimLongEscNormal, VimCtrlBracketNormal, VimLongCtrlBracketNormal
global VimDisableUnused, VimSetTitleMatchMode, VimSetTitleMatchModeFS, VimIconCheckInterval, VimVerbose, VimGroup, VimGroupList, VimTwoLetterList
global VimDisableUnusedText, VimSetTitleMatchModeText, VimIconCheckIntervalText, VimIconCheckIntervalEdit, VimVerboseText, VimGroupText, VimHomepage, VimSettingOK, VimSettingReset, VimSettingCancel, VimTwoLetterText
this.VimVal2V()
Expand All @@ -18,7 +18,12 @@
}else{
y := "Y+10"
}
Gui, % this.Hwnd ":Add", Checkbox, % "+HwndHwnd" k " XM+10 " y " v" k, % this.Vim.Conf[k]["description"]
if(inStr(k, "Long")) {
x := "30"
}else{
x := "10"
}
Gui, % this.Hwnd ":Add", Checkbox, % "+HwndHwnd" k " XM+" x " " y " v" k, % this.Vim.Conf[k]["description"]
hwnd := "Hwnd" k
this.HwndAll.Push(%hwnd%)
created := 1
Expand Down Expand Up @@ -86,7 +91,7 @@
}

UpdateGuiValue(){
global VimRestoreIME, VimJJ, VimLongEscNormal
global VimRestoreIME, VimJJ, VimEscNormal, VimLongEscNormal, VimCtrlBracketNormal, VimLongCtrlBracketNormal
global VimDisableUnused, VimSetTitleMatchMode, VimSetTitleMatchModeFS, VimIconCheckInterval, VimVerbose, VimGroup, VimGroupList, VimTwoLetter, VimTwoLetterList
for i, k in this.Vim.Checkboxes {
GuiControl, % this.Hwnd ":", % k, % %k%
Expand Down Expand Up @@ -130,7 +135,7 @@
}

VimV2Conf(){
global VimRestoreIME, VimJJ, VimLongEscNormal
global VimRestoreIME, VimJJ, VimEscNormal, VimLongEscNormal, VimCtrlBracketNormal, VimLongCtrlBracketNormal
global VimDisableUnused, VimSetTitleMatchMode, VimSetTitleMatchModeFS, VimIconCheckInterval, VimVerbose, VimGroup, VimGroupList, VimTwoLetter, VimTwoLetterList
VimGroup := this.VimParseList(VimGroupList)
VimTwoLetter := this.VimParseList(VimTwoLetterList)
Expand All @@ -157,7 +162,7 @@
}

VimConf2V(vd){
global VimRestoreIME, VimJJ, VimLongEscNormal
global VimRestoreIME, VimJJ, VimEscNormal, VimLongEscNormal, VimCtrlBracketNormal, VimLongCtrlBracketNormal
global VimDisableUnused, VimSetTitleMatchMode, VimSetTitleMatchModeFS, VimIconCheckInterval, VimVerbose, VimGroup, VimGroupList, VimTwoLetterList
StringReplace, VimGroupList, % this.Vim.Conf["VimGroup"][vd], % this.Vim.GroupDel, `n, All
StringReplace, VimTwoLetterList, % this.Vim.Conf["VimTwoLetter"][vd], % this.Vim.GroupDel, `n, All
Expand Down
20 changes: 14 additions & 6 deletions lib/vim_state.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,22 @@
}

HandleEsc(){
global Vim, VimEscNormal, VimLongEscNormal
if (!VimNormal) {
Send, {Esc}
Return
}
; The keywait waits for esc to be released. If it doesn't detect a release
; within the time limit, sets errorlevel to 1.
; within the time limit, sets ErrorLevel to 1.
KeyWait, Esc, T0.5
LongPress := ErrorLevel
global Vim, VimLongEscNormal
both := VimLongEscNormal && LongPress
neither := !(VimLongEscNormal || LongPress)
SetNormal := both or neither
if (SetNormal) {
Vim.State.SetNormal()
} else {
Send,{Esc}
Send, {Esc}
}
if (LongPress){
; Have to ensure the key has been released, otherwise this will get
Expand All @@ -104,11 +108,15 @@
}

HandleCtrlBracket(){
global Vim, VimCtrlBracketNormal, VimLongCtrlBracketNormal
if (!VimCtrlBracketNormal) {
Send, ^[
Return
}
KeyWait, [, T0.5
LongPress := ErrorLevel
global Vim, VimLongEscNormal
both := VimLongEscNormal && LongPress
neither := !(VimLongEscNormal || LongPress)
both := VimLongCtrlBracketNormal && LongPress
neither := !(VimLongCtrlBracketNormal || LongPress)
SetNormal := both or neither
if (SetNormal) {
Vim.State.SetNormal()
Expand Down

0 comments on commit a55cdff

Please sign in to comment.