collect vsplit code in its plugin file
authorLukas Hägele <lukas.haegele93@web.de>
Sun, 29 Mar 2026 10:12:30 +0000 (12:12 +0200)
committerLukas Hägele <lukas.haegele93@web.de>
Sun, 29 Mar 2026 10:12:30 +0000 (12:12 +0200)
lua/config/autocommands.lua
lua/config/keymap.lua
lua/snippets/vsplit.lua

index 2aa54c6ed744b2b36d50dd4f8e577fbd60169f18..cb1985234b4007a04892bde0caa9f0795ace4254 100644 (file)
@@ -1,43 +1,3 @@
-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 = { "*" },
index ab8a00c7b45abbc12c748b98dc3f6ce203427246..8aaa3d60980b44ea632e06fc1d1ed867826782b6 100644 (file)
@@ -5,10 +5,6 @@ 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 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")
 vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
index 8b33ef4e0c0610e5138bae524f171f0f3d041e18..50dcde4f825c09f01b48be6924597b00d80eb027 100644 (file)
@@ -16,4 +16,43 @@ M.split = function()
   M.right_id = vim.api.nvim_open_win(0, true, win_config)
 end
 
+-- 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
+      M.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 == M.left_id) or (new_win == M.right_id)) then
+        -- move new buffer to left pane
+        vim.api.nvim_win_set_buf(M.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(M.right_id)
+        end
+      end
+    end)
+  end
+})
+
+-- keymaps
+vim.keymap.set("n", "<space>s", M.split, { desc = "split vertically and move to new window" })
+
 return M