From 9b5e3ba32d370a4f3e26acba2c052d84e2359316 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 23 Feb 2021 20:14:27 -0500 Subject: vim-patch:8.2.2547: "%" command not accurate for big files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: "%" command not accurate for big files. Solution: Make it more accurate for files up to 21M lines. (Dominique Pellé, closes vim/vim#7889) https://github.com/vim/vim/commit/2c6553498e790604f50016d8435403523a2576d6 N/A patches for version.c: vim-patch:8.2.2545: errors and crash when terminal window is zero height Problem: Errors and crash when terminal window is zero height. (Leonid V. Fedorenchik) Solution: Do not resize when width or height is zero. (closes vim/vim#7890) https://github.com/vim/vim/commit/eba13e4ea28f133ff65f6b426428f49a9bd711b0 --- src/nvim/normal.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 8f22243348..1e15ded643 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5792,16 +5792,20 @@ static void nv_percent(cmdarg_T *cap) } else { cap->oap->motion_type = kMTLineWise; setpcmark(); - /* Round up, so CTRL-G will give same value. Watch out for a - * large line count, the line number must not go negative! */ - if (curbuf->b_ml.ml_line_count > 1000000) + // Round up, so 'normal 100%' always jumps at the line line. + // Beyond 21474836 lines, (ml_line_count * 100 + 99) would + // overflow on 32-bits, so use a formula with less accuracy + // to avoid overflows. + if (curbuf->b_ml.ml_line_count >= 21474836) { curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) / 100L * cap->count0; - else + } else { curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * cap->count0 + 99L) / 100L; - if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) + } + if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; + } beginline(BL_SOL | BL_FIX); } } else { // "%" : go to matching paren -- cgit