From f42657cbcf0e5775692b57e25591d42844a81934 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 5 Jul 2022 16:25:34 +0800 Subject: vim-patch:8.2.2904: "g$" causes scroll if half a double width char is visible Problem: "g$" causes scroll if half a double width char is visible. Solution: Advance to the last fully visible character. (closes vim/vim#8254) https://github.com/vim/vim/commit/74ede80aeb272ac81d41a256057c4f250372dd00 --- src/nvim/normal.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/normal.c') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index c7f7b569e7..ae4372da89 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -6157,6 +6157,16 @@ static void nv_g_cmd(cmdarg_T *cap) i = curwin->w_leftcol + curwin->w_width_inner - col_off - 1; coladvance((colnr_T)i); + // if the character doesn't fit move one back + if (curwin->w_cursor.col > 0 && utf_ptr2cells((const char *)get_cursor_pos_ptr()) > 1) { + colnr_T vcol; + + getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &vcol); + if (vcol >= curwin->w_leftcol + curwin->w_width - col_off) { + curwin->w_cursor.col--; + } + } + // Make sure we stick in this column. validate_virtcol(); curwin->w_curswant = curwin->w_virtcol; -- cgit