diff options
| -rw-r--r-- | config.def.h | 3 | ||||
| -rw-r--r-- | main.c | 33 |
2 files changed, 35 insertions, 1 deletions
diff --git a/config.def.h b/config.def.h index a72af52..26ff499 100644 --- a/config.def.h +++ b/config.def.h @@ -231,7 +231,7 @@ static const KeyBinding bindings_normal[] = { { "<C-r>", ACTION(REDO) }, { "g+", ACTION(LATER) }, { "g-", ACTION(EARLIER) }, - { "<C-l>", ACTION(REDRAW) }, + { "<C-l>", ACTION(CURSORS_REMOVE_COLUMN_EXCEPT) }, { ":", ACTION(PROMPT_SHOW) }, { "ZZ", ALIAS(":wq<Enter>") }, { "ZQ", ALIAS(":q!<Enter>") }, @@ -266,6 +266,7 @@ static const KeyBinding bindings_visual[] = { { "<Delete>", ALIAS("<Backspace>") }, { "<Escape>", ACTION(MODE_NORMAL) }, { "<C-c>", ACTION(CURSORS_REMOVE_COLUMN) }, + { "<C-l>", ACTION(CURSORS_REMOVE_COLUMN_EXCEPT) }, { "v", ALIAS("<Escape>") }, { "V", ACTION(MODE_VISUAL_LINE) }, { ":", ACTION(PROMPT_SHOW) }, @@ -52,6 +52,8 @@ static const char *cursors_clear(Vis*, const char *keys, const Arg *arg); static const char *cursors_remove(Vis*, const char *keys, const Arg *arg); /* remove count (or arg->i)-th cursor column */ static const char *cursors_remove_column(Vis*, const char *keys, const Arg *arg); +/* remove all but the count (or arg->i)-th cursor column */ +static const char *cursors_remove_column_except(Vis*, const char *keys, const Arg *arg); /* move to the previous (arg->i < 0) or next (arg->i > 0) cursor */ static const char *cursors_navigate(Vis*, const char *keys, const Arg *arg); /* select the word the cursor is currently over */ @@ -257,6 +259,7 @@ enum { VIS_ACTION_CURSORS_REMOVE_ALL, VIS_ACTION_CURSORS_REMOVE_LAST, VIS_ACTION_CURSORS_REMOVE_COLUMN, + VIS_ACTION_CURSORS_REMOVE_COLUMN_EXCEPT, VIS_ACTION_CURSORS_PREV, VIS_ACTION_CURSORS_NEXT, VIS_ACTION_SELECTIONS_ROTATE_LEFT, @@ -962,6 +965,11 @@ static const KeyAction vis_action[] = { "Remove count cursor column", cursors_remove_column, { .i = 1 } }, + [VIS_ACTION_CURSORS_REMOVE_COLUMN_EXCEPT] = { + "cursors-remove-column-except", + "Remove all but the count cursor column", + cursors_remove_column_except, { .i = 1 } + }, [VIS_ACTION_CURSORS_PREV] = { "cursors-prev", "Move to the previous cursor", @@ -1427,6 +1435,31 @@ static const char *cursors_remove_column(Vis *vis, const char *keys, const Arg * return keys; } +static const char *cursors_remove_column_except(Vis *vis, const char *keys, const Arg *arg) { + View *view = vis_view(vis); + int max = view_cursors_column_count(view); + int column = vis_count_get_default(vis, arg->i) - 1; + if (column >= max) + column = max - 1; + if (!view_cursors_multiple(view)) { + vis_redraw(vis); + return keys; + } + + Cursor *cur = view_cursors(view); + Cursor *col = view_cursors_column(view, column); + for (Cursor *next; cur; cur = next) { + next = view_cursors_next(cur); + if (cur == col) + col = view_cursors_column_next(col, column); + else + view_cursors_dispose(cur); + } + + vis_count_set(vis, VIS_COUNT_UNKNOWN); + return keys; +} + static const char *cursors_navigate(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); if (!view_cursors_multiple(view)) { |
