Mercurial > vim
diff src/normal.c @ 18291:11f68eb58fda v8.1.2140
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Commit: https://github.com/vim/vim/commit/ceba3dd5187788e09f65bd41b07b40f6f9aab953
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 12 16:12:54 2019 +0200
patch 8.1.2140: "gk" and "gj" do not work correctly in number column
Problem: "gk" and "gj" do not work correctly in number column.
Solution: Allow for a negative "curswant". (Zach Wegner, closes https://github.com/vim/vim/issues/4969)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 12 Oct 2019 16:15:03 +0200 |
parents | 5d67f207f7c3 |
children | 9f51d0cef8da |
line wrap: on
line diff
--- a/src/normal.c +++ b/src/normal.c @@ -2499,17 +2499,18 @@ nv_screengo(oparg_T *oap, int dir, long n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; else n = width1; - if (curwin->w_curswant > (colnr_T)n + 1) - curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) - * width2; + if (curwin->w_curswant >= (colnr_T)n) + curwin->w_curswant = n - 1; } while (dist--) { if (dir == BACKWARD) { - if ((long)curwin->w_curswant > width2) - // move back within line + if ((long)curwin->w_curswant >= width1) + // Move back within the line. This can give a negative value + // for w_curswant if width1 < width2 (with cpoptions+=n), + // which will get clipped to column 0. curwin->w_curswant -= width2; else { @@ -2557,6 +2558,12 @@ nv_screengo(oparg_T *oap, int dir, long } curwin->w_cursor.lnum++; curwin->w_curswant %= width2; + // Check if the cursor has moved below the number display + // when width1 < width2 (with cpoptions+=n). Subtract width2 + // to get a negative value for w_curswant, which will get + // clipped to column 0. + if (curwin->w_curswant >= width1) + curwin->w_curswant -= width2; linelen = linetabsize(ml_get_curline()); } }