From: Lukas Hägele Date: Wed, 25 Mar 2026 16:21:01 +0000 (+0100) Subject: overhauled ergonomics (enforce two split panes for help, man and qf-list) X-Git-Url: https://git.lhaegele.de/?a=commitdiff_plain;h=e13ffff95823d058361c0826657ea2ea96de20da;p=dotfiles_nvim.git overhauled ergonomics (enforce two split panes for help, man and qf-list) --- diff --git a/lua/config/autocommands.lua b/lua/config/autocommands.lua index c21a26b..2aa54c6 100644 --- a/lua/config/autocommands.lua +++ b/lua/config/autocommands.lua @@ -1,3 +1,43 @@ +local vsplit = require("snippets.vsplit") + +-- startup init +vim.api.nvim_create_autocmd( "VimEnter", { + desc = "run explore & create vsplit", + callback = function() + if vim.bo.filetype ~= "gitcommit" then + -- start netrw + vim.cmd.Explore() + -- split window on startup + vsplit.split() + end + end +}) + +-- force new window to the left pane +vim.api.nvim_create_autocmd( "FileType", { + desc = "force new window to the left pane", + group = vim.api.nvim_create_augroup('enforce-single-vsplit', { clear = true }), + pattern = { "man", "help", "qf" }, + callback = function() + vim.schedule(function() + local new_win = vim.api.nvim_get_current_win() + local new_buf = vim.api.nvim_get_current_buf() + if not ((new_win == vsplit.left_id) or (new_win == vsplit.right_id)) then + -- logging + vim.notify("new_win:" ..new_win .." new_buf:" ..new_buf .." vsplit.left_id:" ..vsplit.left_id) + -- move new buffer to left pane + vim.api.nvim_win_set_buf(vsplit.left_id, new_buf) + -- close new window + vim.api.nvim_win_close(new_win, false) + -- switch focus + if vim.bo.filetype == "qf" then + vim.api.nvim_set_current_win(vsplit.right_id) + end + end + end) + end +}) + -- remove trailing whitespace on save vim.api.nvim_create_autocmd({ "BufWritePre" }, { pattern = { "*" }, @@ -31,6 +71,7 @@ end) -- map tag jumps in help file to gd vim.api.nvim_create_autocmd({ "FileType" }, { pattern = { "help" }, + group = vim.api.nvim_create_augroup('map-help-tag-jumps', { clear = true }), callback = function(opts) vim.keymap.set("n", "gd", "", { silent = true, buffer = opts.buf }) end, diff --git a/lua/config/keymap.lua b/lua/config/keymap.lua index 663f564..ab8a00c 100644 --- a/lua/config/keymap.lua +++ b/lua/config/keymap.lua @@ -5,17 +5,9 @@ vim.keymap.set('i', 'jj', '') vim.keymap.set("n", "#", "Vgc", { desc = "select line and toggle comment", remap = true }) vim.keymap.set("v", "#", "gc", { desc = "toggle comment of selected line", remap = true }) --- window actions -vim.keymap.set("n", "s", function() - -- Define window configuration - local win_config = { - vertical = true, - width = math.floor(vim.o.columns * 0.4), - height = vim.o.lines - } - -- split window - vim.api.nvim_open_win(0, true, win_config) -end, { desc = "split vertically and move to new window" }) +-- window management +local vsplit = require("snippets.vsplit") +vim.keymap.set("n", "s", vsplit.split, { desc = "split vertically and move to new window" }) -- move highlighted lines vim.keymap.set("v", "J", ":m '>+1gv=gv") @@ -27,8 +19,20 @@ vim.keymap.set("n", "x", ":.lua") vim.keymap.set("v", "x", ":lua") -- quickfix commands -vim.keymap.set("n", "", "cnext") -vim.keymap.set("n", "", "cprev") +vim.keymap.set("n", "", function() + local success, _ = pcall(vim.cmd, "cnext") + if not success then + vim.cmd("cfirst") + end + vim.cmd("normal! zz") +end) +vim.keymap.set("n", "", function() + local success, _ = pcall(vim.cmd, "cprev") + if not success then + vim.cmd("clast") + end + vim.cmd("normal! zz") +end) vim.keymap.set('n', '', function() local qf_winid = vim.fn.getqflist({ winid = 0 }).winid local action = qf_winid > 0 and 'cclose' or 'copen' @@ -36,5 +40,5 @@ vim.keymap.set('n', '', function() end, { noremap = true, silent = true }) -- build -vim.keymap.set("n", "", "makecopen", { desc = "run makefile and open quickfix list" }) +vim.keymap.set("n", "", "make!copen", { desc = "run makefile and open quickfix list" }) diff --git a/lua/config/settings.lua b/lua/config/settings.lua index f9fa0be..94a1aec 100644 --- a/lua/config/settings.lua +++ b/lua/config/settings.lua @@ -22,6 +22,8 @@ vim.opt.smartcase = true vim.opt.winborder = "rounded" +vim.opt.switchbuf = "useopen" + -- vim.opt.termguicolors = false vim.opt.scrolloff = 8 diff --git a/lua/snippets/vsplit.lua b/lua/snippets/vsplit.lua new file mode 100644 index 0000000..8b33ef4 --- /dev/null +++ b/lua/snippets/vsplit.lua @@ -0,0 +1,19 @@ +local M = {} + +-- create vsplit +M.split = function() + -- remember window id of left pane for later + M.left_id = vim.api.nvim_get_current_win() + + -- Define window configuration + local win_config = { + vertical = true, + split = 'right', + width = math.floor(vim.o.columns * 0.6), + height = vim.o.lines + } + -- split window + M.right_id = vim.api.nvim_open_win(0, true, win_config) +end + +return M diff --git a/plugin/floaterminal.lua b/plugin/floaterminal.lua index 703324f..827db46 100644 --- a/plugin/floaterminal.lua +++ b/plugin/floaterminal.lua @@ -55,4 +55,4 @@ end -- Example usage: -- Create a floating window with default dimensions vim.api.nvim_create_user_command("Floaterminal", toggle_terminal, {}) -vim.keymap.set({ "n", "t" }, "tt", toggle_terminal) +vim.keymap.set({ "n", "t" }, "t", toggle_terminal) diff --git a/plugin/sessionmanager.lua b/plugin/sessionmanager.lua index ab3d5dd..865e4ad 100644 --- a/plugin/sessionmanager.lua +++ b/plugin/sessionmanager.lua @@ -6,7 +6,7 @@ local action_state = require "telescope.actions.state" local history = {} ---- show session history +--- show session history in telescope local function session_picker(opts) opts = opts or require("telescope.themes").get_dropdown{} @@ -38,8 +38,12 @@ local function session_picker(opts) local dir = selection[1] -- change the current directory vim.cmd("cd" ..dir) - -- open file browser - vim.cmd("Explore" ..dir) + + -- start file browser + vim.cmd.Explore(dir) + -- split window + local vsplit = require("snippets.vsplit") + vsplit.split() end) return true end