From db1fa7dcd0d9ca96923f8132280634d7dcf1da35 Mon Sep 17 00:00:00 2001 From: mace Date: Sun, 15 Oct 2023 14:28:16 +0200 Subject: [PATCH] added leader v for split --- lua/custom/keymaps.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lua/custom/keymaps.lua b/lua/custom/keymaps.lua index a6f9782..09ef741 100644 --- a/lua/custom/keymaps.lua +++ b/lua/custom/keymaps.lua @@ -61,3 +61,22 @@ keymap.set('n', 'fs', '(easymotion-overwin-f2)', { silent = true } -- Telescope history keymap.set('n', 'fh', 'Telescope file_history history', { silent = true }) + +-- 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 + + -- 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 +keymap.set('n', 'v', [[:lua move_to_vertical_split()]], { noremap = true, silent = true })