With mode-keys vi, keep cursor in the same position relative to the text

when scrolling. GitHub issue 5216 from Arseniy Simonov.
This commit is contained in:
nicm
2026-06-13 20:39:11 +00:00
parent 5b6ed54817
commit b1054ac227
2 changed files with 22 additions and 0 deletions

10
tmux.1
View File

@@ -2320,6 +2320,11 @@ that line.
(emacs: C\-Down)
.Xc
Scroll down.
If
.Ic mode\-keys
is
.Ic vi ,
the cursor is fixed relative to the text.
.It Xo
.Ic scroll\-down\-and\-cancel
.Xc
@@ -2361,6 +2366,11 @@ that line.
(emacs: C\-Up)
.Xc
Scroll up.
If
.Ic mode\-keys
is
.Ic vi ,
the cursor is fixed relative to the text.
.It Xo
.Ic search\-again
(vi: n)

View File

@@ -6105,6 +6105,7 @@ static void
window_copy_cursor_up(struct window_mode_entry *wme, int scroll_only)
{
struct window_copy_mode_data *data = wme->data;
struct options *oo = wme->wp->window->options;
struct screen *s = &data->screen;
u_int ox, oy, px, py;
int norectsel;
@@ -6120,6 +6121,11 @@ window_copy_cursor_up(struct window_mode_entry *wme, int scroll_only)
if (data->lineflag == LINE_SEL_LEFT_RIGHT && oy == data->sely)
window_copy_other_end(wme);
if (scroll_only && options_get_number(oo, "mode-keys") == MODEKEY_VI) {
if (data->cy < screen_size_y(s) - 1)
window_copy_update_cursor(wme, data->cx, data->cy + 1);
}
if (scroll_only || data->cy == 0) {
if (norectsel)
data->cx = data->lastcx;
@@ -6179,6 +6185,7 @@ static void
window_copy_cursor_down(struct window_mode_entry *wme, int scroll_only)
{
struct window_copy_mode_data *data = wme->data;
struct options *oo = wme->wp->window->options;
struct screen *s = &data->screen;
u_int ox, oy, px, py;
int norectsel;
@@ -6194,6 +6201,11 @@ window_copy_cursor_down(struct window_mode_entry *wme, int scroll_only)
if (data->lineflag == LINE_SEL_RIGHT_LEFT && oy == data->endsely)
window_copy_other_end(wme);
if (scroll_only && options_get_number(oo, "mode-keys") == MODEKEY_VI) {
if (data->cy > 0)
window_copy_update_cursor(wme, data->cx, data->cy - 1);
}
if (scroll_only || data->cy == screen_size_y(s) - 1) {
if (norectsel)
data->cx = data->lastcx;