summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/custom
diff options
context:
space:
mode:
authorKyren223 <ulmliad223@gmail.com>2024-09-16 18:41:47 +0300
committerKyren223 <ulmliad223@gmail.com>2024-09-16 18:41:47 +0300
commita504dfdcdd3db5a3b9ed0b55fde0eee7167d84ee (patch)
treeb955848cafa8266e83e7635ef8959b9740b75023 /.config/nvim/lua/custom
parent497e509828233a075b10eba6554c79b784aeb2c7 (diff)
feat: added keymap to copy current filepath
Diffstat (limited to '.config/nvim/lua/custom')
-rw-r--r--.config/nvim/lua/custom/config/keymaps.lua23
1 files changed, 21 insertions, 2 deletions
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' }, '<C-r>')
set('n', 'U', '<cmd>redo<cr>')
set('i', '<C-z>', '<cmd>undo<cr>')
-set('i', '<C-z>', '<cmd>undo<cr>')
set({ 'i', 'n', 'v' }, '<C-q>', '<cmd>wqa<cr>')
+set('n', '<leader>yp', yank_filepath_to_clipboard('linux'), { desc = '[Y]oink File [P]ath (linux)' })
+set('n', '<leader>yP', yank_filepath_to_clipboard('windows'), { desc = '[Y]oink File [P]ath (windows)' })
-- Window Navigation - NO NEED BECAUSE IT CONFLICTS WITH TMUX
-- set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
@@ -56,7 +76,6 @@ set({ 'n', 't' }, '<C-Right>', string.format('<cmd>vertical resize +%d<CR>', res
-- Keep selection after < and > in visual mode
set('v', '<', '<gv')
set('v', '>', '>gv')
-
-- Execute lua file or line
set('n', '<leader>x', '<cmd>.lua<CR>', { desc = 'Execute the current line' })
set('n', '<leader><leader>x', '<cmd>source %<CR>', { desc = 'Execute the current file' })