diff --git a/README.md b/README.md index 04617f81..df0490b6 100644 --- a/README.md +++ b/README.md @@ -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| @@ -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. diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 9e0b986f..4c35978a 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -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" @@ -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 := {} diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index d4d19cbd..a51fddab 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -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() @@ -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 @@ -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% @@ -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) @@ -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 diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 4abcf4bf..9520387a 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -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 @@ -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()