aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h1
-rw-r--r--vis.c19
2 files changed, 20 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h
index c88d54f..4402cd0 100644
--- a/config.def.h
+++ b/config.def.h
@@ -362,6 +362,7 @@ static KeyBinding vis_mode_normal[] = {
{ { NONE(ESC) }, cursors_clear, { } },
{ { CONTROL('K') }, cursors_new, { .i = -1 } },
{ { CONTROL('J') }, cursors_new, { .i = +1 } },
+ { { CONTROL('A') }, cursors_align, { } },
{ { CONTROL('w'), NONE('n') }, cmd, { .s = "open" } },
{ { CONTROL('w'), NONE('c') }, cmd, { .s = "q" } },
{ { CONTROL('w'), NONE('s') }, cmd, { .s = "split" } },
diff --git a/vis.c b/vis.c
index 9a98d65..0f4cc20 100644
--- a/vis.c
+++ b/vis.c
@@ -322,6 +322,8 @@ static void totill_reverse(const Arg *arg);
static void replace(const Arg *arg);
/* create a new cursor on the previous (arg->i < 0) or next (arg->i > 0) line */
static void cursors_new(const Arg *arg);
+/* try to align all cursors on the same column */
+static void cursors_align(const Arg *arg);
/* remove all but the primary cursor and their selections */
static void cursors_clear(const Arg *arg);
/* adjust action.count by arg->i */
@@ -842,6 +844,23 @@ static void cursors_new(const Arg *arg) {
view_cursors_to(cursor, pos);
}
+static void cursors_align(const Arg *arg) {
+ View *view = vis->win->view;
+ Text *txt = vis->win->file->text;
+ int mincol = INT_MAX;
+ for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) {
+ size_t pos = view_cursors_pos(c);
+ int col = text_line_char_get(txt, pos);
+ if (col < mincol)
+ mincol = col;
+ }
+ for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) {
+ size_t pos = view_cursors_pos(c);
+ size_t col = text_line_char_set(txt, pos, mincol);
+ view_cursors_to(c, col);
+ }
+}
+
static void cursors_clear(const Arg *arg) {
View *view = vis->win->view;
if (view_cursors_count(view) > 1)