aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-05 16:00:37 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-05 16:14:01 +0200
commit9e64bf166ac329103a98baafce10e42242898373 (patch)
tree1e2eb2dd87c0908fe69705d1df719954caf7173f
parent087702ad546b42be13ccd5e3e0cd69b104aa4e3f (diff)
downloadvis-9e64bf166ac329103a98baafce10e42242898373.tar.gz
vis-9e64bf166ac329103a98baafce10e42242898373.tar.xz
vis: let <C-l> remove all but the count cursor column
-rw-r--r--config.def.h3
-rw-r--r--main.c33
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) },
diff --git a/main.c b/main.c
index 35c1bc4..0b45816 100644
--- a/main.c
+++ b/main.c
@@ -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)) {