diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 4d2abf1c8c..a664535c0f 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5038,6 +5038,9 @@ static void nv_visual(cmdarg_T *cap) assert(cap->count0 >= INT_MIN && cap->count0 <= INT_MAX); curwin->w_curswant += resel_VIsual_vcol * cap->count0 - 1; curwin->w_cursor.lnum = lnum; + if (*p_sel == 'e') { + curwin->w_curswant++; + } coladvance(curwin, curwin->w_curswant); } else { curwin->w_set_curswant = true; diff --git a/test/old/testdir/test_visual.vim b/test/old/testdir/test_visual.vim index e25327ddd4..39388cbc27 100644 --- a/test/old/testdir/test_visual.vim +++ b/test/old/testdir/test_visual.vim @@ -2718,4 +2718,50 @@ func Test_visual_block_cursor_insert_enter() bwipe! endfunc +func Test_visual_block_exclusive_selection() + new + set selection=exclusive + call setline(1, ['asöd asdf', 'asdf asdf', 'as€d asdf', 'asdf asdf']) + call cursor(1, 1) + exe ":norm! \eh3j~" + call assert_equal(['ASÖd asdf', 'ASDf asdf', 'AS€d asdf', 'ASDf asdf'], getline(1, '$')) + exe ":norm! 1v~" + call assert_equal(['asöd asdf', 'asdf asdf', 'as€d asdf', 'asdf asdf'], getline(1, '$')) + bwipe! + set selection&vim +endfunc + +func Test_visual_block_exclusive_selection_adjusted() + new + " Test that the end-position of the visual selection is adjusted for exclusive selection + set selection=exclusive + call setline(1, ['asöd asdf ', 'asdf asdf ', 'as€d asdf ', 'asdf asdf ']) + call cursor(1, 1) + " inclusive motion + exe ":norm! \e3jy" + call assert_equal([0, 4, 5, 0], getpos("'>")) + " exclusive motion + exe ":norm! \ta3jy" + call assert_equal([0, 4, 6, 0], getpos("'>")) + " another inclusive motion + exe ":norm! \g_3jy" + call assert_equal([0, 4, 10, 0], getpos("'>")) + + " Reset selection option to Vim default + set selection&vim + call cursor(1, 1) + + " inclusive motion + exe ":norm! \e3jy" + call assert_equal([0, 4, 4, 0], getpos("'>")) + " exclusive motion + exe ":norm! \ta3jy" + call assert_equal([0, 4, 5, 0], getpos("'>")) + " another inclusive motion + exe ":norm! \g_3jy" + call assert_equal([0, 4, 9, 0], getpos("'>")) + bwipe! + set selection&vim +endfunc + " vim: shiftwidth=2 sts=2 expandtab