From a504dfdcdd3db5a3b9ed0b55fde0eee7167d84ee Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Mon, 16 Sep 2024 18:41:47 +0300 Subject: feat: added keymap to copy current filepath --- .config/nvim/lua/custom/config/keymaps.lua | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to '.config/nvim/lua/custom/config') diff --git a/.config/nvim/lua/custom/config/keymaps.lua b/.config/nvim/lua/custom/config/keymaps.lua index 91069b2..5d983a7 100644 --- a/.config/nvim/lua/custom/config/keymaps.lua +++ b/.config/nvim/lua/custom/config/keymaps.lua @@ -12,6 +12,25 @@ local function toggle_zen() vim.cmd('UndotreeHide') end +local function yank_filepath_to_clipboard(os) + return function() + local filepath = vim.fn.expand('%:p') + if os == 'linux' then + local home_dir = vim.fn.expand('~') + filepath = filepath:gsub(home_dir, '~') + elseif os == 'windows' then + local mnt = '/mnt/' + if filepath:sub(1, #mnt) == mnt then + filepath = filepath:sub(#mnt + 1, #mnt + 1) .. ':' .. filepath:sub(#mnt + 2) + else + filepath = '//wsl.localhost/openSUSE-Tumbleweed' .. filepath + end + filepath = filepath:gsub('/', '\\') + end + vim.fn.setreg('+', filepath) + end +end + local function paste() local value = vim.fn.getreg('+') if vim.fn.mode() == 'c' then @@ -37,8 +56,9 @@ unbind({ 'i', 'n', 'v' }, '') set('n', 'U', 'redo') set('i', '', 'undo') -set('i', '', 'undo') set({ 'i', 'n', 'v' }, '', 'wqa') +set('n', 'yp', yank_filepath_to_clipboard('linux'), { desc = '[Y]oink File [P]ath (linux)' }) +set('n', 'yP', yank_filepath_to_clipboard('windows'), { desc = '[Y]oink File [P]ath (windows)' }) -- Window Navigation - NO NEED BECAUSE IT CONFLICTS WITH TMUX -- set('n', '', '', { desc = 'Move focus to the left window' }) @@ -56,7 +76,6 @@ set({ 'n', 't' }, '', string.format('vertical resize +%d', res -- Keep selection after < and > in visual mode set('v', '<', '', '>gv') - -- Execute lua file or line set('n', 'x', '.lua', { desc = 'Execute the current line' }) set('n', 'x', 'source %', { desc = 'Execute the current file' }) -- cgit v1.3.1