From 5c4f564ad7c19e09f9c846736c483fb6d91e313f Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Wed, 18 Mar 2026 11:25:57 +0200 Subject: [PATCH] Align MzansiVim to VS code setup --- README.md | 26 +++++++- lazy-lock.json | 3 +- lua/plugins/lsp.lua | 133 ++++++++++++++++++++++---------------- lua/plugins/oneliners.lua | 10 ++- 4 files changed, 115 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 4c165fe..8d6d6a6 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,33 @@ The **Leader Key** is set to `Space`. | :--- | :--- | :--- | | **Hover Docs** | `K` | Display documentation for the symbol under cursor. | | **Go to Definition**| `gd` | Jump to the source code of a function/variable. | +| **Code Actions** | `ca` | Show available fixes or refactors. | +| **Align File** | `rn` | Auto align file. | | **References** | `gr` | List all places where a symbol is used. | | **Rename** | `rn` | Rename all occurrences of the symbol. | -| **Code Actions** | `ca` | Show available fixes or refactors. | + +### Diagnostics (Errors & Warnings) +| Action | Keybinding | Description | +| :--- | :--- | :--- | +| **Show Error** | `e` | Open a floating window with the full error under cursor. | +| **Next Error** | `]d` | Jump to the next diagnostic in the file. | +| **Previous Error** | `[d` | Jump to the previous diagnostic in the file. | +| **Quickfix List** | `q` | Load all diagnostics into the quickfix list. | +| **Close Quickfix** | `:q ` | Close the quickfix window. | + +### Window Management +| Action | Keybinding | Description | +| :--- | :--- | :--- | +| **Cycle Windows** | `Ctrl + w + w` | Cycle focus between open windows (e.g. quickfix ↔ code). | +| **Move Down** | `Ctrl + w + j` | Move focus to the window below. | +| **Move Up** | `Ctrl + w + k` | Move focus to the window above. | +| **Jump & Stay** | `Ctrl + w + Enter` | Open quickfix entry in a split, keeping quickfix focused. | + +### Commenting +| Action | Keybinding | Description | +| :--- | :--- | :--- | +| **Toggle Comment** | `Ctrl + /` | Comment or uncomment the current line (normal mode). | +| **Toggle Comment** | `Ctrl + /` | Comment or uncomment the selection (visual mode). | ### Editor Essentials | Action | Keybinding | Description | diff --git a/lazy-lock.json b/lazy-lock.json index 97a1f72..9c46294 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,9 +1,11 @@ { + "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, "LuaSnip": { "branch": "master", "commit": "dae4f5aaa3574bd0c2b9dd20fb9542a02c10471c" }, "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, "cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" }, "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "dashboard-nvim": { "branch": "master", "commit": "0775e567b6c0be96d01a61795f7b64c1758262f6" }, "dressing.nvim": { "branch": "master", "commit": "2d7c2db2507fa3c4956142ee607431ddb2828639" }, "flutter-tools.nvim": { "branch": "main", "commit": "677cc07c16e8b89999108d2ebeefcfc5f539b73c" }, "harpoon": { "branch": "harpoon2", "commit": "87b1a3506211538f460786c23f98ec63ad9af4e5" }, @@ -16,7 +18,6 @@ "nvim-treesitter": { "branch": "main", "commit": "2cc172c28e5550e00e6beead4599b1469469c1c7" }, "nvim-web-devicons": { "branch": "master", "commit": "d7462543c9e366c0d196c7f67a945eaaf5d99414" }, "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, - "snacks.nvim": { "branch": "main", "commit": "a049339328e2599ad6e85a69fa034ac501e921b2" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6fea601bd2b694c6f2ae08a6c6fab14930c60e2c" }, "telescope.nvim": { "branch": "master", "commit": "3333a52ff548ba0a68af6d8da1e54f9cd96e9179" }, "tokyonight.nvim": { "branch": "main", "commit": "5da1b76e64daf4c5d410f06bcb6b9cb640da7dfd" }, diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 3e071ec..be25a4a 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -11,7 +11,6 @@ return { local mason_lspconfig = require("mason-lspconfig") -- We no longer need: local lspconfig = require("lspconfig") - local capabilities = require("cmp_nvim_lsp").default_capabilities() local servers = { @@ -51,70 +50,96 @@ return { vim.lsp.enable(server_name) end + -- Diagnostic display config + vim.diagnostic.config({ + virtual_text = true, -- show error inline at end of line + signs = true, + underline = true, + update_in_insert = false, -- only update after leaving insert mode + float = { + border = "rounded", + source = true, -- shows which LSP reported the error + }, + }) + -- Keybindings (unchanged) vim.api.nvim_create_autocmd("LspAttach", { - callback = function(ev) - local opts = { buffer = ev.buf } - vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) - vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) - vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) - vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) - vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) - end, + callback = function(ev) + local opts = { buffer = ev.buf } + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) + vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) + -- Diagnostic keymaps + vim.keymap.set("n", "e", vim.diagnostic.open_float, opts) -- show error under cursor + vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous error + vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next error + vim.keymap.set("n", "q", vim.diagnostic.setloclist, opts) -- all errors in quickfix list + vim.keymap.set("n", "af", vim.lsp.buf.format, { desc = "Format file" }) -- manual format + + -- Format on save + vim.api.nvim_create_autocmd("BufWritePre", { + buffer = ev.buf, + callback = function() + vim.lsp.buf.format({ async = false }) + end, + }) + end, }) - end, - }, - { - "nvim-flutter/flutter-tools.nvim", - lazy = false, -- Load on startup to ensure it handles dartls correctly - dependencies = { + end, + }, + { + "nvim-flutter/flutter-tools.nvim", + lazy = false, -- Load on startup to ensure it handles dartls correctly + dependencies = { "nvim-lua/plenary.nvim", "stevearc/dressing.nvim", -- Optional but highly recommended for better UI - }, - config = function() - require("flutter-tools").setup({ - lsp = { - -- Pass your existing capabilities to the flutter-tools LSP config - capabilities = require("cmp_nvim_lsp").default_capabilities(), - -- You can add specific dartls settings here if needed - settings = { - showTodos = true, - completeFunctionCalls = true, - }, - }, - }) - end, }, - { - "hrsh7th/nvim-cmp", - dependencies = { + config = function() + require("flutter-tools").setup({ + lsp = { + -- Pass your existing capabilities to the flutter-tools LSP config + capabilities = require("cmp_nvim_lsp").default_capabilities(), + -- You can add specific dartls settings here if needed + settings = { + showTodos = true, + completeFunctionCalls = true, + }, + }, + }) + end, + }, + { + "hrsh7th/nvim-cmp", + dependencies = { "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", "L3MON4D3/LuaSnip", -- Snippet engine is usually required by cmp configs "saadparwaiz1/cmp_luasnip", - }, - config = function() + }, + config = function() local cmp = require("cmp") cmp.setup({ - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.confirm({ select = true }), - }), - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "luasnip" }, - }, { - { name = "buffer" }, - }), + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.confirm({ select = true }), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + }, { + { name = "buffer" }, + }), }) - end, - }, - } + end, + }, +} diff --git a/lua/plugins/oneliners.lua b/lua/plugins/oneliners.lua index f469a44..eee171d 100644 --- a/lua/plugins/oneliners.lua +++ b/lua/plugins/oneliners.lua @@ -1,6 +1,14 @@ return { - { + { -- Git Plugin 'tpope/vim-fugitive', }, + { + "numToStr/Comment.nvim", + config = function() + require("Comment").setup() + vim.keymap.set("n", "", "gcc", { remap = true, desc = "Toggle comment" }) + vim.keymap.set("v", "", "gc", { remap = true, desc = "Toggle comment" }) + end, + }, }