From 4a1715446c7dccdaf4f5890447a63a6b44ea535b Mon Sep 17 00:00:00 2001 From: Pratik Tripathy Date: Mon, 16 Dec 2024 19:50:50 +0530 Subject: [PATCH] feat(Neovim): Sensible keymaps, prune plugins, Kickstart.nvim LSP code --- common/.config/nvim/init.lua | 31 +- common/.config/nvim/lua/config/keymaps.lua | 6 + .../nvim/lua/plugins/code-completion.lua | 10 +- common/.config/nvim/lua/plugins/code-db.lua | 8 +- .../.config/nvim/lua/plugins/code-debug.lua | 78 +---- .../.config/nvim/lua/plugins/code-generic.lua | 251 +++++++++++--- common/.config/nvim/lua/plugins/code-git.lua | 13 - common/.config/nvim/lua/plugins/code-lsp.lua | 305 +++++++++++------- .../nvim/lua/plugins/navigate-code.lua | 166 ---------- .../nvim/lua/plugins/navigate-files.lua | 75 ++--- common/.config/nvim/lua/plugins/ui.lua | 15 +- .../nvim/lua/plugins/utility-plugs.lua | 221 +------------ 12 files changed, 450 insertions(+), 729 deletions(-) diff --git a/common/.config/nvim/init.lua b/common/.config/nvim/init.lua index 619dace..e7a658a 100644 --- a/common/.config/nvim/init.lua +++ b/common/.config/nvim/init.lua @@ -6,39 +6,16 @@ -- Check all notifications -> :Notifications -- Check past messages -> :messages --- TIP: Keymap structure: --- b+: [B]buffer Operations --- c+: [C]oding Stuff --- d+: [D]iagnostics --- f+: [F]ile Operations --- g+: [G]it Operations --- l+: [L]ist Things --- n+: [N]eoVim Stuff --- q+: DB [Q]ueries --- r+: [R]efactor Things --- s+: Grep/[S]earch Things --- t+: [T]est runner stuff --- x+: close/dismiss something --- e: explorer --- j: EasyMotion jump --- p: Paste from system clipboard --- y: Copy selected stuff to system clipboard --- u: Open undo-tree side-panel --- v: Open document symbol explorer - --- TODO: --- Reduce noice timeout - -- Load keymaps & options require("config") -- `:help lazy.nvim.txt` for more info -local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" 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 } + 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 - error('Error cloning lazy.nvim:\n' .. out) + error("Error cloning lazy.nvim:\n" .. out) end end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) diff --git a/common/.config/nvim/lua/config/keymaps.lua b/common/.config/nvim/lua/config/keymaps.lua index 3331280..a56dfbe 100644 --- a/common/.config/nvim/lua/config/keymaps.lua +++ b/common/.config/nvim/lua/config/keymaps.lua @@ -52,6 +52,12 @@ vim.keymap.set({ "i", "x", "n", "s" }, "", "w", { desc = "Sav vim.keymap.set({ "i", "x", "n", "s" }, "", "wqa", { desc = "Save all files and Quit Neovim" }) -- Close Current Buffer +vim.keymap.set({ "n", "v" }, "bx", function() + if vim.bo.modified then + vim.cmd.write() + end + vim.cmd("bdelete") +end, { desc = "Save and close current buffer" }) vim.keymap.set({ "n", "v" }, "xb", function() if vim.bo.modified then vim.cmd.write() diff --git a/common/.config/nvim/lua/plugins/code-completion.lua b/common/.config/nvim/lua/plugins/code-completion.lua index b0e0208..db87b1a 100644 --- a/common/.config/nvim/lua/plugins/code-completion.lua +++ b/common/.config/nvim/lua/plugins/code-completion.lua @@ -15,10 +15,10 @@ return { -- Build Step is needed for regex support in snippets. -- This step is not supported in many windows environments. -- Remove the below condition to re-enable on windows. - if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then + if vim.fn.has("win32") == 1 or vim.fn.executable("make") == 0 then return end - return 'make install_jsregexp' + return "make install_jsregexp" end)(), dependencies = { -- `friendly-snippets` contains a variety of premade snippets. @@ -27,7 +27,7 @@ return { { "rafamadriz/friendly-snippets", config = function() - require('luasnip.loaders.from_vscode') + require("luasnip.loaders.from_vscode") end, }, }, @@ -90,12 +90,12 @@ return { if luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() end - end, { 'i', 's' }), + end, { "i", "s" }), [""] = cmp.mapping(function() if luasnip.locally_jumpable(-1) then luasnip.jump(-1) end - end, { 'i', 's' }), + end, { "i", "s" }), }), sources = { { name = "nvim_lsp" }, diff --git a/common/.config/nvim/lua/plugins/code-db.lua b/common/.config/nvim/lua/plugins/code-db.lua index 11782b7..8d5ffc5 100644 --- a/common/.config/nvim/lua/plugins/code-db.lua +++ b/common/.config/nvim/lua/plugins/code-db.lua @@ -34,10 +34,10 @@ return { }) end, keys = { - { "qq", desc = "Query UI" }, - { "qq", "DBUIToggle", desc = "Query UI Toggle" }, - { "qa", "DBUIAddConnection", desc = "Query: Add Connection" }, - { "qf", "DBUIFindBuffer", desc = "Query: Find Connection" }, + { "qq", desc = "DB: UI" }, + { "qq", "DBUIToggle", desc = "DB: UI Toggle" }, + { "qa", "DBUIAddConnection", desc = "DB: Add Connection" }, + { "qf", "DBUIFindBuffer", desc = "DB: Find Connection" }, }, }, } diff --git a/common/.config/nvim/lua/plugins/code-debug.lua b/common/.config/nvim/lua/plugins/code-debug.lua index 005fe73..a564707 100644 --- a/common/.config/nvim/lua/plugins/code-debug.lua +++ b/common/.config/nvim/lua/plugins/code-debug.lua @@ -1,77 +1 @@ --- Primarily focused on configuring the debugger for Go, but can --- be extended to other languages as well. - -return { - "mfussenegger/nvim-dap", - cond = require("config.util").is_not_vscode(), - dependencies = { - -- Creates a beautiful debugger UI - "rcarriga/nvim-dap-ui", - "nvim-neotest/nvim-nio", - - -- Installs the debug adapters for you - "williamboman/mason.nvim", - "jay-babu/mason-nvim-dap.nvim", - - -- Add your own debuggers here - "leoluz/nvim-dap-go", - }, - config = function() - local dap = require("dap") - local dapui = require("dapui") - - require("mason-nvim-dap").setup({ - -- Makes a best effort to setup the various debuggers with reasonable debug configurations - automatic_setup = true, - - -- see mason-nvim-dap README for more information - handlers = {}, - - -- You'll need to check that you have the required things installed online - ensure_installed = { - -- Update this to ensure that you have the debuggers for the langs you want - -- "delve", - -- TODO: Rust, C#, TS/JS, Python - }, - }) - - vim.keymap.set("n", "", dap.continue, { desc = "Debug: Start/Continue" }) - vim.keymap.set("n", "", dap.step_into, { desc = "Debug: Step Into" }) - vim.keymap.set("n", "", dap.step_over, { desc = "Debug: Step Over" }) - vim.keymap.set("n", "", dap.step_out, { desc = "Debug: Step Out" }) - vim.keymap.set("n", "", dap.toggle_breakpoint, { desc = "Debug: Toggle Breakpoint" }) - vim.keymap.set("n", "", function() - dap.set_breakpoint(vim.fn.input("Breakpoint condition: ")) - end, { desc = "Debug: Set Breakpoint" }) - - -- For more information, see |:help nvim-dap-ui| - dapui.setup({ - -- Set icons to characters that are more likely to work in every terminal. - icons = { expanded = "▾", collapsed = "▸", current_frame = "*" }, - controls = { - icons = { - pause = "⏸", - play = "▶", - step_into = "⏎", - step_over = "⏭", - step_out = "⏮", - step_back = "b", - run_last = "▶▶", - terminate = "⏹", - disconnect = "⏏", - }, - }, - }) - - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. - vim.keymap.set("n", "", dapui.toggle, { desc = "Debug: See last session result." }) - - dap.listeners.after.event_initialized["dapui_config"] = dapui.open - dap.listeners.before.event_terminated["dapui_config"] = dapui.close - dap.listeners.before.event_exited["dapui_config"] = dapui.close - - -- Install golang specific config - -- require("dap-go").setup() - -- TODO: Rust, C#, TS/JS, Python - end, -} +return {} diff --git a/common/.config/nvim/lua/plugins/code-generic.lua b/common/.config/nvim/lua/plugins/code-generic.lua index 69f018b..9193db0 100644 --- a/common/.config/nvim/lua/plugins/code-generic.lua +++ b/common/.config/nvim/lua/plugins/code-generic.lua @@ -1,4 +1,7 @@ return { + + -- TODO: + -- Reduce noice timeout { "tpope/vim-repeat" }, -- Better code folding @@ -16,8 +19,8 @@ return { require("statuscol").setup({ relculright = true, segments = { - { text = { "%s" }, click = "v:lua.ScSa" }, - { text = { builtin.foldfunc }, click = "v:lua.ScFa" }, + { text = { "%s" }, click = "v:lua.ScSa" }, + { text = { builtin.foldfunc }, click = "v:lua.ScFa" }, { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" }, }, }) @@ -110,34 +113,6 @@ return { main = "ibl", }, - -- Collection of various small independent plugins/modules - { - "chasnovski/mini.nvim", - config = function() - -- Better Around/Inside textobjects - -- - -- Examples: - -- - va) - [V]isually select [A]round [)]paren - -- - yinq - [Y]ank [I]nside [N]ext [Q]uote - -- - ci' - [C]hange [I]nside [']quote - require('mini.ai').setup { n_lines = 500 } - - -- Add/delete/replace surroundings (brackets, quotes, etc.) - -- - -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren - -- - sd' - [S]urround [D]elete [']quotes - -- - sr)' - [S]urround [R]eplace [)] ['] - require('mini.surround').setup() - - require("mini.pairs").setup() - require("mini.comment").setup() - require("mini.completion").setup() - - -- ... and there is more! - -- Check out: https://github.com/echasnovski/mini.nvim - end, - }, - -- Highlights the current level of indentation, and animates the highlighting. { "echasnovski/mini.indentscope", @@ -162,6 +137,72 @@ return { end, }, + -- mini.nvim: Collection of various small independent plugins/modules + { + "echasnovski/mini.nvim", + version = false, + config = function() + -- Better Around/Inside textobjects + -- + -- - va) - [V]isually select [A]round [)]paren + -- - yinq - [Y]ank [I]nside [N]ext [Q]uote + -- - ci' - [C]hange [I]nside [']quote + require("mini.ai").setup({ n_lines = 500 }) + + -- Add/delete/replace surroundings (brackets, quotes, etc.) + -- + -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren + -- - sd' - [S]urround [D]elete [']quotes + -- - sr)' - [S]urround [R]eplace [)] ['] + require("mini.surround").setup() + + -- gc + require("mini.comment").setup() + + require("mini.pairs").setup() + require("mini.completion").setup() + end, + }, + + -- Automatically highlights other instances of the word under cursor + { + "RRethy/vim-illuminate", + lazy = false, + opts = { + delay = 200, + large_file_cutoff = 2000, + large_file_override = { + providers = { "lsp" }, + }, + }, + config = function(_, opts) + -- Copied from LazyNvim + require("illuminate").configure(opts) + + local function map(key, dir, buffer) + vim.keymap.set("n", key, function() + require("illuminate")["goto_" .. dir .. "_reference"](false) + end, { desc = dir:sub(1, 1):upper() .. dir:sub(2) .. " Reference", buffer = buffer }) + end + + map("]]", "next") + map("[[", "prev") + + -- also set it after loading ftplugins, since a lot overwrite [[ and ]] + vim.api.nvim_create_autocmd("FileType", { + callback = function() + local buffer = vim.api.nvim_get_current_buf() + map("]]", "next", buffer) + map("[[", "prev", buffer) + end, + }) + end, + keys = { + { "]]", desc = "Next Reference" }, + { "[[", desc = "Prev Reference" }, + }, + }, + -- Finds and lists all of the TODO, HACK, BUG, etc comment { "folke/todo-comments.nvim", @@ -191,7 +232,7 @@ return { }, -- TODO: Include hidden files - { "fT", "TodoTelescope", desc = "List Todo/Fix/Fixme" }, + { "fT", "TodoTelescope", desc = "List Todo/Fix/Fixme" }, { "ft", "TodoTelescope keywords=TODO,FIX,FIXME", desc = "List Todo" }, }, }, @@ -243,10 +284,10 @@ return { }, keys = { { "dd", "Trouble project_errors toggle focus=true", desc = "Trouble: Document Diagnostics" }, - { "dw", "Trouble most_severe toggle focus=true", desc = "Trouble: List Project Diagnostics" }, - { "dl", "Trouble loclist toggle focus=true", desc = "Trouble: Location List" }, - { "dq", "Trouble quickfix toggle focus=true", desc = "Trouble: Quickfix List" }, - { "gr", "Trouble lsp_references toggle focus=true", desc = "Code: List References" }, + { "dw", "Trouble most_severe toggle focus=true", desc = "Trouble: List Project Diagnostics" }, + { "dl", "Trouble loclist toggle focus=true", desc = "Trouble: Location List" }, + { "dq", "Trouble quickfix toggle focus=true", desc = "Trouble: Quickfix List" }, + { "gr", "Trouble lsp_references toggle focus=true", desc = "Code: List References" }, { "[q", function() @@ -278,7 +319,6 @@ return { }, }, - -- LspSaga { "nvimdev/lspsaga.nvim", @@ -297,20 +337,12 @@ return { hide_keyword = true, }, lightbulb = { - enable = false, - sign = false, virtual_text = false, }, outline = { auto_preview = false }, }) - vim.keymap.set("n", "cR", "Lspsaga finder", { desc = "Code: Goto References" }) - vim.keymap.set("n", "cd", "Lspsaga peek_definition", - { desc = "Code: Peek definition: Function" }) - vim.keymap.set("n", "cD", "Lspsaga peek_type_definition", - { desc = "Code: Peek definition: Class" }) - - vim.keymap.set("n", "K", "Lspsaga hover_doc", { desc = "Hover Documentation" }) + -- Keymaps in code-lsp.lua end, }, @@ -381,7 +413,7 @@ return { -- -- ["g?"] = actions.help(), -- Open mappings help window { - "o", + "O", function() return require("nvim-navbuddy").open() end, @@ -389,4 +421,131 @@ return { }, }, }, + + -- Treesitter + { + -- nvim-treesitter provides parsers for individual languages + -- Output of these parses are fed to the NVIM's native treesitter(vim.treesitter) + -- What is fed to the native treesitter is essentially the AST + -- This AST is then used for syntax-highlighting and many other operations on the code + -- Hence, this plugin is only to make installing parsers easier + + "nvim-treesitter/nvim-treesitter", + lazy = false, + build = ":TSUpdate", + init = function(plugin) + -- PERF: add nvim-treesitter queries to the rtp and it's custom query predicates early + -- This is needed because a bunch of plugins no longer `require("nvim-treesitter")`, which + -- no longer trigger the **nvim-treeitter** module to be loaded in time. + -- Luckily, the only thing that those plugins need are the custom queries, which we make available + -- during startup. + require("lazy.core.loader").add_to_rtp(plugin) + require("nvim-treesitter.query_predicates") + end, + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + config = function() + -- When in diff mode, we want to use the default + -- vim text objects c & C instead of the treesitter ones. + local move = require("nvim-treesitter.textobjects.move") ---@type table + local configs = require("nvim-treesitter.configs") + for name, fn in pairs(move) do + if name:find("goto") == 1 then + move[name] = function(q, ...) + if vim.wo.diff then + local config = configs.get_module("textobjects.move")[name] ---@type table + for key, query in pairs(config or {}) do + if q == query and key:find("[%]%[][cC]") then + vim.cmd("normal! " .. key) + return + end + end + end + return fn(q, ...) + end + end + end + end, + }, + + config = function() + -- See `:help nvim-treesitter` + -- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' + vim.defer_fn(function() + require("nvim-treesitter.configs").setup({ + ensure_installed = { + -- These 2 are required for cmdline + "regex", + "markdown", + "markdown_inline", + }, + + auto_install = true, + highlight = { enable = true }, + indent = { enable = true }, + + incremental_selection = { + enable = true, + keymaps = { + init_selection = "", + node_incremental = "", + scope_incremental = "", + node_decremental = "", + }, + }, + + textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm (:TSEditQuery textobjects) + ["aa"] = { query = "@parameter.outer", desc = "Select around the parameter" }, + ["ia"] = { query = "@parameter.inner", desc = "Select inside the parameter" }, + ["af"] = { query = "@function.outer", desc = "Select around the function" }, + ["if"] = { query = "@function.inner", desc = "Select inside of the function" }, + ["ac"] = { query = "@class.outer", desc = "Select around the class" }, + ["ic"] = { query = "@class.inner", desc = "Select inside of the class" }, + + ["al"] = { query = "@loop.outer", desc = "Select around the loop" }, + ["il"] = { query = "@loop.inner", desc = "Select inside of the loop" }, + ["as"] = { query = "@scope", query_group = "locals", desc = "Select around the scope" }, + }, + }, + + move = { + -- Jump to next and previous text objects + enable = true, + goto_next_start = { + ["]f"] = { query = "@function.outer", desc = "Goto next inner function start" }, + ["]c"] = { query = "@class.outer", desc = "Goto next inner class start" }, + }, + goto_next_end = { + ["]F"] = { query = "@function.outer", desc = "Goto next outer function end" }, + ["]C"] = { query = "@class.outer", desc = "Goto next outer class end" }, + }, + goto_previous_start = { + ["[f"] = { query = "@function.outer", desc = "Goto goto previous inner function start" }, + ["[c"] = { query = "@class.outer", desc = "Previous inner class start" }, + }, + goto_previous_end = { + ["[F"] = { query = "@function.outer", desc = "Goto goto previous outer function start" }, + ["[C"] = { query = "@class.outer", desc = "Goto previous outer class start" }, + }, + }, + + lsp_interop = { + enable = true, + border = "none", + floating_preview_opts = {}, + -- peek_definition_code = { + -- ["cd"] = { query = "@function.outer", desc = "Peek function definition on a popup" }, + -- ["cD"] = { query = "@class.outer", desc = "Peek class definition on a popup" }, + -- }, + }, + }, + }) + end, 0) + end, + }, } diff --git a/common/.config/nvim/lua/plugins/code-git.lua b/common/.config/nvim/lua/plugins/code-git.lua index ef33a53..027b41f 100644 --- a/common/.config/nvim/lua/plugins/code-git.lua +++ b/common/.config/nvim/lua/plugins/code-git.lua @@ -107,17 +107,4 @@ return { end, }, }, - - -- Git worktree - { - "ThePrimeagen/git-worktree.nvim", - cond = require("config.util").is_not_vscode(), - config = function() - -- FIX: Open files do NOT get replaced with the changed branch - require("telescope").load_extension("git_worktree") - - vim.keymap.set("n", "gw", - " lua require('telescope').extensions.git_worktree.git_worktrees()") - end, - }, } diff --git a/common/.config/nvim/lua/plugins/code-lsp.lua b/common/.config/nvim/lua/plugins/code-lsp.lua index 5656a59..68f9284 100644 --- a/common/.config/nvim/lua/plugins/code-lsp.lua +++ b/common/.config/nvim/lua/plugins/code-lsp.lua @@ -1,81 +1,172 @@ --- This function gets run when an LSP connects to a particular buffer. --- Define mappings specific for LSP related items. --- It sets the mode, buffer and description for us each time. -local on_attach = function(_, bufnr) - local nmap = function(keys, func, desc) - if desc then - desc = "LSP: " .. desc - end - - vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc }) - end - - nmap("cr", vim.lsp.buf.rename, "Rename Symbol") - nmap("ca", vim.lsp.buf.code_action, "Code Action") - nmap("", vim.lsp.buf.code_action, "Code Action: VSCode Style") - -- See `:help K` for why this keymap - -- nmap("K", vim.lsp.buf.hover, "Hover Documentation") - -- nmap("", vim.lsp.buf.signature_help, "Signature Documentation") - - -- Lesser used LSP functionality - nmap("cS", require("telescope.builtin").lsp_dynamic_workspace_symbols, "Search Workspace Symbols") - nmap("clf", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, "Workspace List Folders") - - -- Create a command `:Format` local to the LSP buffer - vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) - vim.lsp.buf.format() - end, { desc = "Format current buffer with LSP" }) -end - return { { - -- LSP Configuration & Plugins + -- TODO: Disable it for VSCode + -- + -- Main LSP Configuration "neovim/nvim-lspconfig", - cond = require("config.util").is_not_vscode(), dependencies = { - -- Automatically install LSPs to stdpath for neovim - { "williamboman/mason.nvim", config = true }, - { "williamboman/mason-lspconfig.nvim" }, - { "folke/neodev.nvim" }, + { "williamboman/mason.nvim", config = true }, -- NOTE: Must be loaded before dependants + "williamboman/mason-lspconfig.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim", - -- Useful status updates for LSP - { "j-hui/fidget.nvim", opts = {} }, + -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` + { "j-hui/fidget.nvim", opts = {} }, -- Allows extra capabilities provided by nvim-cmp - 'hrsh7th/cmp-nvim-lsp', + "hrsh7th/cmp-nvim-lsp", }, - }, - - { - "williamboman/mason-lspconfig.nvim", - cond = require("config.util").is_not_vscode(), config = function() - -- Configure LSP + -- Every time a new file is opened that is associated with + -- an lsp this function will be executed to configure the current buffer + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("lsp-attach", { clear = true }), + callback = function(event) + local map = function(keys, func, desc, mode) + mode = mode or "n" + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) + end - -- mason-lspconfig requires that these setup functions are called in this order - -- BEFORE setting up the servers. - require("mason").setup() - local mason_lspconfig = require("mason-lspconfig") - mason_lspconfig.setup() + -- Lspsaga Keymaps + -- Hover Documentation + -- Press K 2 times to jump into the hover window + -- Place cursor on "View Documentation" gx -> Open the docs on browser + map("K", "Lspsaga hover_doc", "Hover Documentation") + map("", vim.lsp.buf.rename, "Rename Symbol") + map("", "Lspsaga code_action", "Code Actions") + map("ca", "Lspsaga code_action", "Code Actions") + -- e to jump to the symbol under cursor; q to quit + map("o", "Lspsaga outline", "Outline Panel on Left") + map("cr", "Lspsaga finder", "Goto References") + map("cpf", "Lspsaga peek_definition", "Peek definition: Function") + map("cpt", "Lspsaga peek_type_definition", "Peek definition: Class") + map("cpi", "Lspsaga finder imp", "Peek: Implementations") + + -- Jump to the definition of the word under your cursor. + -- This is where a variable was first declared, or where a function is defined, etc. + -- To jump back, press . + map("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition") + map("", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition") + map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") + map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") + map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") + + -- Fuzzy find all the symbols in your current document. + -- Symbols are things like variables, functions, types, etc. + map("cs", require("telescope.builtin").lsp_document_symbols, "Search Document Symbols") + map("cS", require("telescope.builtin").lsp_dynamic_workspace_symbols, "Search Workspace Symbols") + map("ci", require("telescope.builtin").lsp_implementations, "Goto Implementation") + map("ct", require("telescope.builtin").lsp_type_definitions, "Goto Type Definition") + + map("cd", require("telescope.builtin").diagnostics, "List Diagnostics") + + map("nf", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, "Workspace Folders on Notification") + + -- The following two autocommands are used to highlight references of the + -- word under your cursor when your cursor rests there for a little while. + -- When you move your cursor, the highlights will be cleared + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then + local highlight_augroup = vim.api.nvim_create_augroup("kickstart-lsp-highlight", { clear = false }) + vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.document_highlight, + }) + + vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { + buffer = event.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 + + -- TODO: Make inlay_hint enabled by default + -- Change this keymap + -- + -- The following code creates a keymap to toggle inlay hints + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then + map("ni", function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf })) + end, "Toggle Inlay Hints") + end + end, + }) + + -- Change diagnostic symbols in the sign column (gutter) + if vim.g.have_nerd_font then + local signs = { ERROR = "", WARN = "", INFO = "", HINT = "" } + local diagnostic_signs = {} + for type, icon in pairs(signs) do + diagnostic_signs[vim.diagnostic.severity[type]] = icon + end + vim.diagnostic.config({ signs = { text = diagnostic_signs } }) + end + + -- LSP servers and clients are able to communicate to each other what features they support. + -- By default, Neovim doesn't support everything that is in the LSP specification. + -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities. + -- Here, we broadcast the new capabilities to the servers. + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities()) -- Enable the following language servers - -- Add any additional override configuration in the following tables. They will be passed to the `settings` field of the server config - -- If you want to override the default filetypes that your language server will attach to you can define the property 'filetypes' to the map in question. + -- Add any additional override configuration in the following tables. Available keys are: + -- - cmd (table): Override the default command used to start the server + -- - filetypes (table): Override the default list of associated filetypes for the server + -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. + -- - settings (table): Override the default settings passed when initializing the server. + -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { + html = { filetypes = { "html", "twig", "hbs" } }, + cssls = {}, + jsonls = {}, + + bashls = { filetypes = { "sh", "bash", "zsh" } }, + pylsp = {}, + ts_ls = {}, lua_ls = { - Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, - completion = { callSnippet = "Replace" }, - hint = { enable = true }, - -- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings - -- diagnostics = { disable = { 'missing-fields' } }, + -- cmd = { ... }, + -- filetypes = { ... }, + -- capabilities = {}, + settings = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + completion = { callSnippet = "Replace" }, + hint = { enable = true }, + diagnostics = { disable = { "missing-fields" } }, + }, }, }, - bashls = { filetypes = { "sh", "bash", "zsh" } }, - html = { filetypes = { "html", "twig", "hbs" } }, + omnisharp = { + settings = { + DotNet = { + enablePackageRestore = true, + FormattingOptions = { OrganizeImports = true }, + RoslynExtensionOptions = { + EnableAnalyzerSupport = true, + EnableImportCompletion = true, + }, + Sdk = { IncludePrereleases = false }, + }, + }, + }, + + sqlls = {}, + dockerls = {}, + docker_compose_language_service = {}, + + marksman = {}, ltex = { filetypes = { "markdown", "text" }, flags = { debounce_text_changes = 3000 }, @@ -95,52 +186,35 @@ return { }, }, }, - - omnisharp = { - -- DotNet = { - -- enablePackageRestore = true, - -- }, - settings = { - FormattingOptions = { - OrganizeImports = true, - }, - RoslynExtensionOptions = { - EnableAnalyzerSupport = true, - EnableImportCompletion = true, - }, - Sdk = { - IncludePrereleases = false, - }, - }, - }, - - -- https://github.com/joe-re/sql-language-server?tab=readme-ov-file#configuration - sqlls = {}, - marksman = {}, - cssls = {}, - dockerls = {}, - docker_compose_language_service = {}, - jsonls = {}, - pylsp = {}, } - -- nvim-cmp supports additional completion capabilities, so broadcast that to servers - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) + -- Ensure the servers and tools above are installed + require("mason").setup() - mason_lspconfig.setup({ - ensure_installed = vim.tbl_keys(servers), + -- Add other tools here that you want Mason to install for you + local ensure_installed = vim.tbl_keys(servers or {}) + vim.list_extend(ensure_installed, { + "stylua", + "codespell", + "bash-language-server", + "marksman", + "html-lsp", + "css-lsp", + "dockerfile-language-server", + "python-lsp-server", }) + require("mason-tool-installer").setup({ ensure_installed = ensure_installed }) - mason_lspconfig.setup_handlers({ - function(server_name) - require("lspconfig")[server_name].setup({ - inlay_hints = { enabled = true }, - capabilities = capabilities, - on_attach = on_attach, - settings = servers[server_name], - filetypes = (servers[server_name] or {}).filetypes, - diagnostics = { + require("mason-lspconfig").setup({ + handlers = { + function(server_name) + local server = servers[server_name] or {} + -- This handles overriding only values explicitly passed + -- by the server configuration above. Useful when disabling + -- certain features of an LSP (for example, turning off formatting for ts_ls) + server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {}) + server.inlay_hints = { enabled = true } + server.diagnostics = { underline = true, update_in_insert = false, virtual_text = { @@ -149,17 +223,10 @@ return { prefix = "●", }, severity_sort = true, - signs = { - text = { - [vim.diagnostic.severity.ERROR] = require("config.util").icons.diagnostics.Error, - [vim.diagnostic.severity.WARN] = require("config.util").icons.diagnostics.Warn, - [vim.diagnostic.severity.HINT] = require("config.util").icons.diagnostics.Hint, - [vim.diagnostic.severity.INFO] = require("config.util").icons.diagnostics.Info, - }, - }, - }, - }) - end, + } + require("lspconfig")[server_name].setup(server) + end, + }, }) end, }, @@ -169,11 +236,11 @@ return { cond = require("config.util").is_not_vscode(), opts = { progress = { - poll_rate = 1, -- How and when to poll for progress messages - suppress_on_insert = true, -- Suppress new messages while in insert mode - ignore_done_already = true, -- Ignore new tasks that are already complete + poll_rate = 1, -- How and when to poll for progress messages + suppress_on_insert = true, -- Suppress new messages while in insert mode + ignore_done_already = true, -- Ignore new tasks that are already complete ignore_empty_message = true, -- Ignore new tasks that don't contain a message - ignore = {}, -- List of LSP servers to ignore + ignore = {}, -- List of LSP servers to ignore display = { render_limit = 1, -- How many LSP messages to show at once @@ -182,7 +249,7 @@ return { }, notification = { - poll_rate = 2, -- How often to udate and render notifications + poll_rate = 2, -- How often to udate and render notifications filter = vim.log.levels.WARN, -- Minimum notifications level }, }, diff --git a/common/.config/nvim/lua/plugins/navigate-code.lua b/common/.config/nvim/lua/plugins/navigate-code.lua index c6c6076..22dda68 100644 --- a/common/.config/nvim/lua/plugins/navigate-code.lua +++ b/common/.config/nvim/lua/plugins/navigate-code.lua @@ -1,170 +1,4 @@ return { { "easymotion/vim-easymotion" }, { "unblevable/quick-scope" }, - - -- Automatically highlights other instances of the word under cursor - { - "RRethy/vim-illuminate", - lazy = false, - opts = { - delay = 200, - large_file_cutoff = 2000, - large_file_override = { - providers = { "lsp" }, - }, - }, - config = function(_, opts) - -- Copied from LazyNvim - require("illuminate").configure(opts) - - local function map(key, dir, buffer) - vim.keymap.set("n", key, function() - require("illuminate")["goto_" .. dir .. "_reference"](false) - end, { desc = dir:sub(1, 1):upper() .. dir:sub(2) .. " Reference", buffer = buffer }) - end - - map("]]", "next") - map("[[", "prev") - - -- also set it after loading ftplugins, since a lot overwrite [[ and ]] - vim.api.nvim_create_autocmd("FileType", { - callback = function() - local buffer = vim.api.nvim_get_current_buf() - map("]]", "next", buffer) - map("[[", "prev", buffer) - end, - }) - end, - keys = { - { "]]", desc = "Next Reference" }, - { "[[", desc = "Prev Reference" }, - }, - }, - - -- Treesitter - { - -- nvim-treesitter provides parsers for individual languages - -- Output of these parses are fed to the NVIM's native treesitter(vim.treesitter) - -- What is fed to the native treesitter is essentially the AST - -- This AST is then used for syntax-highlighting and many other operations on the code - -- Hence, this plugin is only to make installing parsers easier - - "nvim-treesitter/nvim-treesitter", - lazy = false, - build = ":TSUpdate", - init = function(plugin) - -- PERF: add nvim-treesitter queries to the rtp and it's custom query predicates early - -- This is needed because a bunch of plugins no longer `require("nvim-treesitter")`, which - -- no longer trigger the **nvim-treeitter** module to be loaded in time. - -- Luckily, the only thing that those plugins need are the custom queries, which we make available - -- during startup. - require("lazy.core.loader").add_to_rtp(plugin) - require("nvim-treesitter.query_predicates") - end, - dependencies = { - "nvim-treesitter/nvim-treesitter-textobjects", - config = function() - -- When in diff mode, we want to use the default - -- vim text objects c & C instead of the treesitter ones. - local move = require("nvim-treesitter.textobjects.move") ---@type table - local configs = require("nvim-treesitter.configs") - for name, fn in pairs(move) do - if name:find("goto") == 1 then - move[name] = function(q, ...) - if vim.wo.diff then - local config = configs.get_module("textobjects.move")[name] ---@type table - for key, query in pairs(config or {}) do - if q == query and key:find("[%]%[][cC]") then - vim.cmd("normal! " .. key) - return - end - end - end - return fn(q, ...) - end - end - end - end, - }, - - config = function() - -- See `:help nvim-treesitter` - -- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' - vim.defer_fn(function() - require("nvim-treesitter.configs").setup({ - ensure_installed = { - -- These 2 are required for cmdline - "regex", - "markdown", - "markdown_inline", - }, - - auto_install = true, - highlight = { enable = true }, - indent = { enable = true }, - - incremental_selection = { - enable = true, - keymaps = { - init_selection = "", - node_incremental = "", - scope_incremental = "", - node_decremental = "", - }, - }, - - textobjects = { - select = { - enable = true, - lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim - keymaps = { - -- You can use the capture groups defined in textobjects.scm (:TSEditQuery textobjects) - ["aa"] = { query = "@parameter.outer", desc = "Select around the parameter" }, - ["ia"] = { query = "@parameter.inner", desc = "Select inside the parameter" }, - ["af"] = { query = "@function.outer", desc = "Select around the function" }, - ["if"] = { query = "@function.inner", desc = "Select inside of the function" }, - ["ac"] = { query = "@class.outer", desc = "Select around the class" }, - ["ic"] = { query = "@class.inner", desc = "Select inside of the class" }, - - ["al"] = { query = "@loop.outer", desc = "Select around the loop" }, - ["il"] = { query = "@loop.inner", desc = "Select inside of the loop" }, - ["as"] = { query = "@scope", query_group = "locals", desc = "Select around the scope" }, - }, - }, - - move = { - -- Jump to next and previous text objects - enable = true, - goto_next_start = { - ["]f"] = { query = "@function.outer", desc = "Goto next inner function start" }, - ["]c"] = { query = "@class.outer", desc = "Goto next inner class start" }, - }, - goto_next_end = { - ["]F"] = { query = "@function.outer", desc = "Goto next outer function end" }, - ["]C"] = { query = "@class.outer", desc = "Goto next outer class end" }, - }, - goto_previous_start = { - ["[f"] = { query = "@function.outer", desc = "Goto goto previous inner function start" }, - ["[c"] = { query = "@class.outer", desc = "Previous inner class start" }, - }, - goto_previous_end = { - ["[F"] = { query = "@function.outer", desc = "Goto goto previous outer function start" }, - ["[C"] = { query = "@class.outer", desc = "Goto previous outer class start" }, - }, - }, - - lsp_interop = { - enable = true, - border = "none", - floating_preview_opts = {}, - -- peek_definition_code = { - -- ["cd"] = { query = "@function.outer", desc = "Peek function definition on a popup" }, - -- ["cD"] = { query = "@class.outer", desc = "Peek class definition on a popup" }, - -- }, - }, - }, - }) - end, 0) - end, - }, } diff --git a/common/.config/nvim/lua/plugins/navigate-files.lua b/common/.config/nvim/lua/plugins/navigate-files.lua index f3bfa11..f7ab711 100644 --- a/common/.config/nvim/lua/plugins/navigate-files.lua +++ b/common/.config/nvim/lua/plugins/navigate-files.lua @@ -6,8 +6,8 @@ return { cond = require("config.util").is_not_vscode(), branch = "v3.x", keys = { - { "", "Neotree toggle left", desc = "Open NeoTree Explorer at Git root", remap = true }, - { "e", "Neotree toggle float", desc = "Open NeoTree on Floating Window", remap = true }, + { "", "Neotree toggle left", desc = "Open NeoTree Explorer at Git root", remap = true }, + { "e", "Neotree toggle float", desc = "Open NeoTree on Floating Window", remap = true }, { "be", @@ -46,10 +46,10 @@ return { }, window = { position = "left", - width = 30, -- Saner window size + width = 30, -- Saner window size mappings = { - ["s"] = "open_split", -- horizontal split - ["v"] = "open_vsplit", -- vertical split + ["s"] = "open_split", -- horizontal split + ["v"] = "open_vsplit", -- vertical split ["Y"] = function(state) -- Copy file's path to + register local node = state.tree:get_node() local path = node:get_id() @@ -59,7 +59,7 @@ return { }, default_component_configs = { indent = { - indent_size = 2, -- Compact tree display + indent_size = 2, -- Compact tree display with_expanders = true, -- if nil and file nesting is enabled, will enable expanders expander_collapsed = "", expander_expanded = "", @@ -79,7 +79,7 @@ return { local events = require("neo-tree.events") opts.event_handlers = opts.event_handlers or {} vim.list_extend(opts.event_handlers, { - { event = events.FILE_MOVED, handler = on_move }, + { event = events.FILE_MOVED, handler = on_move }, { event = events.FILE_RENAMED, handler = on_move }, }) require("neo-tree").setup(opts) @@ -110,8 +110,9 @@ return { }, "nvim-telescope/telescope-ui-select.nvim", { - "nvim-tree/nvim-web-devicons", enabled = vim.g.have_nerd_font - } + "nvim-tree/nvim-web-devicons", + enabled = vim.g.have_nerd_font, + }, }, config = function() -- NOTE: Search in hidden files trick taken from: https://stackoverflow.com/a/75500661/11057673 @@ -158,9 +159,7 @@ return { pcall(require("telescope").load_extension, "fzf") pcall(require("telescope").load_extension, "ui-select") - -- Special Things: Telescope - vim.keymap.set("n", "nc", require("telescope.builtin").colorscheme, - { desc = "List Neovim Colorschemes (with preview)" }) + -- Keymaps for LSP Things -> In code-lsp.lua -- Grep things -> Search vim.keymap.set("n", "sb", function() @@ -169,55 +168,31 @@ return { prompt_title = "Live Grep in Open Files", }) end, { desc = "Search Open Buffers" }) - vim.keymap.set("n", "sg", require("telescope.builtin").live_grep, - { desc = "Search/LiveGrep the Project" }) - vim.keymap.set("n", "", require("telescope.builtin").live_grep, - { desc = "Search/LiveGrep the Project" }) - vim.keymap.set("n", "sw", require("telescope.builtin").grep_string, - { desc = "Search current Word in Project" }) + vim.keymap.set("n", "sg", require("telescope.builtin").live_grep, { desc = "Search/LiveGrep the Project" }) + vim.keymap.set("n", "", require("telescope.builtin").live_grep, { desc = "Search/LiveGrep the Project" }) + vim.keymap.set("n", "sw", require("telescope.builtin").grep_string, { desc = "Search current Word in Project" }) -- List vim.keymap.set("n", "fb", require("telescope.builtin").buffers, { desc = "List Buffers" }) - vim.keymap.set("n", "fc", require("telescope.builtin").command_history, - { desc = "List NeoVIM Command History" }) vim.keymap.set("n", "", require("telescope.builtin").find_files, { desc = "List & Search Files" }) vim.keymap.set("n", "ff", require("telescope.builtin").find_files, { desc = "List & Search Files" }) - vim.keymap.set("n", "fn", require("telescope.builtin").help_tags, - { desc = "List & Search NeoVIM Help" }) - vim.keymap.set("n", "fq", require("telescope.builtin").quickfixhistory, - { desc = "List Quickfix History" }) - vim.keymap.set("n", "fs", require("telescope.builtin").search_history, - { desc = "List Search History" }) + vim.keymap.set("n", "fq", require("telescope.builtin").quickfixhistory, { desc = "List Quickfix History" }) -- Git vim.keymap.set("n", "gfb", require("telescope.builtin").git_branches, { desc = "List Git Branches" }) vim.keymap.set("n", "gfc", require("telescope.builtin").git_commits, { desc = "List Git Commits" }) - -- LSP Things -> Coding - vim.keymap.set("n", "cld", require("telescope.builtin").diagnostics, - { desc = "Code: List Diagnostics" }) - - vim.keymap.set("n", "ci", require("telescope.builtin").lsp_implementations, - { desc = "Code: Goto Implementation" }) - - vim.keymap.set("n", "gd", require("telescope.builtin").lsp_definitions, { desc = "Code: Goto Definition" }) - vim.keymap.set("n", "ct", require("telescope.builtin").lsp_type_definitions, - { desc = "Code: Goto Type Definition" }) - -- vim.keymap.set("n", "cgD", vim.lsp.buf.declaration, { desc = "Goto Declaration" }) - - vim.keymap.set("n", "cR", require("telescope.builtin").lsp_references, - { desc = "Code: Goto References" }) - -- vim.keymap.set("n", "cR", require("telescope.builtin").lsp_references, { desc = "Code: List References for word under cursor" }) - - vim.keymap.set("n", "O", require("telescope.builtin").lsp_workspace_symbols, - { desc = "Code: Search Workspace Symbols" }) - - vim.keymap.set("n", "nk", require("telescope.builtin").keymaps, - { desc = "List & Search NeoVIM Keymaps" }) - vim.keymap.set("n", "nm", require("telescope.builtin").man_pages, - { desc = "List & Search System Man Pages" }) + -- Neovim Things + vim.keymap.set("n", "ns", require("telescope.builtin").search_history, { desc = "List Search History" }) + vim.keymap.set("n", "nn", require("telescope.builtin").help_tags, { desc = "List & Search NeoVIM Help" }) + vim.keymap.set("n", "nc", require("telescope.builtin").command_history, { desc = "List NeoVIM Command History" }) + vim.keymap.set("n", "nC", require("telescope.builtin").colorscheme, { desc = "List Neovim Colorschemes (with preview)" }) vim.keymap.set("n", "nn", "Telescope notify", { desc = "List past notifications" }) - vim.keymap.set("n", "nv", require("telescope.builtin").vim_options, { desc = "List Vim Options" }) + + -- Help + vim.keymap.set("n", "hk", require("telescope.builtin").keymaps, { desc = "Help: NeoVIM Keymaps" }) + vim.keymap.set("n", "hm", require("telescope.builtin").man_pages, { desc = "Help: System Man Pages" }) + vim.keymap.set("n", "hv", require("telescope.builtin").vim_options, { desc = "Help: Vim Options" }) end, }, } diff --git a/common/.config/nvim/lua/plugins/ui.lua b/common/.config/nvim/lua/plugins/ui.lua index 6ab12c7..0b957c7 100644 --- a/common/.config/nvim/lua/plugins/ui.lua +++ b/common/.config/nvim/lua/plugins/ui.lua @@ -39,11 +39,11 @@ return { }, event = "VeryLazy", keys = { - { "bp", "BufferLineTogglePin", desc = "Toggle buffer-pin" }, - { "bj", "BufferLinePick", desc = "Choose and jump to a buffer" }, + { "bp", "BufferLineTogglePin", desc = "Toggle buffer-pin" }, + { "bX", "BufferLineCloseOthers", desc = "Close other buffers" }, { "xo", "BufferLineCloseOthers", desc = "Close other buffers" }, - { "[b", "BufferLineCyclePrev", desc = "Prev buffer" }, - { "]b", "BufferLineCycleNext", desc = "Next buffer" }, + { "[b", "BufferLineCyclePrev", desc = "Prev buffer" }, + { "]b", "BufferLineCycleNext", desc = "Next buffer" }, }, opts = { options = { @@ -69,6 +69,11 @@ return { local buf_line = require("bufferline") buf_line.setup(opts) + -- ... to switch to a buffer + for i = 1, 9 do + vim.keymap.set("n", string.format("", i), string.format("BufferLineGoToBuffer %s", i), { noremap = true, silent = true }) + end + -- Fix bufferline when restoring a session vim.api.nvim_create_autocmd("BufAdd", { callback = function() @@ -288,7 +293,7 @@ return { }, lualine_y = { - { "progress", separator = " ", padding = { left = 1, right = 0 } }, + { "progress", separator = " ", padding = { left = 1, right = 0 } }, { "location", padding = { left = 0, right = 1 } }, }, lualine_z = { diff --git a/common/.config/nvim/lua/plugins/utility-plugs.lua b/common/.config/nvim/lua/plugins/utility-plugs.lua index 5badf0c..f0b5457 100644 --- a/common/.config/nvim/lua/plugins/utility-plugs.lua +++ b/common/.config/nvim/lua/plugins/utility-plugs.lua @@ -1,180 +1,4 @@ -local M = {} ----@type table> -M.dials_by_ft = {} - ----@param increment boolean ----@param g? boolean -function M.dial(increment, g) - local mode = vim.fn.mode(true) - -- Use visual commands for VISUAL 'v', VISUAL LINE 'V' and VISUAL BLOCK '\22' - local is_visual = mode == "v" or mode == "V" or mode == "\22" - local func = (increment and "inc" or "dec") .. (g and "_g" or "_") .. (is_visual and "visual" or "normal") - local group = M.dials_by_ft[vim.bo.filetype] or "default" - return require("dial.map")[func](group) -end - return { - -- Better increment/decrement with - { - "monaqa/dial.nvim", - -- stylua: ignore - keys = { - { "", function() return M.dial(true) end, expr = true, desc = "Increment", mode = { "n", "v" } }, - { "", function() return M.dial(false) end, expr = true, desc = "Decrement", mode = { "n", "v" } }, - { "g", function() return M.dial(true, true) end, expr = true, desc = "Increment", mode = { "n", "v" } }, - { "g", function() return M.dial(false, true) end, expr = true, desc = "Decrement", mode = { "n", "v" } }, - }, - opts = function() - local augend = require("dial.augend") - - local logical_alias = augend.constant.new({ - elements = { "&&", "||" }, - word = false, - cyclic = true, - }) - - local ordinal_numbers = augend.constant.new({ - -- elements through which we cycle. When we increment, we go down - -- On decrement we go up - elements = { - "first", - "second", - "third", - "fourth", - "fifth", - "sixth", - "seventh", - "eighth", - "ninth", - "tenth", - }, - -- if true, it only matches strings with word boundary. firstDate wouldn't work for example - word = false, - -- do we cycle back and forth (tenth to first on increment, first to tenth on decrement). - -- Otherwise nothing will happen when there are no further values - cyclic = true, - }) - - local weekdays = augend.constant.new({ - elements = { - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - "Sunday", - }, - word = true, - cyclic = true, - }) - - local months = augend.constant.new({ - elements = { - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December", - }, - word = true, - cyclic = true, - }) - - local capitalized_boolean = augend.constant.new({ - elements = { - "True", - "False", - }, - word = true, - cyclic = true, - }) - - return { - dials_by_ft = { - css = "css", - javascript = "typescript", - javascriptreact = "typescript", - json = "json", - lua = "lua", - markdown = "markdown", - python = "python", - sass = "css", - scss = "css", - typescript = "typescript", - typescriptreact = "typescript", - cs = "csharp", - }, - groups = { - default = { - augend.integer.alias.decimal, -- nonnegative decimal number (0, 1, 2, 3, ...) - augend.integer.alias.hex, -- nonnegative hex number (0x01, 0x1a1f, etc.) - augend.date.alias["%Y/%m/%d"], -- date (2022/02/19, etc.) - }, - typescript = { - augend.integer.alias.decimal, -- nonnegative and negative decimal number - augend.constant.alias.bool, -- boolean value (true <-> false) - logical_alias, - augend.constant.new({ elements = { "let", "const" } }), - ordinal_numbers, - weekdays, - months, - }, - css = { - augend.integer.alias.decimal, -- nonnegative and negative decimal number - augend.hexcolor.new({ - case = "lower", - }), - augend.hexcolor.new({ - case = "upper", - }), - }, - markdown = { - augend.misc.alias.markdown_header, - ordinal_numbers, - weekdays, - months, - }, - json = { - augend.integer.alias.decimal, -- nonnegative and negative decimal number - augend.semver.alias.semver, -- versioning (v1.1.2) - }, - lua = { - augend.integer.alias.decimal, -- nonnegative and negative decimal number - augend.constant.alias.bool, -- boolean value (true <-> false) - augend.constant.new({ - elements = { "and", "or" }, - word = true, -- if false, "sand" is incremented into "sor", "doctor" into "doctand", etc. - cyclic = true, -- "or" is incremented into "and". - }), - ordinal_numbers, - weekdays, - months, - }, - python = { - augend.integer.alias.decimal, -- nonnegative and negative decimal number - capitalized_boolean, - logical_alias, - ordinal_numbers, - weekdays, - months, - }, - }, - } - end, - config = function(_, opts) - require("dial.config").augends:register_group(opts.groups) - M.dials_by_ft = opts.dials_by_ft - end, - }, - -- Navigate between NVIM & Tmux splits seamlessly { "christoomey/vim-tmux-navigator", @@ -231,50 +55,11 @@ return { { "folke/which-key.nvim", + cond = require("config.util").is_not_vscode(), dependencies = { "echasnovski/mini.icons", }, opts = { - defaults = { - ["r"] = { name = "+refactor" }, - }, - icons = { - -- set icon mappings to true if you have a Nerd Font - mappings = vim.g.have_nerd_font, - -- If you are using a Nerd Font: set icons.keys to an empty table which will use the - -- default which-key.nvim defined Nerd Font icons, otherwise define a string table - keys = vim.g.have_nerd_font and {} or { - Up = ' ', - Down = ' ', - Lefj = ' ', - Right = ' ', - C = ' ', - M = ' ', - D = ' ', - S = ' ', - CR = ' ', - Esc = ' ', - ScrollWheelDown = ' ', - ScrollWheelUp = ' ', - NL = ' ', - BS = ' ', - Space = ' ', - Tab = ' ', - F1 = '', - F2 = '', - F3 = '', - F4 = '', - F5 = '', - F6 = '', - F7 = '', - F8 = '', - F9 = '', - F10 = '', - F11 = '', - F12 = '', - }, - }, - -- Document existing key chains spec = { { "c", group = "Code" }, @@ -283,8 +68,9 @@ return { { "f", group = "File Operations" }, { "g", group = "Git" }, { "f", group = "Find and List Things" }, + { "h", group = "Help" }, { "n", group = "NVIM Things" }, - { "q", group = "Database Query" }, + { "q", group = "Database" }, { "s", group = "Search/Grep Things" }, { "t", group = "Unit Test Operations" }, { "x", group = "Delete/Remove Something" }, @@ -296,6 +82,7 @@ return { -- TIP: autocmd to autoload sessions at: ../config/autocmd.lua { "folke/persistence.nvim", + cond = require("config.util").is_not_vscode(), event = "BufReadPre", opts = { -- Session files stored at: ~/.config/nvim/sessions/