aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-04 20:31:58 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-04 20:31:58 +0200
commit4c316385d06858edcb9d107dde1996a25959164f (patch)
tree59c2e637aaf33dbe9beffc2b0e545fe649f44e77
parent36e663f30e0bcd225164780022d04dc84bd7da13 (diff)
downloadvis-4c316385d06858edcb9d107dde1996a25959164f.tar.gz
vis-4c316385d06858edcb9d107dde1996a25959164f.tar.xz
vis: let <C-c> remove the count cursor column
-rw-r--r--config.def.h4
-rw-r--r--main.c28
2 files changed, 30 insertions, 2 deletions
diff --git a/config.def.h b/config.def.h
index 0af24fd..a72af52 100644
--- a/config.def.h
+++ b/config.def.h
@@ -174,7 +174,7 @@ static const KeyBinding bindings_operator_options[] = {
static const KeyBinding bindings_normal[] = {
{ "<Escape>", ACTION(CURSORS_REMOVE_ALL) },
- { "<C-c>", ALIAS("<Escape>") },
+ { "<C-c>", ACTION(CURSORS_REMOVE_COLUMN) },
{ "<Delete>", ALIAS("x") },
{ "<C-k>", ACTION(CURSORS_NEW_LINE_ABOVE) },
{ "<M-C-k>", ACTION(CURSORS_NEW_LINE_ABOVE_FIRST) },
@@ -265,7 +265,7 @@ static const KeyBinding bindings_visual[] = {
{ "<C-h>", ALIAS("<Backspace>") },
{ "<Delete>", ALIAS("<Backspace>") },
{ "<Escape>", ACTION(MODE_NORMAL) },
- { "<C-c>", ALIAS("<Escape>") },
+ { "<C-c>", ACTION(CURSORS_REMOVE_COLUMN) },
{ "v", ALIAS("<Escape>") },
{ "V", ACTION(MODE_VISUAL_LINE) },
{ ":", ACTION(PROMPT_SHOW) },
diff --git a/main.c b/main.c
index 483c208..35c1bc4 100644
--- a/main.c
+++ b/main.c
@@ -50,6 +50,8 @@ static const char *cursors_align_indent(Vis*, const char *keys, const Arg *arg);
static const char *cursors_clear(Vis*, const char *keys, const Arg *arg);
/* remove the least recently added cursor */
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);
/* 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 */
@@ -254,6 +256,7 @@ enum {
VIS_ACTION_CURSORS_ALIGN_INDENT_RIGHT,
VIS_ACTION_CURSORS_REMOVE_ALL,
VIS_ACTION_CURSORS_REMOVE_LAST,
+ VIS_ACTION_CURSORS_REMOVE_COLUMN,
VIS_ACTION_CURSORS_PREV,
VIS_ACTION_CURSORS_NEXT,
VIS_ACTION_SELECTIONS_ROTATE_LEFT,
@@ -954,6 +957,11 @@ static const KeyAction vis_action[] = {
"Remove least recently created cursor",
cursors_remove,
},
+ [VIS_ACTION_CURSORS_REMOVE_COLUMN] = {
+ "cursors-remove-column",
+ "Remove count cursor column",
+ cursors_remove_column, { .i = 1 }
+ },
[VIS_ACTION_CURSORS_PREV] = {
"cursors-prev",
"Move to the previous cursor",
@@ -1399,6 +1407,26 @@ static const char *cursors_remove(Vis *vis, const char *keys, const Arg *arg) {
return keys;
}
+static const char *cursors_remove_column(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_mode_switch(vis, VIS_MODE_NORMAL);
+ return keys;
+ }
+
+ for (Cursor *c = view_cursors_column(view, column), *next; c; c = next) {
+ next = view_cursors_column_next(c, column);
+ view_cursors_dispose(c);
+ }
+
+ 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)) {