From d84f20edf0e2d60adedd0eb0fa480e4b34531158 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Fri, 24 Oct 2025 08:18:51 +0200 Subject: [PATCH] feat(nvim): clean configuration --- nvim/.config/nvim/lua/plugins/lint.lua | 2 +- nvim/.config/nvim/lua/plugins/lsp.lua | 12 +++- nvim/.config/nvim/lua/plugins/telescope.lua | 70 ++++++++++++-------- nvim/.config/nvim/lua/plugins/treesitter.lua | 43 ++++++------ nvim/.config/nvim/lua/settings.lua | 65 +++++++++--------- 5 files changed, 105 insertions(+), 87 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/lint.lua b/nvim/.config/nvim/lua/plugins/lint.lua index 16302a2..ff72e13 100644 --- a/nvim/.config/nvim/lua/plugins/lint.lua +++ b/nvim/.config/nvim/lua/plugins/lint.lua @@ -12,7 +12,7 @@ return { typescript = { "eslint_d" }, javascriptreact = { "eslint_d" }, typescriptreact = { "eslint_d" }, - python = { "flake8" }, + python = { "ruff" }, } local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true }) diff --git a/nvim/.config/nvim/lua/plugins/lsp.lua b/nvim/.config/nvim/lua/plugins/lsp.lua index cbff9aa..b72cb86 100644 --- a/nvim/.config/nvim/lua/plugins/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -10,9 +10,15 @@ return { config = function() local lsp_zero = require("lsp-zero") lsp_zero.on_attach(function(client, bufnr) - -- see :help lsp-zero-keybindings - -- to learn the available actions - lsp_zero.default_keymaps({ buffer = bufnr }) + local opts = { buffer = bufnr, silent = true } + + vim.keymap.set("n", "gd", vim.lsp.buf.definition, vim.tbl_extend("force", opts, { desc = "Go to definition" })) + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, vim.tbl_extend("force", opts, { desc = "Go to declaration" })) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, vim.tbl_extend("force", opts, { desc = "Go to implementation" })) + vim.keymap.set("n", "gr", vim.lsp.buf.references, vim.tbl_extend("force", opts, { desc = "Show references" })) + vim.keymap.set("n", "K", vim.lsp.buf.hover, vim.tbl_extend("force", opts, { desc = "Hover documentation" })) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, vim.tbl_extend("force", opts, { desc = "Rename symbol" })) + vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, vim.tbl_extend("force", opts, { desc = "Code action" })) end) require("mason").setup({}) diff --git a/nvim/.config/nvim/lua/plugins/telescope.lua b/nvim/.config/nvim/lua/plugins/telescope.lua index de827a7..44d2488 100644 --- a/nvim/.config/nvim/lua/plugins/telescope.lua +++ b/nvim/.config/nvim/lua/plugins/telescope.lua @@ -1,7 +1,13 @@ return { "nvim-telescope/telescope.nvim", branch = "0.1.x", - dependencies = { "nvim-lua/plenary.nvim" }, + dependencies = { + "nvim-lua/plenary.nvim", + { + "nvim-telescope/telescope-fzf-native.nvim", + build = "make", + }, + }, opts = { defaults = { file_ignore_patterns = { "**/*.pdf" }, @@ -15,37 +21,45 @@ return { height = 0.80, preview_cutoff = 120, }, - sorting_strategy = "ascending", - borderchars = { "█", "█", "█", "█", "█", "█", "█", "█" }, - prompt_prefix = " 🔍 ", - selection_caret = " ➜ ", - entry_prefix = " ", - winblend = 0, - results_title = "", - prompt_title = "", - preview_title = "", - mappings = { - i = { - [""] = require("telescope.actions").delete_buffer, + sorting_strategy = "ascending", + borderchars = { "█", "█", "█", "█", "█", "█", "█", "█" }, + prompt_prefix = " 🔍 ", + selection_caret = " ➜ ", + entry_prefix = " ", + winblend = 0, + results_title = "", + prompt_title = "", + preview_title = "", + mappings = { + i = { + [""] = require("telescope.actions").delete_buffer, + }, + n = { + [""] = require("telescope.actions").delete_buffer, + }, }, - n = { - [""] = require("telescope.actions").delete_buffer, - }, - }, }, }, config = function(_, opts) - require("telescope").setup(opts) - vim.api.nvim_set_hl(0, "TelescopeNormal", { bg = "#3c3836" }) - vim.api.nvim_set_hl(0, "TelescopePromptNormal", { bg = "#3c3836" }) - vim.api.nvim_set_hl(0, "TelescopeResultsNormal", { bg = "#3c3836" }) - vim.api.nvim_set_hl(0, "TelescopePreviewNormal", { bg = "#3c3836" }) - vim.api.nvim_set_hl(0, "TelescopePromptBorder", { fg = "#3c3836", bg = "#3c3836" }) - vim.api.nvim_set_hl(0, "TelescopeResultsBorder", { fg = "#3c3836", bg = "#3c3836" }) - vim.api.nvim_set_hl(0, "TelescopePreviewBorder", { fg = "#3c3836", bg = "#3c3836" }) - vim.api.nvim_set_hl(0, "TelescopePromptTitle", { fg = "#3c3836", bg = "#3c3836" }) - vim.api.nvim_set_hl(0, "TelescopeResultsTitle", { fg = "#3c3836", bg = "#3c3836" }) - vim.api.nvim_set_hl(0, "TelescopePreviewTitle", { fg = "#3c3836", bg = "#3c3836" }) + local telescope = require("telescope") + telescope.setup(opts) + telescope.load_extension("fzf") + + local bg = vim.api.nvim_get_hl(0, { name = "CursorColumn" }).bg + if type(bg) == "number" then + bg = string.format("#%06x", bg) + end + + vim.api.nvim_set_hl(0, "TelescopeNormal", { bg = bg }) + vim.api.nvim_set_hl(0, "TelescopePromptNormal", { bg = bg }) + vim.api.nvim_set_hl(0, "TelescopeResultsNormal", { bg = bg }) + vim.api.nvim_set_hl(0, "TelescopePreviewNormal", { bg = bg }) + vim.api.nvim_set_hl(0, "TelescopePromptBorder", { fg = bg, bg = bg }) + vim.api.nvim_set_hl(0, "TelescopeResultsBorder", { fg = bg, bg = bg }) + vim.api.nvim_set_hl(0, "TelescopePreviewBorder", { fg = bg, bg = bg }) + vim.api.nvim_set_hl(0, "TelescopePromptTitle", { fg = bg, bg = bg }) + vim.api.nvim_set_hl(0, "TelescopeResultsTitle", { fg = bg, bg = bg }) + vim.api.nvim_set_hl(0, "TelescopePreviewTitle", { fg = bg, bg = bg }) end, keys = { { "ff", "Telescope find_files", desc = "Find files" }, diff --git a/nvim/.config/nvim/lua/plugins/treesitter.lua b/nvim/.config/nvim/lua/plugins/treesitter.lua index c439fe4..400b028 100644 --- a/nvim/.config/nvim/lua/plugins/treesitter.lua +++ b/nvim/.config/nvim/lua/plugins/treesitter.lua @@ -4,26 +4,29 @@ return { config = function() local configs = require("nvim-treesitter.configs") - configs.setup({ - ensure_installed = { - "lua", - "vim", - "vimdoc", - "javascript", - "html", - "python", - "dockerfile", - "latex", - "yaml", - "regex", - "bash", - "markdown", - "markdown_inline", - }, - sync_install = false, - highlight = { enable = false }, - indent = { enable = true }, - }) + configs.setup({ + ensure_installed = { + "lua", + "vim", + "vimdoc", + "javascript", + "html", + "python", + "dockerfile", + "latex", + "yaml", + "regex", + "bash", + "markdown", + "markdown_inline", + }, + sync_install = false, + highlight = { + enable = true, + disable = { "latex" }, + }, + indent = { enable = true }, + }) end, -- opts = function(_, opts) -- vim.treesitter.language.register("markdown", "mdx") diff --git a/nvim/.config/nvim/lua/settings.lua b/nvim/.config/nvim/lua/settings.lua index 67bb0f7..74538d5 100644 --- a/nvim/.config/nvim/lua/settings.lua +++ b/nvim/.config/nvim/lua/settings.lua @@ -1,46 +1,43 @@ -local cmd = vim.cmd -- execute Vim commands -local exec = vim.api.nvim_exec -- execute Vimscript --- local fn = vim.fn -- call Vim functions -local g = vim.g -- global variables -local opt = vim.opt -- global/buffer/windows-scoped options +local cmd = vim.cmd +local exec = vim.api.nvim_exec +local g = vim.g +local opt = vim.opt -g.showmode = true -g.hidden = true -- Required to keep multiple buffers open multiple buffers -opt.mouse = 'a' -- enable mouse -opt.clipboard = 'unnamedplus' -- copy/paste with system -opt.swapfile = false -- no swapfile +opt.mouse = 'a' +opt.clipboard = 'unnamedplus' +opt.swapfile = false -opt.wrap = true -- Display long lines as just one line -opt.expandtab = true -- Use space instead of tabs -opt.tabstop = 4 -- Insert 4 spaces for a tab -opt.shiftwidth = 4 -- Change the number of space characters inserted for indentation -opt.smarttab = true -- Makes tabbing smarter will realize you have 2 vs 4 -opt.autoindent = true -- Good auto indent -opt.foldmethod='indent' +opt.wrap = true +opt.expandtab = true +opt.tabstop = 4 +opt.shiftwidth = 4 +opt.smarttab = true +opt.autoindent = true +opt.foldmethod = 'indent' -opt.number = true -- show line number -opt.relativenumber = true -- show relative line number -opt.cursorline = true -- highlight current line +opt.number = true +opt.relativenumber = true +opt.cursorline = true -opt.scrolloff = 8 -- Keep 8 lines visible above/below cursor -opt.ignorecase = true -- Ignore case on search -opt.smartcase = true -- ignore lowercse for the whoel pattern +opt.scrolloff = 8 +opt.ignorecase = true +opt.smartcase = true -opt.completeopt = 'menuone,noselect,noinsert' -- completion options +opt.completeopt = 'menuone,noselect,noinsert' -opt.spell = true -opt.spelllang = {'fr', 'en'} +vim.api.nvim_create_autocmd("FileType", { + pattern = { "markdown", "text", "tex", "gitcommit" }, + callback = function() + vim.opt_local.spell = true + vim.opt_local.spelllang = { "fr", "en" } + end, +}) opt.nrformats = opt.nrformats + 'alpha' +opt.showmatch = true -g.showtabline = true - --- don't auto commenting new lines cmd[[au BufEnter * set fo-=c fo-=r fo-=o]] -opt.showmatch = true -- show parenthethis match - --- Highlight on yank exec([[ augroup YankHighlight autocmd! @@ -48,6 +45,4 @@ exec([[ augroup end ]], false) - --- Python 3 -g.python3_host_prog="~/.venv/nvim/bin/python" +g.python3_host_prog = vim.fn.expand("~/.venv/nvim/bin/python")