diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2020-04-28 15:27:31 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2020-04-28 15:29:58 +0200 |
| commit | b116d210f174ad7869fcfc901f964ff62112ac41 (patch) | |
| tree | 158fc912d492ba31c8b9e873e9ced63e1a1aef83 | |
| parent | d8ab659d7c91a0563108b82521a41eeaadce1249 (diff) | |
| download | vis-b116d210f174ad7869fcfc901f964ff62112ac41.tar.gz vis-b116d210f174ad7869fcfc901f964ff62112ac41.tar.xz | |
vis: make <Escape> reset count in normal mode
Fix #825
| -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 77476a8..9eaffb0 100644 --- a/config.def.h +++ b/config.def.h @@ -225,7 +225,7 @@ static const KeyBinding bindings_normal[] = { { "<C-y>", ACTION(WINDOW_SLIDE_DOWN) }, { "D", ALIAS("d$") }, { "<Delete>", ALIAS("x") }, - { "<Escape>", ACTION(SELECTIONS_REMOVE_ALL) }, + { "<Escape>", ACTION(MODE_NORMAL_ESCAPE) }, { "<F1>", ALIAS(":help<Enter>") }, { "ga", ACTION(UNICODE_INFO) }, { "g8", ACTION(UTF8_INFO) }, @@ -32,6 +32,8 @@ static const char *macro_record(Vis*, const char *keys, const Arg *arg); static const char *macro_replay(Vis*, const char *keys, const Arg *arg); /* temporarily suspend the editor and return to the shell, type 'fg' to get back */ 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); /* 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 */ @@ -200,6 +202,7 @@ enum { VIS_ACTION_WINDOW_HALFPAGE_UP, VIS_ACTION_WINDOW_HALFPAGE_DOWN, VIS_ACTION_MODE_NORMAL, + VIS_ACTION_MODE_NORMAL_ESCAPE, VIS_ACTION_MODE_VISUAL, VIS_ACTION_MODE_VISUAL_LINE, VIS_ACTION_MODE_INSERT, @@ -600,6 +603,11 @@ static const KeyAction vis_action[] = { VIS_HELP("Enter normal mode") switchmode, { .i = VIS_MODE_NORMAL } }, + [VIS_ACTION_MODE_NORMAL_ESCAPE] = { + "vis-mode-normal-escape", + VIS_HELP("Reset count or remove all non-primary selections") + normalmode_escape, + }, [VIS_ACTION_MODE_VISUAL] = { "vis-mode-visual-charwise", VIS_HELP("Enter characterwise visual mode") @@ -2228,6 +2236,14 @@ static const char *join(Vis *vis, const char *keys, const Arg *arg) { return keys; } +static const char *normalmode_escape(Vis *vis, const char *keys, const Arg *arg) { + if (vis_count_get(vis) == VIS_COUNT_UNKNOWN) + selections_clear(vis, keys, arg); + 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; |
