diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-03-06 06:56:24 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-03-15 18:15:18 +0800 |
commit | bfb77544425b7cca372cb87f00ef6b6e87c5f6d5 (patch) | |
tree | 874fa2e7b2beee039d5164b3030a2aead15c6998 /runtime/lua/vim/_editor.lua | |
parent | 2601e0873ff50ed804487dff00bd27e233709beb (diff) | |
download | rneovim-bfb77544425b7cca372cb87f00ef6b6e87c5f6d5.tar.gz rneovim-bfb77544425b7cca372cb87f00ef6b6e87c5f6d5.tar.bz2 rneovim-bfb77544425b7cca372cb87f00ef6b6e87c5f6d5.zip |
fix(paste): deal with eol and eof in Visual mode
Diffstat (limited to 'runtime/lua/vim/_editor.lua')
-rw-r--r-- | runtime/lua/vim/_editor.lua | 15 |
1 files changed, 13 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("']")) |