From 8aeb7e3c877ba41428a6bff2b6be40e67a3ebf9f Mon Sep 17 00:00:00 2001 From: afranco Date: Sun, 16 Mar 2025 01:12:43 +0000 Subject: [PATCH] chore(nvim): a lot of changes --- .config/nvim/.gitignore | 2 +- .config/nvim/init.lua | 1 - .config/nvim/lua/core/package_manager.lua | 33 +++++---- .config/nvim/lua/core/variables.lua | 1 - .config/nvim/lua/plugins/cmp.lua | 16 +++-- .config/nvim/lua/plugins/lsp.lua | 48 ++++++++++++- .config/nvim/lua/plugins/misc.lua | 13 +++- .config/nvim/lua/plugins/picker.lua | 2 +- .config/nvim/lua/plugins/statusline.lua | 24 +++++++ .config/nvim/lua/plugins/treesitter.lua | 9 +++ .config/nvim/lua/plugins/ui.lua | 19 ++--- .config/nvim/lua/winbar.lua | 87 ----------------------- 12 files changed, 135 insertions(+), 120 deletions(-) create mode 100644 .config/nvim/lua/plugins/statusline.lua delete mode 100644 .config/nvim/lua/winbar.lua diff --git a/.config/nvim/.gitignore b/.config/nvim/.gitignore index 648bf93..cb39c01 100644 --- a/.config/nvim/.gitignore +++ b/.config/nvim/.gitignore @@ -1,2 +1,2 @@ -plugin lazy-lock.json +lua/dev diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index fc41d55..d66f680 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -2,5 +2,4 @@ require("core.variables") require("core.keymaps") require("core.autocmds") require('core.package_manager') -require('winbar') require('core.theme') diff --git a/.config/nvim/lua/core/package_manager.lua b/.config/nvim/lua/core/package_manager.lua index 0a78990..8d72c6f 100644 --- a/.config/nvim/lua/core/package_manager.lua +++ b/.config/nvim/lua/core/package_manager.lua @@ -1,18 +1,27 @@ +-- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" - -if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end end - vim.opt.rtp:prepend(lazypath) --Call lazy config here local lazy = require("lazy") -lazy.setup("plugins") +lazy.setup({ + spec = { + { import = "plugins" } + }, + dev = { + path = vim.fn.stdpath("config") .. "/lua/dev" + } +}) diff --git a/.config/nvim/lua/core/variables.lua b/.config/nvim/lua/core/variables.lua index f815f1d..e9c628e 100644 --- a/.config/nvim/lua/core/variables.lua +++ b/.config/nvim/lua/core/variables.lua @@ -47,4 +47,3 @@ vim.opt.signcolumn = "yes" vim.opt.autoread = true -- disable swapfile vim.opt.swapfile = false -vim.opt.laststatus = 3 diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua index f2574bb..a1913fd 100644 --- a/.config/nvim/lua/plugins/cmp.lua +++ b/.config/nvim/lua/plugins/cmp.lua @@ -25,18 +25,26 @@ return { sources = { default = { 'lsp', 'path', 'snippets', 'buffer' }, providers = { - lazydev = { name = "LazyDev", module = "lazydev.integrations.blink", fallbacks = { "lsp" } }, + lazydev = { + name = "LazyDev", + module = "lazydev.integrations.blink", + fallbacks = { "lsp" } + }, }, }, signature = { enabled = true, window = { - max_width = 160, - max_height = 30, - scrollbar = true, show_documentation = false, } }, + cmdline = { + completion = { + menu = { + auto_show = true + } + } + }, completion = { accept = { auto_brackets = { diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index 59cf01e..1ff5fdd 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -117,10 +117,19 @@ return { capabilities = capabilities, filetypes = { 'haskell', 'lhaskell', 'cabal' }, }) - lspconfig["clangd"].setup({ + -- lspconfig["clangd"].setup({ + -- capabilities = capabilities, + -- }) + lspconfig["texlab"].setup({ capabilities = capabilities, }) - lspconfig["texlab"].setup({ + lspconfig["bashls"].setup({ + capabilities = capabilities, + }) + lspconfig["zls"].setup({ + capabilities = capabilities, + }) + lspconfig["pyright"].setup({ capabilities = capabilities, }) end, @@ -165,11 +174,35 @@ return { rust = { "rustfmt" }, go = { "gofmt" }, json = { "jq" }, - bash = { "shfmt" } + bash = { "shfmt", "beautysh" }, + zsh = { "beautysh" } } }) end, }, + { + 'mfussenegger/nvim-lint', + config = function() + local lint = require("lint") + + lint.linters_by_ft = { + go = { "golangcilint" }, + } + + local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true }) + + vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, { + group = lint_augroup, + callback = function() + lint.try_lint() + end, + }) + + vim.keymap.set("n", "li", function() + lint.try_lint() + end, { desc = "Trigger linting for current file" }) + end, + }, { "lervag/vimtex", @@ -180,6 +213,15 @@ return { else vim.g.vimtex_view_method = 'zathura' end + vim.g.vimtex_quickfix_ignore_filters = { + "warning", + "Warning" + } + vim.g.vimtex_quickfix_open_on_warning = 0 + vim.g.vimtex_quickfix_ignore_filters = { + 'Overfull', + 'Underfull', + } vim.g.vimtex_compiler_method = 'latexmk' vim.g.vimtex_compiler_latexmk = { out_dir = 'build', diff --git a/.config/nvim/lua/plugins/misc.lua b/.config/nvim/lua/plugins/misc.lua index bb2c338..4d2182c 100644 --- a/.config/nvim/lua/plugins/misc.lua +++ b/.config/nvim/lua/plugins/misc.lua @@ -25,6 +25,7 @@ return { statuscolumn = { enabled = true }, dashboard = { enabled = true }, input = { enabled = true }, + image = { enabled = true }, lazygit = { vim.keymap.set('n', 'lg', function() Snacks.lazygit.open() @@ -46,5 +47,15 @@ return { end }, "tpope/vim-fugitive", - "pimalaya/himalaya-vim" + { + "afonsofrancof/worktrees.nvim", + dev = true, + opts = { + mappings = { + create = "wtc", + delete = "wtd", + switch = "wts", + } + } + } } diff --git a/.config/nvim/lua/plugins/picker.lua b/.config/nvim/lua/plugins/picker.lua index 4bae661..24479bf 100644 --- a/.config/nvim/lua/plugins/picker.lua +++ b/.config/nvim/lua/plugins/picker.lua @@ -9,7 +9,7 @@ return { fzflua.setup({ defaults = { winopts = { - border = "single", + border = "rounded", width = 0.6, height = 0.5, }, diff --git a/.config/nvim/lua/plugins/statusline.lua b/.config/nvim/lua/plugins/statusline.lua new file mode 100644 index 0000000..0b3d5e7 --- /dev/null +++ b/.config/nvim/lua/plugins/statusline.lua @@ -0,0 +1,24 @@ +return { + { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + opts = { + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_c = { { 'filename', path = 1 } }, + lualine_x = { 'filetype' }, + lualine_y = { 'progress' }, + lualine_z = { 'location' } + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {} + }, + } + } +} diff --git a/.config/nvim/lua/plugins/treesitter.lua b/.config/nvim/lua/plugins/treesitter.lua index e74bd8c..6001626 100644 --- a/.config/nvim/lua/plugins/treesitter.lua +++ b/.config/nvim/lua/plugins/treesitter.lua @@ -19,6 +19,15 @@ return { disable = { "latex" }, use_languagetree = true, }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "gnn", + node_incremental = "grn", + scope_incremental = "grc", + node_decremental = "grm", + }, + }, indent = { enable = true, }, diff --git a/.config/nvim/lua/plugins/ui.lua b/.config/nvim/lua/plugins/ui.lua index e6a41ba..e8c82e5 100644 --- a/.config/nvim/lua/plugins/ui.lua +++ b/.config/nvim/lua/plugins/ui.lua @@ -1,14 +1,14 @@ return { - { - "vimpostor/vim-tpipeline", - config = function() - vim.g.tpipeline_restore = 0 - vim.g.tpipeline_autoembed = 0 - vim.o.laststatus = 0 - vim.g.tpipeline_statusline = '%=%l:%c' - end - }, + -- { + -- "vimpostor/vim-tpipeline", + -- config = function() + -- vim.g.tpipeline_restore = 0 + -- vim.g.tpipeline_autoembed = 0 + -- vim.o.laststatus = 0 + -- vim.g.tpipeline_statusline = '%=%l:%c' + -- end + -- }, { "folke/noice.nvim", event = "VeryLazy", @@ -36,6 +36,7 @@ return { }, { 'kevinhwang91/nvim-ufo', + event = "VeryLazy", dependencies = 'kevinhwang91/promise-async', config = function() vim.o.foldcolumn = '0' diff --git a/.config/nvim/lua/winbar.lua b/.config/nvim/lua/winbar.lua deleted file mode 100644 index 436ea0d..0000000 --- a/.config/nvim/lua/winbar.lua +++ /dev/null @@ -1,87 +0,0 @@ -local folder_icon = "󰉋" - -local M = {} - ---- Window bar that shows the current file path (in a fancy way). ----@return string -function M.render() - -- Get the path and expand variables. - local path = vim.fs.normalize(vim.fn.expand '%:p' --[[@as string]]) - - -- Replace slashes by arrows. - local separator = ' %#WinbarSeparator# ' - - local prefix, prefix_path = '', '' - - -- If the window gets too narrow, shorten the path and drop the prefix. - if vim.api.nvim_win_get_width(0) < math.floor(vim.o.columns / 3) then - path = vim.fn.pathshorten(path) - else - -- For some special folders, add a prefix instead of the full path (making - -- sure to pick the longest prefix). - ---@type table - local special_dirs = { - DOTFILES = "$HOME/.config", - HOME = vim.env.HOME, - PROJECTS = "$HOME/projects", - ["University"] = "$HOME/projects/University", - ["Personal"] = "$HOME/projects/Personal", - } - for dir_name, dir_path in pairs(special_dirs) do - if vim.startswith(path, vim.fs.normalize(dir_path)) and #dir_path > #prefix_path then - prefix, prefix_path = dir_name, dir_path - end - end - if prefix ~= '' then - path = path:gsub('^' .. prefix_path, '') - prefix = string.format('%%#WinBarSpecial#%s %s%s', folder_icon, prefix, separator) - end - end - - -- Remove leading slash. - path = path:gsub('^/', '') - - -- Get the background color of the Normal highlight group - local normal_bg_color = vim.api.nvim_get_hl_by_name('Normal', true).background - -- Get the foreground color of the Normal highlight group - local normal_fg_color = vim.api.nvim_get_hl_by_name('Normal', true).foreground - - -- Convert the RGB color to a hex string - local bg_hex_color = normal_bg_color and string.format('#%06x', normal_bg_color) or 'transparent' - -- Convert the RGB color to a hex string - local fg_hex_color = string.format('#%06x', normal_fg_color) - - -- Define the Winbar highlight group with the same background color - vim.api.nvim_command('highlight Winbar guibg=' .. bg_hex_color) - -- Define the Winbar highlight group with the same foreground color - vim.api.nvim_command('highlight Winbar guifg=' .. fg_hex_color) - - return table.concat { - ' ', - prefix, - table.concat( - vim.iter(vim.split(path, '/')) - :map(function(segment) - return string.format('%%#Winbar#%s', segment) - end):totable(), - separator - ), - } -end - -vim.api.nvim_create_autocmd('BufWinEnter', { - group = vim.api.nvim_create_augroup('mariasolos/winbar', { clear = true }), - desc = 'Attach winbar', - callback = function(args) - if - not vim.api.nvim_win_get_config(0).zindex -- Not a floating window - and vim.bo[args.buf].buftype == '' -- Normal buffer - and vim.api.nvim_buf_get_name(args.buf) ~= '' -- Has a file name - and not vim.wo[0].diff -- Not in diff mode - then - vim.wo.winbar = "%{%v:lua.require'winbar'.render()%}" - end - end, -}) - -return M