diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2020-04-28 15:35:06 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2020-04-28 15:35:06 +0200 |
| commit | a106a42bf1ddf2d88ccf4e470bb134e6a9fa8334 (patch) | |
| tree | e6d3a91abdeb045724258ffa6b1d20fac8aa41f3 | |
| parent | b116d210f174ad7869fcfc901f964ff62112ac41 (diff) | |
| download | vis-a106a42bf1ddf2d88ccf4e470bb134e6a9fa8334.tar.gz vis-a106a42bf1ddf2d88ccf4e470bb134e6a9fa8334.tar.xz | |
vis: make <Escape> reset count in visual modes
| -rw-r--r-- | config.def.h | 2 | ||||
| -rw-r--r-- | main.c | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/config.def.h b/config.def.h index 9eaffb0..cfa87b4 100644 --- a/config.def.h +++ b/config.def.h @@ -284,7 +284,7 @@ static const KeyBinding bindings_visual[] = { { "<C-u>", ACTION(SELECTIONS_PREV) }, { "<C-x>", ACTION(SELECTIONS_NEW_MATCH_SKIP) }, { "<Delete>", ALIAS("<Backspace>") }, - { "<Escape>", ACTION(MODE_NORMAL) }, + { "<Escape>", ACTION(MODE_VISUAL_ESCAPE) }, { "I", ACTION(SELECTIONS_NEW_LINES_BEGIN) }, { "J", ACTION(JOIN_LINES) }, { "gJ", ACTION(JOIN_LINES_TRIM) }, @@ -34,6 +34,8 @@ static const char *macro_replay(Vis*, const char *keys, const Arg *arg); static const char *suspend(Vis*, const char *keys, const Arg *arg); /* reset count if set, otherwise remove all but the primary selection */ static const char *normalmode_escape(Vis*, const char *keys, const Arg *arg); +/* reset count if set, otherwise switch to normal mode */ +static const char *visualmode_escape(Vis*, const char *keys, const Arg *arg); /* switch to mode indicated by arg->i */ static const char *switchmode(Vis*, const char *keys, const Arg *arg); /* switch to insert mode after performing movement indicated by arg->i */ @@ -204,6 +206,7 @@ enum { VIS_ACTION_MODE_NORMAL, VIS_ACTION_MODE_NORMAL_ESCAPE, VIS_ACTION_MODE_VISUAL, + VIS_ACTION_MODE_VISUAL_ESCAPE, VIS_ACTION_MODE_VISUAL_LINE, VIS_ACTION_MODE_INSERT, VIS_ACTION_MODE_REPLACE, @@ -613,6 +616,11 @@ static const KeyAction vis_action[] = { VIS_HELP("Enter characterwise visual mode") switchmode, { .i = VIS_MODE_VISUAL } }, + [VIS_ACTION_MODE_VISUAL_ESCAPE] = { + "vis-mode-visual-escape", + VIS_HELP("Reset count or switch to normal mode") + visualmode_escape, + }, [VIS_ACTION_MODE_VISUAL_LINE] = { "vis-mode-visual-linewise", VIS_HELP("Enter linewise visual mode") @@ -2244,6 +2252,14 @@ static const char *normalmode_escape(Vis *vis, const char *keys, const Arg *arg) return keys; } +static const char *visualmode_escape(Vis *vis, const char *keys, const Arg *arg) { + if (vis_count_get(vis) == VIS_COUNT_UNKNOWN) + vis_mode_switch(vis, VIS_MODE_NORMAL); + else + vis_count_set(vis, VIS_COUNT_UNKNOWN); + return keys; +} + static const char *switchmode(Vis *vis, const char *keys, const Arg *arg) { vis_mode_switch(vis, arg->i); return keys; |
