From 1bf3a84fd03958a746ecd24133c93ea46524e0b9 Mon Sep 17 00:00:00 2001 From: Tibeuleu Date: Tue, 9 Jun 2026 17:13:34 +0200 Subject: [PATCH] update and optimize nvim --- .config/nvim/after/plugin/comment.lua | 2 +- .config/nvim/after/plugin/lsp.lua | 4 +- .config/nvim/after/plugin/treesitter.lua | 49 +++++------ .config/nvim/lua/config/pckr.lua | 107 ++++++++++++----------- .config/nvim/lua/config/remap.lua | 92 +++++++++---------- .config/nvim/old_init.vim | 7 +- 6 files changed, 137 insertions(+), 124 deletions(-) diff --git a/.config/nvim/after/plugin/comment.lua b/.config/nvim/after/plugin/comment.lua index 969032f..485936f 100644 --- a/.config/nvim/after/plugin/comment.lua +++ b/.config/nvim/after/plugin/comment.lua @@ -1,7 +1,7 @@ require("ts_context_commentstring").setup({ enable_autocmd = false, }) -require('Comment').setup({ +require('mini.comment').setup({ ignore = '^$', -- Ignore empty lines pre_hook = require("ts_context_commentstring.integrations.comment_nvim").create_pre_hook(), }) diff --git a/.config/nvim/after/plugin/lsp.lua b/.config/nvim/after/plugin/lsp.lua index 5cc42de..bb9a8ff 100644 --- a/.config/nvim/after/plugin/lsp.lua +++ b/.config/nvim/after/plugin/lsp.lua @@ -106,8 +106,8 @@ local servers = { -- Default handlers for LSP local default_handlers = { - ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }), - ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded", focus = false }), + ["textDocument/hover"] = vim.lsp.buf.hover({ border = "rounded" }), + ["textDocument/signatureHelp"] = vim.lsp.buf.signature_help({ border = "rounded", focus = false }), } -- nvim-cmp supports additional completion capabilities diff --git a/.config/nvim/after/plugin/treesitter.lua b/.config/nvim/after/plugin/treesitter.lua index 2c62a2c..5549cd9 100644 --- a/.config/nvim/after/plugin/treesitter.lua +++ b/.config/nvim/after/plugin/treesitter.lua @@ -1,27 +1,27 @@ -require'nvim-treesitter.configs'.setup { - -- A list of parser names, or "all" (the five listed parsers should always be installed) - ensure_installed = { "bash", "bibtex", "c", "cpp", "lua", "markdown", "python", "vim", "vimdoc" }, +require 'nvim-treesitter'.setup { + -- A list of parser names, or "all" (the five listed parsers should always be installed) + ensure_installed = { "bash", "bibtex", "c", "cpp", "lua", "markdown", "python", "vim", "vimdoc" }, - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, - -- Automatically install missing parsers when entering buffer - -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally - auto_install = true, + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + auto_install = true, - ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) - -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! + ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) + -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! - highlight = { - enable = true, + highlight = { + enable = true, - -- Setting this to true will run `:h syntax` and tree-sitter at the same time. - -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). - -- Using this option may slow down your editor, and you may see some duplicate highlights. - -- Instead of true it can also be a list of languages - disable = {"latex"}, - additional_vim_regex_highlighting = false, - }, + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + disable = { "latex" }, + additional_vim_regex_highlighting = false, + }, } local vim = vim @@ -36,21 +36,20 @@ opt.foldexpr = "nvim_treesitter#foldexpr()" -------- This function is taken from https://github.com/norcalli/nvim_utils function M.nvim_create_augroups(definitions) for group_name, definition in pairs(definitions) do - api.nvim_command('augroup '..group_name) + api.nvim_command('augroup ' .. group_name) api.nvim_command('autocmd!') for _, def in ipairs(definition) do - local command = table.concat(vim.iter{'autocmd', def}:flatten():totable(), ' ') + local command = table.concat(vim.iter { 'autocmd', def }:flatten():totable(), ' ') api.nvim_command(command) end api.nvim_command('augroup END') end end - local autoCommands = { -- other autocommands open_folds = { - {"BufReadPost,FileReadPost", "*", "normal zR"} + { "BufReadPost,FileReadPost", "*", "normal zR" } } } @@ -61,8 +60,8 @@ vim.o.foldexpr = 'v:lua.vim.treesitter.foldexpr()' -- Prefer LSP folding if client supports it vim.api.nvim_create_autocmd('LspAttach', { callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - if client:supports_method('textDocument/foldingRange') then + local client = vim.lsp.get_client_by_id(args.data.client_id) + if client:supports_method('textDocument/foldingRange') then local win = vim.api.nvim_get_current_win() vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()' end diff --git a/.config/nvim/lua/config/pckr.lua b/.config/nvim/lua/config/pckr.lua index 073bd48..1267c73 100644 --- a/.config/nvim/lua/config/pckr.lua +++ b/.config/nvim/lua/config/pckr.lua @@ -1,71 +1,80 @@ local function bootstrap_pckr() - local pckr_path = vim.fn.stdpath("data") .. "/pckr/pckr.nvim" + local pckr_path = vim.fn.stdpath("data") .. "/pckr/pckr.nvim" - if not (vim.uv or vim.loop).fs_stat(pckr_path) then - vim.fn.system({ - 'git', - 'clone', - "--filter=blob:none", - 'https://github.com/lewis6991/pckr.nvim', - pckr_path - }) - end + if not (vim.uv or vim.loop).fs_stat(pckr_path) then + vim.fn.system({ + 'git', + 'clone', + "--filter=blob:none", + 'https://github.com/lewis6991/pckr.nvim', + pckr_path + }) + end - vim.opt.rtp:prepend(pckr_path) + vim.opt.rtp:prepend(pckr_path) end bootstrap_pckr() -require('pckr').add{ +require('pckr').add { { 'nvim-telescope/telescope.nvim', - tag = '0.1.1', - -- or branch = '0.1.x', - requires = { {'nvim-lua/plenary.nvim'} } - }; - "ellisonleao/gruvbox.nvim"; + version = '*', + requires = { + { 'nvim-lua/plenary.nvim' }, + { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' }, + } + }, + "ellisonleao/gruvbox.nvim", { 'nvim-treesitter/nvim-treesitter', - run = function() - local ts_update = require('nvim-treesitter.install').update({ with_sync = true }) - ts_update() - end, - }; + branch = "main", + build = ':TSUpdate' + }, { 'ThePrimeagen/harpoon', - requires = { {'nvim-lua/plenary.nvim'} } - }; - 'mbbill/undotree'; - 'tpope/vim-fugitive'; - 'airblade/vim-gitgutter'; - 'lukas-reineke/indent-blankline.nvim'; - 'JoosepAlviste/nvim-ts-context-commentstring'; - 'numToStr/Comment.nvim'; - 'lervag/vimtex'; + requires = { { 'nvim-lua/plenary.nvim' } } + }, + 'mbbill/undotree', + 'tpope/vim-fugitive', + 'airblade/vim-gitgutter', + 'lukas-reineke/indent-blankline.nvim', + 'JoosepAlviste/nvim-ts-context-commentstring', + { + 'nvim-mini/mini.comment', + branch = "main", + config = function() + require('mini.comment').setup() + end, + }, + 'lervag/vimtex', { 'neovim/nvim-lspconfig', requires = { -- LSP Support - {'williamboman/mason.nvim'}, - {'williamboman/mason-lspconfig.nvim'}, + { 'williamboman/mason.nvim' }, + { 'williamboman/mason-lspconfig.nvim' }, -- DAP Support - {'mfussenegger/nvim-dap'}, - {'mfussenegger/nvim-dap-python'}, - {'jay-babu/mason-nvim-dap.nvim'}, + { 'mfussenegger/nvim-dap' }, + { 'mfussenegger/nvim-dap-python' }, + { 'jay-babu/mason-nvim-dap.nvim' }, -- Autocompletion - {'hrsh7th/nvim-cmp'}, - {'hrsh7th/cmp-nvim-lsp'}, - {'hrsh7th/cmp-buffer'}, - {'hrsh7th/cmp-path'}, - {'hrsh7th/cmp-cmdline'}, + { 'hrsh7th/nvim-cmp' }, + { 'hrsh7th/cmp-nvim-lsp' }, + { 'hrsh7th/cmp-buffer' }, + { 'hrsh7th/cmp-path' }, + { 'hrsh7th/cmp-cmdline' }, -- Snippets - {'L3MON4D3/LuaSnip'}, - {'saadparwaiz1/cmp_luasnip'}, - {'rafamadriz/friendly-snippets'}, - {'onsails/lspkind.nvim'}, + { + 'L3MON4D3/LuaSnip', + run = "make install_jsregexp", + }, + { 'saadparwaiz1/cmp_luasnip' }, + { 'rafamadriz/friendly-snippets' }, + { 'onsails/lspkind.nvim' }, -- Utils - {'j-hui/fidget.nvim'}, - {'folke/neodev.nvim'} - }; - }; + { 'j-hui/fidget.nvim' }, + { 'folke/neodev.nvim' } + }, + }, } diff --git a/.config/nvim/lua/config/remap.lua b/.config/nvim/lua/config/remap.lua index db3ee7f..63b1cb0 100644 --- a/.config/nvim/lua/config/remap.lua +++ b/.config/nvim/lua/config/remap.lua @@ -11,7 +11,7 @@ vim.g.mapleader = " " vim.g.maplocalleader = ";" -- Set Explorer keybind to leader-"e" -vim.keymap.set("n","e", vim.cmd.Ex) +vim.keymap.set("n", "e", vim.cmd.Ex) -- Disable Space bar since it'll be used as the leader key nnoremap("", "") @@ -37,98 +37,98 @@ nnoremap("cl", "!wc -l %") -- LSP Keybinds (exports a function to be used in ../../after/plugin/lsp.lua b/c we need a reference to the current buffer) -- M.map_lsp_keybinds = function(buffer_number) -- Rename variable - nnoremap("rn", vim.lsp.buf.rename, { desc = "LSP: [R]e[n]ame", buffer = buffer_number }) + nnoremap("rn", vim.lsp.buf.rename, { desc = "LSP: [R]e[n]ame", buffer = buffer_number }) -- LSP code action - nnoremap("ca", vim.lsp.buf.code_action, { desc = "LSP: [C]ode [A]ction", buffer = buffer_number }) + nnoremap("ca", vim.lsp.buf.code_action, { desc = "LSP: [C]ode [A]ction", buffer = buffer_number }) -- Goto definition - nnoremap("gd", vim.lsp.buf.definition, { desc = "LSP: [G]oto [D]efinition", buffer = buffer_number }) + nnoremap("gd", vim.lsp.buf.definition, { desc = "LSP: [G]oto [D]efinition", buffer = buffer_number }) - -- Telescope LSP keybinds -- + -- Telescope LSP keybinds -- -- Goto reference - nnoremap( - "gr", - require("telescope.builtin").lsp_references, - { desc = "LSP: [G]oto [R]eferences", buffer = buffer_number } - ) + nnoremap( + "gr", + require("telescope.builtin").lsp_references, + { desc = "LSP: [G]oto [R]eferences", buffer = buffer_number } + ) -- Goto implementation - nnoremap( - "gi", - require("telescope.builtin").lsp_implementations, - { desc = "LSP: [G]oto [I]mplementation", buffer = buffer_number } - ) + nnoremap( + "gi", + require("telescope.builtin").lsp_implementations, + { desc = "LSP: [G]oto [I]mplementation", buffer = buffer_number } + ) -- List of symbols in the current buffer - nnoremap( - "bs", - require("telescope.builtin").lsp_document_symbols, - { desc = "LSP: [B]uffer [S]ymbols", buffer = buffer_number } - ) + nnoremap( + "bs", + require("telescope.builtin").lsp_document_symbols, + { desc = "LSP: [B]uffer [S]ymbols", buffer = buffer_number } + ) -- List of symbols in the workspace - nnoremap( - "ps", - require("telescope.builtin").lsp_workspace_symbols, - { desc = "LSP: [P]roject [S]ymbols", buffer = buffer_number } - ) + nnoremap( + "ps", + require("telescope.builtin").lsp_workspace_symbols, + { desc = "LSP: [P]roject [S]ymbols", buffer = buffer_number } + ) -- Hover documentation - nnoremap("K", vim.lsp.buf.hover, { desc = "LSP: Hover Documentation", buffer = buffer_number }) + nnoremap("K", vim.lsp.buf.hover, { desc = "LSP: Hover Documentation", buffer = buffer_number }) -- Signature documentation - nnoremap("k", vim.lsp.buf.signature_help, { desc = "LSP: Signature Documentation", buffer = buffer_number }) - inoremap("", vim.lsp.buf.signature_help, { desc = "LSP: Signature Documentation", buffer = buffer_number }) + nnoremap("k", vim.lsp.buf.signature_help, { desc = "LSP: Signature Documentation", buffer = buffer_number }) + inoremap("", vim.lsp.buf.signature_help, { desc = "LSP: Signature Documentation", buffer = buffer_number }) - -- Goto declaration - nnoremap("gD", vim.lsp.buf.declaration, { desc = "LSP: [G]oto [D]eclaration", buffer = buffer_number }) + -- Goto declaration + nnoremap("gD", vim.lsp.buf.declaration, { desc = "LSP: [G]oto [D]eclaration", buffer = buffer_number }) -- Type definition - nnoremap("td", vim.lsp.buf.type_definition, { desc = "LSP: [T]ype [D]efinition", buffer = buffer_number }) + nnoremap("td", vim.lsp.buf.type_definition, { desc = "LSP: [T]ype [D]efinition", buffer = buffer_number }) end -- Goto next diagnostic of any severity nnoremap("]d", function() - vim.diagnostic.goto_next({}) - vim.api.nvim_feedkeys("zz", "n", false) + vim.diagnostic.jump({ count = 1, float = true }) + vim.api.nvim_feedkeys("zz", "n", false) end) -- Goto prev diagnostic of any severity nnoremap("[d", function() - vim.diagnostic.goto_prev({}) - vim.api.nvim_feedkeys("zz", "n", false) + vim.diagnostic.jump({ count = -1, float = true }) + vim.api.nvim_feedkeys("zz", "n", false) end) -- Goto next error diagnostic nnoremap("]e", function() - vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR }) - vim.api.nvim_feedkeys("zz", "n", false) + vim.diagnostic.jump({ severity = vim.diagnostic.severity.ERROR, count = 1, float = true }) + vim.api.nvim_feedkeys("zz", "n", false) end) -- Goto previous error diagnostic nnoremap("[e", function() - vim.diagnostic.goto_prev({ severity = vim.diagnostic.severity.ERROR }) - vim.api.nvim_feedkeys("zz", "n", false) + vim.diagnostic.jump({ severity = vim.diagnostic.severity.ERROR, count = -1, float = true }) + vim.api.nvim_feedkeys("zz", "n", false) end) -- Goto next warning diagnostic nnoremap("]w", function() - vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.WARN }) - vim.api.nvim_feedkeys("zz", "n", false) + vim.diagnostic.jump({ severity = vim.diagnostic.severity.WARN, count = 1, float = true }) + vim.api.nvim_feedkeys("zz", "n", false) end) -- Goto previous warning diagnostic nnoremap("[w", function() - vim.diagnostic.goto_prev({ severity = vim.diagnostic.severity.WARN }) - vim.api.nvim_feedkeys("zz", "n", false) + vim.diagnostic.jump({ severity = vim.diagnostic.severity.WARN, count = -1, float = true }) + vim.api.nvim_feedkeys("zz", "n", false) end) -- Open diagnostic window nnoremap("d", function() - vim.diagnostic.open_float({ - border = "rounded", - }) + vim.diagnostic.open_float({ + border = "rounded", + }) end) return M diff --git a/.config/nvim/old_init.vim b/.config/nvim/old_init.vim index 76e5e20..1c35ec8 100644 --- a/.config/nvim/old_init.vim +++ b/.config/nvim/old_init.vim @@ -11,7 +11,7 @@ autocmd VimLeave *.tex !texclear % " Ensure files are read as what I want: - let g:vimwiki_ext2syntax = {'.Rmd': 'markdown', '.rmd': 'markdown','.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'} + let g:vimwiki_ext2syntax = {'.Rmd': 'markdown', '.rmd': 'markdown','.mdx': 'markdown','.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'} map v :VimwikiIndex let g:vimwiki_list = [{'path': '~/.local/share/nvim/vimwiki', 'syntax': 'markdown', 'ext': '.md'}] autocmd BufRead,BufNewFile /tmp/calcurse*,~/.calcurse/notes/* set filetype=markdown @@ -37,6 +37,11 @@ autocmd BufWritePost ~/.config/i3/config !i3 restart autocmd BufWritePost ~/.config/i3blocks/config !i3 restart +" Remove checkhealth warning for optionnal providers + let g:loaded_node_provider = 0 + let g:loaded_perl_provider = 0 + let g:loaded_ruby_provider = 0 + " Function for toggling the bottom statusbar: let s:hidden_all = 0 function! ToggleHiddenAll()