aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/regexp.c5
-rw-r--r--test/old/testdir/test_visual.vim8
2 files changed, 13 insertions, 0 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 74f3b3452b..37f672fc86 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -1365,6 +1365,11 @@ static bool reg_match_visual(void)
top = curbuf->b_visual.vi_end;
bot = curbuf->b_visual.vi_start;
}
+ // a substitue command may have
+ // removed some lines
+ if (bot.lnum > curbuf->b_ml.ml_line_count) {
+ bot.lnum = curbuf->b_ml.ml_line_count;
+ }
mode = curbuf->b_visual.vi_mode;
curswant = curbuf->b_visual.vi_curswant;
}
diff --git a/test/old/testdir/test_visual.vim b/test/old/testdir/test_visual.vim
index b09078352e..983f07a375 100644
--- a/test/old/testdir/test_visual.vim
+++ b/test/old/testdir/test_visual.vim
@@ -1626,4 +1626,12 @@ func Test_visual_drag_out_of_window()
bwipe!
endfunc
+func Test_visual_substitute_visual()
+ new
+ call setline(1, ['one', 'two', 'three'])
+ call feedkeys("Gk\<C-V>j$:s/\\%V\\_.*\\%V/foobar\<CR>", 'tx')
+ call assert_equal(['one', 'foobar'], getline(1, '$'))
+ bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab