From 93b501048d7515b1b22f7239d7c040462bf544f0 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Thu, 31 Oct 2024 17:53:54 +0100 Subject: [PATCH] feat: debloat --- init.lua | 98 ++++++++++++++++------------------ lua/core/env.lua | 4 -- lua/core/globals.lua | 6 +-- lua/core/mappings.lua | 49 ++++++----------- lua/core/options.lua | 72 +++++++++++++++++++++---- lua/core/user_commands.lua | 42 --------------- lua/plugins/bufdelete.lua | 9 ---- lua/plugins/grapple.lua | 40 -------------- lua/plugins/lsp-inlayhints.lua | 8 --- lua/plugins/lualine.lua | 41 -------------- lua/plugins/winresizer.lua | 14 ----- lua/plugins/winshift.lua | 9 ---- 12 files changed, 124 insertions(+), 268 deletions(-) delete mode 100644 lua/core/env.lua delete mode 100644 lua/core/user_commands.lua delete mode 100644 lua/plugins/bufdelete.lua delete mode 100644 lua/plugins/grapple.lua delete mode 100644 lua/plugins/lsp-inlayhints.lua delete mode 100644 lua/plugins/lualine.lua delete mode 100644 lua/plugins/winresizer.lua delete mode 100644 lua/plugins/winshift.lua diff --git a/init.lua b/init.lua index f853988..2ab6f92 100644 --- a/init.lua +++ b/init.lua @@ -3,12 +3,10 @@ vim.loader.enable() local utils = require("utils") local files = { - "env", "globals", "options", "autocommands", "mappings", - "user_commands", } for _, file in ipairs(files) do @@ -21,58 +19,54 @@ for _, file in ipairs(files) do end end -if vim.g.vscode then - -- VSCode extension -else - local ok, err = pcall(require, "bootstrap") - if not ok then - utils.err("Error during bootstrap") - utils.err(err:gsub("\t", " ")) - return - end +local ok, err = pcall(require, "bootstrap") +if not ok then + utils.err("Error during bootstrap") + utils.err(err:gsub("\t", " ")) + return +end - ---@type LazyPluginSpec[] - local plugins = { - { - "neovim/nvim-lspconfig", - config = require("lsp").setup, - }, - { import = "plugins" }, - } +---@type LazyPluginSpec[] +local plugins = { + { + "neovim/nvim-lspconfig", + config = require("lsp").setup, + }, + { import = "plugins" }, +} - ---@type LazyConfig - local opts = { - install = { - colorscheme = { "moonfly" }, - }, - ui = { - icons = { - cmd = "", - config = "", - event = "", - favorite = "", - ft = "", - init = "", - import = "", - keys = "", - lazy = "", - loaded = "", - not_loaded = "", - plugin = "", - runtime = "", - require = " ", - source = "", - start = "", - task = "", - list = { - "", - "", - "", - "", - }, +---@type LazyConfig +local opts = { + install = { + colorscheme = { "moonfly" }, + }, + ui = { + icons = { + cmd = "", + config = "", + event = "", + favorite = "", + ft = "", + init = "", + import = "", + keys = "", + lazy = "", + loaded = "", + not_loaded = "", + plugin = "", + runtime = "", + require = " ", + source = "", + start = "", + task = "", + list = { + "", + "", + "", + "", }, }, - } + }, +} - require("lazy").setup(plugins, opts) -end +require("lazy").setup(plugins, opts) diff --git a/lua/core/env.lua b/lua/core/env.lua deleted file mode 100644 index 246ec29..0000000 --- a/lua/core/env.lua +++ /dev/null @@ -1,4 +0,0 @@ --- Tell neovim to prefer tmux as clipboard over xsel/xclip. -if vim.fn.getenv("TMUX") ~= vim.NIL then - vim.fn.setenv("DISPLAY", vim.NIL) -end diff --git a/lua/core/globals.lua b/lua/core/globals.lua index e1a542f..aa146e3 100644 --- a/lua/core/globals.lua +++ b/lua/core/globals.lua @@ -1,5 +1,5 @@ vim.g.mapleader = " " -vim.g.vimsyn_embed = "1" +vim.g.vimsyn_embed = "lpP" vim.g.netrw_banner = 0 vim.g.netrw_liststyle = 1 vim.g.netrw_list_hide = '\\.venv/,\\.git/' @@ -11,7 +11,3 @@ vim.g.netrw_sort_options = 'i' vim.g.netrw_sort_sequence = '[\\/]\\s*,*' vim.g.netrw_special_syntax = 1 vim.g.netrw_timefmt = '%d-%m-%Y %H:%M' -vim.cmd.language("en_US.UTF-8") - --- Bundled plugins config -vim.g.zig_fmt_autosave = 0 diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index c13259b..df2099a 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -1,44 +1,27 @@ ---- Tab mappings --- +-- Tab mappings --- vim.keymap.set("n", "tn", vim.cmd.tabnew) vim.keymap.set("n", "tq", vim.cmd.tabclose) --- switch tabs with Ctrl+PgUp/Ctrl+PgDwn (default vim mapping) ---- Buffer mappings --- --- Center cursorline -vim.keymap.set("n", "", "zz") --- Save buffer -vim.keymap.set("n", "", function () - vim.cmd.write({ mods = { silent = true, }, }) -end) --- Cycle buffers -vim.keymap.set("n", "", vim.cmd.bnext) -vim.keymap.set("n", "", vim.cmd.bprev) - ---- Navigation --- -vim.keymap.set("n", "", "zz") -vim.keymap.set("n", "", "zz") -vim.keymap.set("n", "n", "nzzzv") -vim.keymap.set("n", "N", "Nzzzv") --- nnoremap j v:count ? 'j' : 'gj' --- nnoremap k v:count ? 'k' : 'gk' - ---- General mappings --- --- yank/put using named register -vim.keymap.set({ "n", "x", }, "y", '"+y') +-- Clipboard +if vim.env.TMUX and vim.fn.executable('tmux') then + vim.keymap.set( + { "n", "x" }, + "y", + "\"+y:call system('tmux load-buffer -w -', @+)" + ) +else + vim.keymap.set({ "n", "x", }, "y", '"+y') +end vim.keymap.set({ "n", "x", }, "p", '"+p') vim.keymap.set({ "n", "x", }, "P", '"+P') -vim.keymap.set({ "n", "x", }, "+", function () - vim.fn.setreg("+", vim.fn.getreg('"')) -end) +vim.keymap.set({ "n", "x", }, "+", ":call setreg('+', @\")") -- Allow exiting insert mode in terminal by hitting vim.keymap.set("t", "", "") -- Use :diffput/get instead of normal one to allow staging visual selection -vim.keymap.set("n", "dp", vim.cmd.diffput) -vim.keymap.set("x", "dp", ":diffput") -vim.keymap.set("n", "do", vim.cmd.diffget) -vim.keymap.set("x", "do", ":diffget") +vim.keymap.set({"n", "x"}, "dp", ":diffput") +vim.keymap.set({"n", "x"}, "do", ":diffget") vim.keymap.set({ "n", "i", }, "", function () if vim.fn.pumvisible() ~= 0 then @@ -56,6 +39,8 @@ vim.keymap.set({ "n", "i", }, "", { expr = true, } ) +vim.keymap.set("n", "q", ":bp \\| bd#") + -- Allow (de)indenting without deselecting vim.keymap.set({"x"}, "<", "", ">gv") @@ -73,7 +58,6 @@ vim.keymap.set('i', '', '') vim.keymap.set('i', '', '') vim.keymap.set('i', '', '^') vim.keymap.set('i', '', '$') -vim.keymap.set('i', '', 'C') vim.keymap.set('i', '', 'x') vim.keymap.set('i', '', 'w') vim.keymap.set('i', '', 'b') @@ -85,7 +69,6 @@ vim.keymap.set('c', '', '') vim.keymap.set('c', '', '') vim.keymap.set('c', '', '') vim.keymap.set('c', '', '') --- vim.keymap.set('c', '', '???') vim.keymap.set('c', '', '') vim.keymap.set('c', '', '') vim.keymap.set('c', '', '') diff --git a/lua/core/options.lua b/lua/core/options.lua index ed3001b..51ac956 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -15,7 +15,6 @@ vim.opt.fillchars = { } vim.opt.splitbelow = true vim.opt.splitright = true --- set tabline=%!MyTabLine() vim.opt.tabstop = 4 vim.opt.softtabstop = 4 vim.opt.expandtab = true @@ -25,7 +24,6 @@ vim.opt.smarttab = false vim.opt.foldlevelstart = 99 vim.opt.foldmethod = "indent" vim.opt.foldignore = "" -vim.opt.guifont = "JetBrains Mono:11" vim.opt.completeopt:append({ "menu", "menuone", @@ -34,8 +32,7 @@ vim.opt.completeopt:append({ "noselect", }) -- set nowrap -vim.opt.matchpairs:append({ "<:>", "':'", "\":\"", }) -vim.opt.fileencoding = "utf-8" +vim.opt.matchpairs:append({ "<:>", }) -- Only relevant with wrap enabled (default) vim.opt.linebreak = true vim.opt.breakindent = true @@ -46,12 +43,6 @@ vim.opt.visualbell = true vim.opt.errorbells = false -- Persistent undo even after you close a file and re-open it vim.opt.undofile = true --- Insert mode key word completion setting, see :h 'compelete' --- and https://medium.com/usevim/set-complete-e76b9f196f0f#:~:text=When%20in%20Insert%20mode%2C%20you,%2D%2D%20CTRL%2DN%20goes%20backwards. --- kspell is only relevant if ':set spell' is toggled on, e.g. when editing --- documents -vim.opt.complete = ".,kspell" -vim.opt.spelllang = "en" -- Align indent to next multiple value of shiftwidth. -- E.g., only insert as many spaces necessary for reaching the next shiftwidth vim.opt.shiftround = true @@ -73,7 +64,6 @@ vim.opt.diffopt:append("internal") -- These make diffs easier to read, please see the following: -- https://vimways.org/2018/the-power-of-diff/ vim.opt.diffopt:append({ "indent-heuristic", "algorithm:histogram", }) -vim.cmd.filetype("plugin on") vim.opt.hlsearch = true vim.opt.laststatus = 3 vim.opt.textwidth = 0 @@ -82,3 +72,63 @@ vim.opt.shortmess:append("a") vim.opt.autoread = true -- vim.opt.cmdheight = 0 -- To hide cmdline when not used. Disabled due to -- causing "Press ENTER to continue" messages for small messages. +vim.opt.jumpoptions = {'stack', 'view', 'clean'} +vim.opt.updatetime = 100 + +function _G._status_line_git() + local status = vim.b.gitsigns_status_dict + if not status then + return '' + end + + local parts = {} + + if status.added > 0 then + table.insert(parts, string.format("%%#GitSignsAdd#+%d%%*", status.added)) + end + + if status.changed > 0 then + table.insert(parts, string.format('%%#GitSignsChange#~%d%%*', status.changed)) + end + + if status.removed > 0 then + table.insert(parts, string.format('%%#GitSignsDelete#-%d%%*', status.removed)) + end + + return table.concat(parts, " ") +end + +function _G._status_line_diagnostics() + local diag = vim.diagnostic.count(0) + local err = diag[vim.diagnostic.severity.ERROR] or 0 + local warn = diag[vim.diagnostic.severity.WARN] or 0 + local hint = diag[vim.diagnostic.severity.HINT] or 0 + local info = diag[vim.diagnostic.severity.INFO] or 0 + local parts = {} + + if err > 0 then + table.insert(parts, string.format("%%#DiagnosticError#E%d%%*", err)) + end + + if warn > 0 then + table.insert(parts, string.format('%%#DiagnosticWarn#W%d%%*', warn)) + end + + if hint > 0 then + table.insert(parts, string.format('%%#DiagnosticHint#H%d%%*', hint)) + end + + if info > 0 then + table.insert(parts, string.format('%%#DiagnosticInfo#I%d%%*', info)) + end + + return table.concat(parts, " ") +end + +vim.opt.statusline = " %f%4( %m%) %{%v:lua._status_line_git()%} %=" + .. " %{%v:lua._status_line_diagnostics()%} " + .. " %{&filetype} %-6.6{&fileencoding}" + .. " %-4.4{&fileformat} %4.4(%p%%%)%5.5l:%-3.3v" + +vim.cmd("syntax on") +vim.cmd("filetype plugin indent on") diff --git a/lua/core/user_commands.lua b/lua/core/user_commands.lua deleted file mode 100644 index 196ef67..0000000 --- a/lua/core/user_commands.lua +++ /dev/null @@ -1,42 +0,0 @@ -local module_name = "core.user_commands" -local utils = require("utils") - -vim.api.nvim_create_user_command("Update", function(_) - local lazy = utils.try_require("lazy") - if lazy then - lazy.update() - end - - local treesitter_install = utils.try_require("nvim-treesitter.install") - if treesitter_install then - treesitter_install.update({ with_sync = true })("all") - end - - local mason_update_all = utils.try_require("mason-update-all") - if mason_update_all then - mason_update_all.update_all() - end -end, { - desc = "Update lazy plugins, treesitter parsers and mason language servers", - force = false, -}) - -vim.api.nvim_create_user_command("Cmake", function(ctx) - local args = ctx.fargs - if vim.tbl_isempty(args) then - args = { "--build", "build" } - end - - local mp = vim.o.makeprg - vim.o.makeprg = "cmake" - local ok, res = pcall(vim.cmd.make, { args = args, bang = ctx.bang }) - vim.o.makeprg = mp - - if not ok then - utils.err(res) - end -end, { - desc = "Like :make, but for CMake", - force = false, - nargs = "*", -}) diff --git a/lua/plugins/bufdelete.lua b/lua/plugins/bufdelete.lua deleted file mode 100644 index baccb72..0000000 --- a/lua/plugins/bufdelete.lua +++ /dev/null @@ -1,9 +0,0 @@ --- https://github.com/famiu/bufdelete.nvim - ----@type LazyPluginSpec -return { - "famiu/bufdelete.nvim", - keys = { - { "q", vim.cmd.Bwipeout, { remap = false, silent = true }, mode = "n" }, - }, -} diff --git a/lua/plugins/grapple.lua b/lua/plugins/grapple.lua deleted file mode 100644 index 161a45e..0000000 --- a/lua/plugins/grapple.lua +++ /dev/null @@ -1,40 +0,0 @@ --- https://github.com/cbochs/grapple.nvim - ----@type LazyPluginSpec -return { - "cbochs/grapple.nvim", - dependencies = { "nvim-lua/plenary.nvim" }, - config = function() - local grapple = require("grapple") - grapple.setup() - vim.keymap.set("n", "'", grapple.toggle_tags) - vim.keymap.set("n", "mm", function() - if grapple.exists() then - grapple.untag() - return - end - - for i = 1, 9 do - local opts = { name = "m" .. i } - if not grapple.exists(opts) then - grapple.tag(opts) - return - end - end - - grapple.tag({ name = "m0" }) - end) - - for i = 1, 9 do - local opts = { name = "m" .. i } - - vim.keymap.set("n", "m" .. i, function() - grapple.tag(opts) - end) - - vim.keymap.set("n", "" .. i, function() - grapple.select(opts) - end) - end - end, -} diff --git a/lua/plugins/lsp-inlayhints.lua b/lua/plugins/lsp-inlayhints.lua deleted file mode 100644 index 3a8dc9e..0000000 --- a/lua/plugins/lsp-inlayhints.lua +++ /dev/null @@ -1,8 +0,0 @@ --- https://github.com/lvimuser/lsp-inlayhints.nvim - ----@type LazyPluginSpec -return { - "lvimuser/lsp-inlayhints.nvim", - branch = "anticonceal", - config = true, -} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua deleted file mode 100644 index 0db3954..0000000 --- a/lua/plugins/lualine.lua +++ /dev/null @@ -1,41 +0,0 @@ --- https://github.com/nvim-lualine/lualine.nvim - ----@type LazyPluginSpec -return { - "nvim-lualine/lualine.nvim", - event = "VeryLazy", - config = function() - local custom_moonfly = require("lualine.themes.moonfly") - custom_moonfly.normal.c.bg = require("moonfly").palette.bg - - require("lualine").setup({ - options = { - icons_enabled = false, - theme = custom_moonfly, - component_separators = { left = "", right = "" }, - section_separators = { left = "", right = "" }, - always_divide_middle = true, - globalstatus = true, - }, - sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { - { "filename", path = 1 }, - { "diff" }, - { "diagnostics", sources = { "nvim_diagnostic" } }, - { require("grapple").statusline, cond = require("grapple").exists }, - }, - lualine_x = { - "bo:filetype", - "encoding", - "bo:fileformat", - "progress", - "location", - }, - lualine_y = {}, - lualine_z = {}, - }, - }) - end, -} diff --git a/lua/plugins/winresizer.lua b/lua/plugins/winresizer.lua deleted file mode 100644 index 1cb6736..0000000 --- a/lua/plugins/winresizer.lua +++ /dev/null @@ -1,14 +0,0 @@ --- https://github.com/simeji/winresizer - ----@type LazyPluginSpec -return { - "simeji/winresizer", - keys = { - { "r", vim.cmd.WinResizerStartResize, mode = "n" }, - }, - init = function() - vim.g.winresizer_vert_resize = "5" - vim.g.winresizer_horiz_resize = "5" - vim.g.winresizer_start_key = "" - end, -} diff --git a/lua/plugins/winshift.lua b/lua/plugins/winshift.lua deleted file mode 100644 index 0af4e1c..0000000 --- a/lua/plugins/winshift.lua +++ /dev/null @@ -1,9 +0,0 @@ --- https://github.com/sindrets/winshift.nvim - ----@type LazyPluginSpec -return { - "sindrets/winshift.nvim", - keys = { - { "m", vim.cmd.WinShift, mode = "n" }, - }, -}