feat: add key mapping for paste overwrite
This commit is contained in:
@@ -73,3 +73,8 @@ add_keymap("<leader>qP", function()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end, "Test Prompt")
|
end, "Test Prompt")
|
||||||
|
|
||||||
|
-- Paste over text with overwrite
|
||||||
|
add_keymap("<leader>cp", function()
|
||||||
|
data.func.paste_overwrite()
|
||||||
|
end, "Paste overwrite", "n")
|
||||||
|
|||||||
@@ -455,6 +455,41 @@ function M.move_visual(up, multiplier)
|
|||||||
vim.cmd("norm gv")
|
vim.cmd("norm gv")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.paste_overwrite()
|
||||||
|
-- Get the register contents and type
|
||||||
|
local register = vim.fn.getreginfo(vim.v.register or '"')
|
||||||
|
local regcontents = register.regcontents
|
||||||
|
|
||||||
|
-- Enter Virtual Replace Mode
|
||||||
|
vim.api.nvim_feedkeys("gR", "n", false)
|
||||||
|
|
||||||
|
-- Process each line in the register contents
|
||||||
|
for i, line in ipairs(regcontents) do
|
||||||
|
if i > 1 then
|
||||||
|
-- Handle formatting of multi-line pastes (except for the first line)
|
||||||
|
vim.api.nvim_feedkeys(
|
||||||
|
vim.api.nvim_replace_termcodes("<Esc>0gR", true, false, true),
|
||||||
|
"n",
|
||||||
|
false
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Paste the current line; add a newline if it's not the last line
|
||||||
|
if i < #regcontents then
|
||||||
|
vim.api.nvim_feedkeys(line .. "\n", "n", false)
|
||||||
|
else
|
||||||
|
vim.api.nvim_feedkeys(line, "n", false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Properly exit Virtual Replace Mode using <Esc>
|
||||||
|
vim.api.nvim_feedkeys(
|
||||||
|
vim.api.nvim_replace_termcodes("<Esc>", true, false, true),
|
||||||
|
"n",
|
||||||
|
false
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
---@function Function to reload the user's Neovim configuration
|
---@function Function to reload the user's Neovim configuration
|
||||||
---@return nil
|
---@return nil
|
||||||
function M.reload_config()
|
function M.reload_config()
|
||||||
|
|||||||
Reference in New Issue
Block a user