overhauled ergonomics (enforce two split panes for help, man and qf-list)
authorLukas Hägele <lukas.haegele93@web.de>
Wed, 25 Mar 2026 16:21:01 +0000 (17:21 +0100)
committerLukas Hägele <lukas.haegele93@web.de>
Wed, 25 Mar 2026 16:21:01 +0000 (17:21 +0100)
lua/config/autocommands.lua
lua/config/keymap.lua
lua/config/settings.lua
lua/snippets/vsplit.lua [new file with mode: 0644]
plugin/floaterminal.lua
plugin/sessionmanager.lua

index c21a26ba8251e589a8221ed017f675be99abc93a..2aa54c6ed744b2b36d50dd4f8e577fbd60169f18 100644 (file)
@@ -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", "<C-]>", { silent = true, buffer = opts.buf })
   end,
index 663f56424ade730f5b8ec82d6f80eebef90fe215..ab8a00c7b45abbc12c748b98dc3f6ce203427246 100644 (file)
@@ -5,17 +5,9 @@ vim.keymap.set('i', 'jj', '<Esc>')
 vim.keymap.set("n", "<space>#", "Vgc", { desc = "select line and toggle comment", remap = true })
 vim.keymap.set("v", "<space>#", "gc", { desc = "toggle comment of selected line", remap = true })
 
--- window actions
-vim.keymap.set("n", "<space>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", "<space>s", vsplit.split, { desc = "split vertically and move to new window" })
 
 -- move highlighted lines
 vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
@@ -27,8 +19,20 @@ vim.keymap.set("n", "<space>x", ":.lua<CR>")
 vim.keymap.set("v", "<space>x", ":lua<CR>")
 
 -- quickfix commands
-vim.keymap.set("n", "<M-j>", "<cmd>cnext<CR>")
-vim.keymap.set("n", "<M-k>", "<cmd>cprev<CR>")
+vim.keymap.set("n", "<M-j>", function()
+  local success, _ = pcall(vim.cmd, "cnext")
+  if not success then
+    vim.cmd("cfirst")
+  end
+  vim.cmd("normal! zz")
+end)
+vim.keymap.set("n", "<M-k>", function()
+  local success, _ = pcall(vim.cmd, "cprev")
+  if not success then
+    vim.cmd("clast")
+  end
+  vim.cmd("normal! zz")
+end)
 vim.keymap.set('n', '<M-o>', 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', '<M-o>', function()
 end, { noremap = true, silent = true })
 
 -- build
-vim.keymap.set("n", "<M-m>", "<cmd>make<CR><cmd>copen<CR>", { desc = "run makefile and open quickfix list" })
+vim.keymap.set("n", "<M-m>", "<cmd>make!<CR><cmd>copen<CR>", { desc = "run makefile and open quickfix list" })
 
index f9fa0be0aed2de98fed6511c019173af7fbe8188..94a1aec78e995eff660223978bc50ad40aad7aba 100644 (file)
@@ -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 (file)
index 0000000..8b33ef4
--- /dev/null
@@ -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
index 703324f97791292480d01546700f8c676b73312e..827db46e44c33d1365d1cc050471a634ca4c6970 100644 (file)
@@ -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" }, "<space>tt", toggle_terminal)
+vim.keymap.set({ "n", "t" }, "<space>t", toggle_terminal)
index ab3d5dd2d5fa23624bd300be61cd3ed7a7ffefe5..865e4ad14fa80979e20433d592014a9e3cdebec5 100644 (file)
@@ -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