From 33487db7c329f610e0fec633abfdb460470e042e Mon Sep 17 00:00:00 2001 From: Mathias Rothenhaeusler Date: Mon, 25 Aug 2025 16:32:44 +0200 Subject: [PATCH] copy filename shortcut --- lua/custom/keymaps.lua | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/lua/custom/keymaps.lua b/lua/custom/keymaps.lua index 4f534c9..d50d912 100644 --- a/lua/custom/keymaps.lua +++ b/lua/custom/keymaps.lua @@ -14,6 +14,8 @@ keymap.set('n', 'tp', ':tabp', { silent = true }) -- go to prev keymap.set('n', 'gn', ':bn', { silent = true }) keymap.set('n', 'gp', ':bp', { silent = true }) keymap.set('n', 'g[', ':b#', { silent = true }) +-- copy filename in buffer +keymap.set('n', 'cf', ':let @+ = expand("%:t")', { silent = true }) -- keymap.set('n', '', ':w') keymap.set('n', 'x', ':bd', { silent = true }) @@ -72,18 +74,18 @@ keymap.set('n', 'fh', 'Telescope file_history history', { silen -- Define a custom function to move the current buffer to a vertical split with the previous buffer function move_to_vertical_split() - local current_buffer = vim.fn.bufnr('%') -- Get the current buffer number - local last_buffer = vim.fn.bufnr('#') -- Get the previous buffer number + local current_buffer = vim.fn.bufnr('%') -- Get the current buffer number + local last_buffer = vim.fn.bufnr('#') -- Get the previous buffer number - -- Check if last_buffer is set; if not, duplicate the current buffer - if last_buffer == -1 then - vim.cmd('vsplit') - vim.cmd('b ' .. current_buffer) - else - vim.cmd('vsplit') - vim.cmd('b ' .. last_buffer) - vim.cmd('wincmd w') -- Switch focus to the original (current) buffer - end + -- Check if last_buffer is set; if not, duplicate the current buffer + if last_buffer == -1 then + vim.cmd('vsplit') + vim.cmd('b ' .. current_buffer) + else + vim.cmd('vsplit') + vim.cmd('b ' .. last_buffer) + vim.cmd('wincmd w') -- Switch focus to the original (current) buffer + end end -- Map v to the custom function @@ -93,12 +95,12 @@ keymap.set('n', 'v', [[:lua move_to_vertical_split()]], { noremap = keymap.set("n", "", 'Telescope persisted', { silent = true }) keymap.set("n", "m", function() - local winid = vim.api.nvim_get_current_win() - local wininfo = vim.fn.getwininfo(winid)[1] + local winid = vim.api.nvim_get_current_win() + local wininfo = vim.fn.getwininfo(winid)[1] - if wininfo and wininfo.wincol > vim.o.columns / 2 then - vim.cmd("wincmd H") -- Move to the left if currently on the right - else - vim.cmd("wincmd L") -- Move to the right if currently on the left - end + if wininfo and wininfo.wincol > vim.o.columns / 2 then + vim.cmd("wincmd H") -- Move to the left if currently on the right + else + vim.cmd("wincmd L") -- Move to the right if currently on the left + end end, { desc = "Move buffer between left/right split" })