+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 = { "*" },
-- 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,
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")
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'
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" })
vim.opt.winborder = "rounded"
+vim.opt.switchbuf = "useopen"
+
-- vim.opt.termguicolors = false
vim.opt.scrolloff = 8
--- /dev/null
+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
-- 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)
local history = {}
---- show session history
+--- show session history in telescope
local function session_picker(opts)
opts = opts or require("telescope.themes").get_dropdown{}
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