Add commands to centre the cursor in copy mode, from m-einfalt at gmx
authornicm <nicm>
Tue, 28 Oct 2025 16:36:52 +0000 (28 16:36 +0000)
committernicm <nicm>
Tue, 28 Oct 2025 16:36:52 +0000 (28 16:36 +0000)
dot de in GitHub issue 4662.

key-bindings.c
tmux.1
window-copy.c

index fb766a0..1fb8189 100644 (file)
@@ -493,6 +493,8 @@ key_bindings_init(void)
                "bind -Tcopy-mode C-b { send -X cursor-left }",
                "bind -Tcopy-mode C-g { send -X clear-selection }",
                "bind -Tcopy-mode C-k { send -X copy-pipe-end-of-line-and-cancel }",
+               "bind -Tcopy-mode C-l { send -X cursor-centre-vertical }",
+               "bind -Tcopy-mode M-l { send -X cursor-centre-horizontal }",
                "bind -Tcopy-mode C-n { send -X cursor-down }",
                "bind -Tcopy-mode C-p { send -X cursor-up }",
                "bind -Tcopy-mode C-r { command-prompt -T search -ip'(search up)' -I'#{pane_search_string}' { send -X search-backward-incremental -- '%%' } }",
diff --git a/tmux.1 b/tmux.1
index 0c3688d..c483499 100644 (file)
--- a/tmux.1
+++ b/tmux.1
@@ -1951,6 +1951,16 @@ Move the cursor right.
 .Xc
 Move the cursor up.
 .It Xo
+.Ic cursor-centre-vertical
+(emacs: C-l)
+.Xc
+Moves the cursor to the vertical centre of the pane.
+.It Xo
+.Ic cursor-centre-horizontal
+(emacs: M-l)
+.Xc
+Moves the cursor to the horizontal centre of the pane.
+.It Xo
 .Ic end-of-line
 (vi: $)
 (emacs: C-e)
index 09939d4..3b0f11d 100644 (file)
@@ -1498,6 +1498,28 @@ window_copy_cmd_cursor_up(struct window_copy_cmd_state *cs)
 }
 
 static enum window_copy_cmd_action
+window_copy_cmd_centre_vertical(struct window_copy_cmd_state *cs)
+{
+       struct window_mode_entry        *wme = cs->wme;
+       struct window_copy_mode_data    *data = wme->data;
+
+       window_copy_update_cursor(wme, data->cx,  wme->wp->sy / 2);
+       window_copy_update_selection(wme, 1, 0);
+       return (WINDOW_COPY_CMD_REDRAW);
+}
+
+static enum window_copy_cmd_action
+window_copy_cmd_centre_horizontal(struct window_copy_cmd_state *cs)
+{
+       struct window_mode_entry        *wme = cs->wme;
+       struct window_copy_mode_data    *data = wme->data;
+
+       window_copy_update_cursor(wme, wme->wp->sx / 2, data->cy);
+       window_copy_update_selection(wme, 1, 0);
+       return (WINDOW_COPY_CMD_REDRAW);
+}
+
+static enum window_copy_cmd_action
 window_copy_cmd_end_of_line(struct window_copy_cmd_state *cs)
 {
        struct window_mode_entry        *wme = cs->wme;
@@ -2785,6 +2807,16 @@ static const struct {
          .clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
          .f = window_copy_cmd_cursor_up
        },
+       { .command = "cursor-centre-vertical",
+         .args = { "", 0, 0, NULL },
+         .clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
+         .f = window_copy_cmd_centre_vertical,
+       },
+       { .command = "cursor-centre-horizontal",
+         .args = { "", 0, 0, NULL },
+         .clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,
+         .f = window_copy_cmd_centre_horizontal,
+       },
        { .command = "end-of-line",
          .args = { "", 0, 0, NULL },
          .clear = WINDOW_COPY_CMD_CLEAR_EMACS_ONLY,