From 2b2ce07edc5e8eb5b9e4cffc234abe4cdc8512f6 Mon Sep 17 00:00:00 2001 From: wholteza Date: Sat, 14 Mar 2026 11:38:01 +0100 Subject: [PATCH] Continuing on new nvim stepu --- .config/nvim/init.lua | 168 ++++++++++++++++++++++++------- .config/nvim/nvim-pack-lock.json | 12 +++ 2 files changed, 143 insertions(+), 37 deletions(-) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 9ced6e5..a9cfde0 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,20 +1,28 @@ -- SECTION: Options -vim.o.number = true -- Show line numbers -vim.o.wrap = true -- Soft-wrap lines -vim.o.tabstop = 2 -- 2 space tab width -vim.o.shiftwidth = 2 -- 2 space tab width -vim.o.swapfile = false -- Disable swap files (annoying) -vim.o.undofile = true -- Enable undo between sessions -vim.o.mouse = 'a' -- Enable mouse support -vim.o.showmode = false -- Don't show mode in status bar -vim.o.inccommand = 'split' -- Preview replace commands inline -vim.o.scrolloff = 20 -- Scroll if cursor is X lines to edge -vim.o.confirm = true -- Add confirmation on some destructive actions -vim.o.ignorecase = true -- Case insensitive search -vim.o.smartcase = true -- Case sensitive when caps is used -vim.o.cursorline = true -- Highlight current line +vim.o.number = true -- Show line numbers +vim.o.wrap = true -- Soft-wrap lines +vim.o.tabstop = 2 -- 2 space tab width +vim.o.shiftwidth = 2 -- 2 space tab width +vim.o.swapfile = false -- Disable swap files (annoying) +vim.o.undofile = true -- Enable undo between sessions +vim.o.mouse = 'a' -- Enable mouse support +vim.o.showmode = false -- Don't show mode in status bar +vim.o.inccommand = 'split' -- Preview replace commands inline +vim.o.scrolloff = 20 -- Scroll if cursor is X lines to edge +vim.o.confirm = true -- Add confirmation on some destructive actions +vim.o.ignorecase = true -- Case insensitive search +vim.o.smartcase = true -- Case sensitive when caps is used +vim.o.cursorline = true -- Highlight current line +vim.o.winborder = "single" -- Borders around popups like when you press leader for keybinds vim.opt.signcolumn = -'yes' -- TEST: Prohibit layout shifting by always showing the sign column (left of line numbers), you should see an icon there on this row. +'yes' -- TEST: Prohibit layout shifting by always showing the sign column (left of line numbers), you should see an icon there on this row. +vim.o.autocomplete = true -- Turn on builtin autocomplete +vim.o.complete = "o,.,w,b,u" -- Indicates what kind of items to show in the autocomplete +vim.o.completeopt = "fuzzy,menuone,noselect,popup" -- Options for autocomplete +vim.o.pumheight = 7 -- Max items to show in autocomplete +vim.o.pummaxwidth = 80 -- Max width of autocomplete +vim.o.updatetime = 250 +vim.o.timeoutlen = 300 -- SECTION: Globals vim.g.mapleader = ' ' -- Mapping leader to space. @@ -38,12 +46,6 @@ vim.keymap.set('n', 'r', ':restart') -- Lets you use ESC to stop highlighting text that you have searched with '/' vim.keymap.set('n', '', 'nohlsearch') --- Lets you move focus from the current window to another. -vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) - -- Format the current buffer using the active lsp vim.keymap.set('n', 'f', vim.lsp.buf.format, { desc = "Format buffer" }) @@ -51,18 +53,25 @@ vim.keymap.set('n', 'f', vim.lsp.buf.format, { desc = "Format buffer" }) vim.keymap.set('n', 'sf', ":Pick files", { desc = "Search files" }) vim.keymap.set('n', 'sg', ":Pick grep_live", { desc = "Search files" }) +-- Get help with keybinds +vim.keymap.set('n', '?', ":WhichKey", { desc = "Show keybinds" }) + -- SECTION: Install packages vim.pack.add({ - 'https://github.com/catppuccin/nvim', -- color scheme - 'https://github.com/nvim-mini/mini.pick', -- File picker, grep - 'https://github.com/nvim-mini/mini.pairs', -- Auto create {}, (), [] - pairs etc. - 'https://github.com/nvim-mini/mini.notify', -- Popup notifications - 'https://github.com/neovim/nvim-lspconfig', -- Language servers - 'https://github.com/mason-org/mason.nvim', -- LSP deps installer - 'https://github.com/folke/lazydev.nvim', -- Automatically resolve vim api paths. - 'https://github.com/folke/which-key.nvim', -- Shortcut hints (bar at the bottom when pressing space) - 'https://github.com/nvim-lua/plenary.nvim', -- Helper lua functions, dep of todo-comments. - 'https://github.com/folke/todo-comments.nvim' -- Helper lua functions, dep of todo-comments. + 'https://github.com/catppuccin/nvim', -- color scheme + 'https://github.com/nvim-mini/mini.pick', -- File picker, grep + 'https://github.com/nvim-mini/mini.pairs', -- Auto create {}, (), [] - pairs etc. + 'https://github.com/nvim-mini/mini.notify', -- Popup notifications + 'https://github.com/neovim/nvim-lspconfig', -- Language servers + 'https://github.com/mason-org/mason.nvim', -- LSP deps installer + 'https://github.com/mason-org/mason-lspconfig.nvim', -- Lets you install mason tooling using lsp names + 'https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim', -- Automatically install mason tooling + 'https://github.com/folke/lazydev.nvim', -- Automatically resolve vim api paths. + 'https://github.com/folke/which-key.nvim', -- Shortcut hints (bar at the bottom when pressing space) + 'https://github.com/nvim-lua/plenary.nvim', -- Helper lua functions, dep of todo-comments. + 'https://github.com/folke/todo-comments.nvim', -- Helper lua functions, dep of todo-comments. + 'https://github.com/nvim-treesitter/nvim-treesitter', + }) -- SECTION: Colorscheme @@ -72,7 +81,14 @@ vim.cmd("colorscheme catppuccin-mocha") -- Folke require("lazydev").setup() -require('which-key').setup() + +local wk = require('which-key') +wk.setup() +wk.add({ + { 's', group = '[S]earch' }, + { 'o', group = 'Source current file', mode = { 'n' } }, +}) + require('todo-comments').setup({ keywords = { SECTION = { @@ -87,14 +103,24 @@ require('mini.pick').setup() require('mini.pairs').setup() require('mini.notify').setup() +require('nvim-treesitter').setup({ + auto_install = true +}) + -- LSP Language Server -require("mason").setup({ +require("mason").setup() +require("mason-lspconfig").setup({ + -- Install lsp deps here + ensure_installed = { 'lua_ls' }, + automatic_enable = true +}) +require("mason-tool-installer").setup({ + -- Install deps of lsp deps here ensure_installed = { - 'lua-language-server', + 'tree-sitter-cli', + 'markdownlint' } }) -vim.lsp.config('lua_ls', {}) -vim.lsp.enable('lua_ls') -- SECTION: Autocommands vim.api.nvim_create_autocmd('TextYankPost', { @@ -105,11 +131,27 @@ vim.api.nvim_create_autocmd('TextYankPost', { end, }) --- Autoformat on save +-- Actions on LspAttach vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('my.lsp', {}), callback = function(ev) + -- INFO: Helpers + local function client_supports_method(client, method, bufnr) + if vim.fn.has 'nvim-0.11' == 1 then + return client:supports_method(method, bufnr) + else + return client.supports_method(method, { bufnr = bufnr }) + end + end + local client = assert(vim.lsp.get_client_by_id(ev.data.client_id)) + + -- Enable auto-completion + if client:supports_method('textDocument/completion') then + vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true }) + end + -- Auto-format ("lint") on save. + -- Usually not needed if server supports "textDocument/willSaveWaitUntil". if not client:supports_method('textDocument/willSaveWaitUntil') and client:supports_method('textDocument/formatting') then vim.api.nvim_create_autocmd('BufWritePre', { @@ -120,5 +162,57 @@ vim.api.nvim_create_autocmd('LspAttach', { end, }) end + + -- Highlight the word you are standing on after a little while + if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, ev.buf) then + local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) + vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { + buffer = ev.buf, + group = highlight_augroup, + callback = vim.lsp.buf.document_highlight, + }) + + vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + buffer = ev.buf, + group = highlight_augroup, + callback = vim.lsp.buf.clear_references, + }) + + vim.api.nvim_create_autocmd('LspDetach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), + callback = function(event2) + vim.lsp.buf.clear_references() + vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } + end, + }) + end + + -- Swap out the icons in the leftmost column and show inlay hints + vim.diagnostic.config { + severity_sort = true, + float = { border = 'rounded', source = 'if_many' }, + underline = { severity = vim.diagnostic.severity.ERROR }, + signs = vim.g.have_nerd_font and { + text = { + [vim.diagnostic.severity.ERROR] = '󰅚 ', + [vim.diagnostic.severity.WARN] = '󰀪 ', + [vim.diagnostic.severity.INFO] = '󰋽 ', + [vim.diagnostic.severity.HINT] = '󰌶 ', + }, + } or {}, + virtual_text = { + source = 'if_many', + spacing = 2, + format = function(diagnostic) + local diagnostic_message = { + [vim.diagnostic.severity.ERROR] = diagnostic.message, + [vim.diagnostic.severity.WARN] = diagnostic.message, + [vim.diagnostic.severity.INFO] = diagnostic.message, + [vim.diagnostic.severity.HINT] = diagnostic.message, + } + return diagnostic_message[diagnostic.severity] + end, + }, + } end, }) diff --git a/.config/nvim/nvim-pack-lock.json b/.config/nvim/nvim-pack-lock.json index adea26b..a8c566f 100644 --- a/.config/nvim/nvim-pack-lock.json +++ b/.config/nvim/nvim-pack-lock.json @@ -8,6 +8,14 @@ "rev": "5231c62aa83c2f8dc8e7ba957aa77098cda1257d", "src": "https://github.com/folke/lazydev.nvim" }, + "mason-lspconfig.nvim": { + "rev": "a676ab7282da8d651e175118bcf54483ca11e46d", + "src": "https://github.com/mason-org/mason-lspconfig.nvim" + }, + "mason-tool-installer.nvim": { + "rev": "443f1ef8b5e6bf47045cb2217b6f748a223cf7dc", + "src": "https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim" + }, "mason.nvim": { "rev": "44d1e90e1f66e077268191e3ee9d2ac97cc18e65", "src": "https://github.com/mason-org/mason.nvim" @@ -36,6 +44,10 @@ "rev": "883c6495b53fccbd35d0938aac8bdf72f6d499c0", "src": "https://github.com/neovim/nvim-lspconfig" }, + "nvim-treesitter": { + "rev": "eb1f8e80cb28eb7892f347609e0bdc5eb574b945", + "src": "https://github.com/nvim-treesitter/nvim-treesitter" + }, "plenary.nvim": { "rev": "b9fd5226c2f76c951fc8ed5923d85e4de065e509", "src": "https://github.com/nvim-lua/plenary.nvim"