diff --git a/users/price/dots/.config/nvim/lua/neovide.lua b/users/price/dots/.config/nvim/lua/neovide.lua index 11e54eb6..2c8f0de9 100644 --- a/users/price/dots/.config/nvim/lua/neovide.lua +++ b/users/price/dots/.config/nvim/lua/neovide.lua @@ -18,10 +18,37 @@ vim.g.neovide_fullscreen = false vim.g.neovide_cursor_vfx_mode = "ripple" vim.g.neovide_cursor_vfx_particle_lifetime = 0.3 --- Allow clipboard copy paste in neovim -vim.keymap.set({ "n", "v" }, "", '"+P') -- Paste normal and visual mode -vim.keymap.set({ "i", "c" }, "", "+") -- Paste insert and command mode -vim.keymap.set("t", "", [["+Pi]]) -- Paste terminal mode +-- ===== Allow clipboard copy paste in neovim +-- Paste normal and visual mode +vim.keymap.set({ "n", "v" }, "", '"+P') +-- Paste insert and command mode +vim.keymap.set({ "i", "c" }, "", function() + local register = "+" + local register_type = vim.fn.getregtype(register) + local register_content = vim.fn.getreg(register) + -- Set the register to be pasted `charwise`, see `:h charwise` + vim.fn.setreg(register, register_content, "c") + -- Handle pasting at the end of lines. Because we're invoking `normal!` commands whilst in + -- `insert` mode, we have to handle EOL stuff. For some reason (and I'm too lazy to investiage), + -- `nvim_feedkeys` doesn't block correctly here and the last `setreg` call is triggered too + -- early. + local cmd = '"' .. register .. "g" + if vim.fn.charcol(".") == (vim.fn.charcol("$")) then + -- At eol, paste AFTER the cursor + vim.cmd.normal({ cmd .. "p", bang = true }) + -- Since we're in insert mode and we just invoked a `normal` mode command, the cursor is + -- actually offset one column to the left from where it should be -- move it over by one. + local win = vim.api.nvim_get_current_win() + local row, col = unpack(vim.api.nvim_win_get_cursor(win)) + vim.api.nvim_win_set_cursor(win, { row, col + 1 }) + else + vim.cmd.normal({ cmd .. "P", bang = true }) + end + -- Restore the register's type back to what it was previously + vim.fn.setreg(register, register_content, register_type) +end) +-- Paste terminal mode +vim.keymap.set("t", "", [["+Pi]]) -- Next/prev tabs vim.keymap.set({ "", "!", "v", "t" }, "", "tabnext", { noremap = true, silent = true })