aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/_editor.lua15
-rw-r--r--test/functional/api/vim_spec.lua36
2 files changed, 49 insertions, 2 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua
index 8e49b51cec..6b1725c9ff 100644
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -192,8 +192,19 @@ do
if mode:find('^n') then -- Normal mode
vim.api.nvim_put(lines, 'c', true, false)
else -- Visual or Select mode
- vim.api.nvim_command([[exe "normal! \<Del>"]])
- vim.api.nvim_put(lines, 'c', false, false)
+ vim.api.nvim_command([[exe "silent normal! \<Del>"]])
+ local del_start = vim.fn.getpos("'[")
+ local cursor_pos = vim.fn.getpos('.')
+ if mode:find('^[VS]') then -- linewise
+ if cursor_pos[2] < del_start[2] then -- replacing lines at eof
+ -- create a new line
+ vim.api.nvim_put({''}, 'l', true, true)
+ end
+ vim.api.nvim_put(lines, 'c', false, false)
+ else
+ -- paste after cursor when replacing text at eol, otherwise paste before cursor
+ vim.api.nvim_put(lines, 'c', cursor_pos[3] < del_start[3], false)
+ end
end
-- put cursor at the end of the text instead of one character after it
vim.fn.setpos('.', vim.fn.getpos("']"))
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 3d57953a11..eaee9211f4 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -702,6 +702,42 @@ describe('API', function()
feed('u')
expect('||')
end)
+ it('stream: Visual mode either end not at the end of a line', function()
+ feed('i|xxx<CR>xxx|<Esc>hvhk')
+ nvim('paste', 'aaaaaa', false, 1)
+ nvim('paste', 'bbbbbb', false, 2)
+ nvim('paste', 'cccccc', false, 2)
+ nvim('paste', 'dddddd', false, 3)
+ expect('|aaaaaabbbbbbccccccdddddd|')
+ feed('u')
+ expect([[
+ |xxx
+ xxx|]])
+ end)
+ it('stream: Visual mode cursor at the end of a line', function()
+ feed('i||xxx<CR>xxx<Esc>vko')
+ nvim('paste', 'aaaaaa', false, 1)
+ nvim('paste', 'bbbbbb', false, 2)
+ nvim('paste', 'cccccc', false, 2)
+ nvim('paste', 'dddddd', false, 3)
+ expect('||aaaaaabbbbbbccccccdddddd')
+ feed('u')
+ expect([[
+ ||xxx
+ xxx]])
+ end)
+ it('stream: Visual mode other end at the end of a line', function()
+ feed('i||xxx<CR>xxx<Esc>vk')
+ nvim('paste', 'aaaaaa', false, 1)
+ nvim('paste', 'bbbbbb', false, 2)
+ nvim('paste', 'cccccc', false, 2)
+ nvim('paste', 'dddddd', false, 3)
+ expect('||aaaaaabbbbbbccccccdddddd')
+ feed('u')
+ expect([[
+ ||xxx
+ xxx]])
+ end)
it('non-streaming', function()
-- With final "\n".
nvim('paste', 'line 1\nline 2\nline 3\n', true, -1)