From 201e113a6503cdf0ec1f431d525e9fbd9eec23fd Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Sat, 26 Oct 2024 15:15:19 +0300 Subject: [PATCH] Automatically remove \r when pasting in NVIM --- .config/nvim/lua/custom/config/keymaps.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.config/nvim/lua/custom/config/keymaps.lua b/.config/nvim/lua/custom/config/keymaps.lua index 5d983a7..74b2e37 100644 --- a/.config/nvim/lua/custom/config/keymaps.lua +++ b/.config/nvim/lua/custom/config/keymaps.lua @@ -31,7 +31,13 @@ local function yank_filepath_to_clipboard(os) end end +function RemoveClipboardCR() + local clipboard = vim.fn.getreg('+'):gsub('\r', '') + vim.fn.setreg('+', clipboard) +end + local function paste() + RemoveClipboardCR() local value = vim.fn.getreg('+') if vim.fn.mode() == 'c' then -- value = vim.split(value, '\n')[1] -- only use first line (default with normal pasting) @@ -42,10 +48,14 @@ local function paste() end end + -- "Greatest Keymap ever" - ThePrimeagen -- https://www.youtube.com/watch?v=qZO9A5F6BZs&list=PLm323Lc7iSW_wuxqmKx_xxNtJC_hJbQ7R&index=4 set('x', 'p', '"_dP') +set('n', 'p', 'lua RemoveClipboardCR()p', { noremap = true }) +set('n', 'P', 'lua RemoveClipboardCR()P', { noremap = true }) + -- Misc set({ 'n', 'i' }, '', 'ggVG', { desc = 'Visually Highlight [A]ll' }) set('i', '', '', { desc = 'Ctrl + Backspace to delete word' })