diff --git a/init.lua b/init.lua index 5814654..07896a8 100644 --- a/init.lua +++ b/init.lua @@ -29,12 +29,12 @@ (c) Frank Zechert 2026 ]] --- enable loading of precompiled lua modules to improve startup time -vim.loader.enable() - vim.g.mapleader = " " vim.g.maplocalleader = " " +-- enable loading of precompiled lua modules to improve startup time +vim.loader.enable() + -- load configuration require("config.ui") require("config.options") diff --git a/lua/config/autocommands.lua b/lua/config/autocommands.lua index cd38fa4..601eca1 100644 --- a/lua/config/autocommands.lua +++ b/lua/config/autocommands.lua @@ -62,6 +62,15 @@ create_cmd({"BufRead", "BufNewFile"}, { end, }) +-- disable list chars in specific filetypes, e.g. netrw +create_cmd({"FileType"}, { + desc = "Disable list chars for some filetypes", + pattern = { "netrw" }, + callback = function(args) + vim.opt_local.list = false + end, +}) + -- automatically remove trailing whitespace on save file create_cmd({"BufWritePre"}, { desc = "Remove trailing whitespace when saving", diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index aff8838..3adb5fa 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -36,3 +36,67 @@ map("t", "", "", { desc = "exit terminanl" }) -- Pressing ESC removes search highlights map("n", "", "nohlsearch") + +-- Smart buffer switch (to alternative, previous, or next) if possible +local function smart_buffer_switch(current) + local alternative = vim.fn.bufnr("#") + + -- get all listed buffers + local buffers = vim.fn.getbufinfo({ buflisted = 1 }) + + -- find index of the current buffer + local current_index = nil + for index, buffer in ipairs(buffers) do + if buffer.bufnr == current then + current_index = i + break + end + end + + -- try to switch to alternate buffer + if alternative > 0 and vim.fn.buflisted(alternative) == 1 and alternative ~= current then + vim.api.nvim_set_current_buf(alternative) + -- try to switch to previous buffer + elseif current_index and current_index > 1 then + vim.api.nvim_set_current_buf(buffers[current_index -1].bufnr) + -- try to switch to next buffer + elseif current_index and current_index < #buffers then + vim.api.nvim_set_current_buf(buffers[current_index + 1].bufnr) + end +end + +local function smart_buffer_delete() + local current = vim.api.nvim_get_current_buf() + smart_buffer_switch(current) + -- delete current buffer + vim.cmd(":confirm bdelete " .. current) +end +map("n", "bd", smart_buffer_delete, { desc = "Close Current Buffer" }) + +local function smart_buffer_wipeout() + local current = vim.api.nvim_get_current_buf() + smart_buffer_switch(current) + -- delete current buffer + vim.cmd(":confirm bwipeout " .. current) +end +map("n", "bw", smart_buffer_wipeout, { desc = "Wipeout Current Buffer" }) + +local function delete_other_buffers() + local current = vim.api.nvim_get_current_buf() + for _, buffer in ipairs(vim.api.nvim_list_bufs()) do + if buffer ~= current and vim.bo[buffer].buflisted and not vim.bo[buffer].modified then + vim.api.nvim_buf_delete(buffer, {}) + end + end +end +map("n", "bD", delete_other_buffers, { desc = "Close All Other Buffers" }) + +local function wipeout_other_buffers() + local current = vim.api.nvim_get_current_buf() + for _, buffer in ipairs(vim.api.nvim_list_bufs()) do + if buffer ~= current and vim.bo[buffer].buflisted and not vim.bo[buffer].modified then + vim.cmd("bwipeout " .. buffer) + end + end +end +map("n", "bW", wipeout_other_buffers, { desc = "Wipeout All Other Buffers" }) diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua index 8bd32fe..79d8052 100644 --- a/lua/plugins/lualine.lua +++ b/lua/plugins/lualine.lua @@ -128,6 +128,28 @@ return { lualine_y = {}, lualine_z = {}, } + }, + keys = { + { "b1", ":LualineBuffersJump! 1", desc = "Show Buffer 1" }, + { "b2", ":LualineBuffersJump! 2", desc = "Show Buffer 2" }, + { "b3", ":LualineBuffersJump! 3", desc = "Show Buffer 3" }, + { "b4", ":LualineBuffersJump! 4", desc = "Show Buffer 4" }, + { "b5", ":LualineBuffersJump! 5", desc = "Show Buffer 5" }, + { "b6", ":LualineBuffersJump! 6", desc = "Show Buffer 6" }, + { "b7", ":LualineBuffersJump! 7", desc = "Show Buffer 7" }, + { "b8", ":LualineBuffersJump! 8", desc = "Show Buffer 8" }, + { "b9", ":LualineBuffersJump! 9", desc = "Show Buffer 9" }, + { "b0", ":LualineBuffersJump! 10", desc = "Show Buffer 10" }, + { + "bb", + function() + local index = tonumber(vim.fn.input("Jump to Buffer: ")) + if index then + vim.cmd("LualineBuffersJump! " .. index) + end + end, + desc = "Show Buffer ?" + }, } } } diff --git a/lua/plugins/whichkey.lua b/lua/plugins/whichkey.lua new file mode 100644 index 0000000..c2722ff --- /dev/null +++ b/lua/plugins/whichkey.lua @@ -0,0 +1,56 @@ +--[[ + +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣷⣦⣄⡀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⡀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⡀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠚⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠗⢀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣄⡉⠓⠦⣌⡙⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⢋⣡⠴⠚⢉⣠⣤⣀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣤⣶⣿⣿⣿⣿⣿⣷⣦⣄⡉⠓⠦⣌⡙⠻⢿⣿⣿⣿⣿⣿⣿⡿⠟⢋⣡⠴⠚⢉⣠⣴⣾⣿⣿⣿⣿⣿⣶⣤ +⠀⠀⠀⠀⠀⠀⠀⠀⠐⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠓⠦⣌⡙⠻⠟⢋⣡⠴⠚⢉⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⠂ +⠀⠀⠀⠀⢀⣠⣴⣆⡈⠻⢿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠃⠘⢉⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⡿⠟⢁⣰⣦⣄⡀ +⠀⠀⠐⠾⣿⣿⣿⣿⣿⣷⣦⣌⡙⠻⢿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⡿⠟⢋⣡⣴⣾⣿⣿⣿⣿⣿⠷⠂ +⠀⢸⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣌⡙⠻⢿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⡿⠟⢋⣡⣴⣾⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⡇ +⠀⢸⣿⣿⣿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣌⡙⠻⢿⣿⣷⣦⣄⡉⠛⠿⠿⠛⢉⣠⣴⣾⣿⡿⠟⢋⣡⣴⣾⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⣿⣿⣿⡇ +⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣌⡙⠻⢿⣿⣷⡆⢰⣾⣿⡿⠟⢋⣡⣴⣾⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⣿⣿⣿⣿⠿⠛⠉ +⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣌⡙⠃⠘⢋⣡⣴⣾⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⣿⣿⣿⣿⠿⠛⠉ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⣿⣷⣾⣿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⣿⣿⣿⣿⠿⠛⠉ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣄⡉⠛⠿⣿⣿⣿⣿⠿⠛⢉⣠⣴⣾⣿⣿⣿⣿⣿⠿⠛⠉ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣷⣦⣄⡉⢉⣠⣴⣾⣿⣿⣿⣿⣿⠿⠛⠉ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⡇⢸⣿⣿⣿⣿⠿⠛⠉ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⡇⢸⠿⠛⠉ + + __ _ _ + / _|___ ___| |_ __ _ ___| | __ + | ||_ /____/ __| __/ _` |/ __| |/ / + | _/ /_____\__ \ || (_| | (__| < + |_|/___| |___/\__\__,_|\___|_|\_\ + + Neovim 0.12 configuration + (c) Frank Zechert 2026 +]] + +return { + { + "folke/which-key.nvim", + dependencies = { + { "nvim-mini/mini.icons" }, + { "nvim-tree/nvim-web-devicons" }, + }, + event = "VeryLazy", + opts = { + preset = "modern", + spec = { + { "b", group = "Buffers" }, + }, + }, + keys = { + { + "?", + function() + require("which-key").show({ global = false }) + end, + desc = "Buffer Local Keymaps" + }, + } + } +}