diff --git a/common/.config/nvim/init.lua b/common/.config/nvim/init.lua index 460576c..619dace 100644 --- a/common/.config/nvim/init.lua +++ b/common/.config/nvim/init.lua @@ -33,17 +33,14 @@ require("config") -- `:help lazy.nvim.txt` for more info -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not vim.loop.fs_stat(lazypath) then - vim.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", - lazypath, - }) -end +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 } + if vim.v.shell_error ~= 0 then + error('Error cloning lazy.nvim:\n' .. out) + end +end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) -- You can also configure plugins after the setup call, diff --git a/common/.config/nvim/lua/config/options.lua b/common/.config/nvim/lua/config/options.lua index 86a283f..b02776e 100644 --- a/common/.config/nvim/lua/config/options.lua +++ b/common/.config/nvim/lua/config/options.lua @@ -17,3 +17,8 @@ vim.opt.inccommand = "split" -- With :%s command, show the preview in a split in vim.opt.splitkeep = "screen" -- Fix markdown indentation settings vim.g.markdown_recommended_style = 0 + +vim.g.have_nerd_font = true + +vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } +vim.opt.inccommand = 'split' diff --git a/common/.config/nvim/lua/plugins/code-completion.lua b/common/.config/nvim/lua/plugins/code-completion.lua index 44055d5..00002f5 100644 --- a/common/.config/nvim/lua/plugins/code-completion.lua +++ b/common/.config/nvim/lua/plugins/code-completion.lua @@ -5,10 +5,33 @@ return { { -- Autocompletion "hrsh7th/nvim-cmp", + event = "InsertEnter", cond = require("config.util").is_not_vscode(), dependencies = { -- Snippet Engine & its associated nvim-cmp source - "L3MON4D3/LuaSnip", + { + 'L3MON4D3/LuaSnip', + build = (function() + -- 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 + return + end + return 'make install_jsregexp' + end)(), + dependencies = { + -- `friendly-snippets` contains a variety of premade snippets. + -- See the README about individual language/framework/plugin snippets: + -- https://github.com/rafamadriz/friendly-snippets + { + 'rafamadriz/friendly-snippets', + config = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, + }, + }, + }, "saadparwaiz1/cmp_luasnip", -- Adds LSP completion capabilities @@ -18,9 +41,6 @@ return { "hrsh7th/cmp-vsnip", "hrsh7th/vim-vsnip", - - -- Adds a number of user-friendly snippets - "rafamadriz/friendly-snippets", }, config = function() -- See `:help cmp` @@ -63,6 +83,19 @@ return { behavior = cmp.ConfirmBehavior.Replace, select = true, }), + + -- will move you to the right of each of the expansion locations + -- is similar, except moving you backwards. + [""] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { 'i', 's' }), + [""] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { 'i', 's' }), }), sources = { { name = "nvim_lsp" }, diff --git a/common/.config/nvim/lua/plugins/code-formatting.lua b/common/.config/nvim/lua/plugins/code-formatting.lua index 8ce769e..e551ef2 100644 --- a/common/.config/nvim/lua/plugins/code-formatting.lua +++ b/common/.config/nvim/lua/plugins/code-formatting.lua @@ -3,56 +3,63 @@ return { "stevearc/conform.nvim", -- cond = require("config.util").is_not_vscode(), lazy = true, - event = { "BufReadPre", "BufNewFile" }, - config = function() - local conform = require("conform") - - conform.setup({ - formatters_by_ft = { - javascript = { "prettierd", "prettier", stop_after_first = true }, - typescript = { "prettierd", "prettier", stop_after_first = true }, - javascriptreact = { "prettierd", "prettier", stop_after_first = true }, - typescriptreact = { "prettierd", "prettier", stop_after_first = true }, - svelte = { "prettierd", "prettier", stop_after_first = true }, - css = { "prettierd", "prettier", stop_after_first = true }, - html = { "prettierd", "prettier", stop_after_first = true }, - json = { "prettierd", "prettier", stop_after_first = true }, - graphql = { "prettierd", "prettier", stop_after_first = true }, - yaml = { "yamlfmt", "prettierd", stop_after_first = true }, - markdown = { "markdownlint" }, - lua = { "stylua" }, - python = { "black" }, - sh = { "shfmt", "shellharden", stop_after_first = true }, - bash = { "shfmt", "shellharden", stop_after_first = true }, - zsh = { "shfmt", "shellharden", stop_after_first = true }, - ["_"] = { "trim_whitespace" }, - }, - format_on_save = { - lsp_fallback = true, - async = false, - timeout_ms = 3000, + event = { "BufWritePre" }, + opts = { + formatters_by_ft = { + javascript = { "prettierd", "prettier", stop_after_first = true }, + typescript = { "prettierd", "prettier", stop_after_first = true }, + javascriptreact = { "prettierd", "prettier", stop_after_first = true }, + typescriptreact = { "prettierd", "prettier", stop_after_first = true }, + svelte = { "prettierd", "prettier", stop_after_first = true }, + css = { "prettierd", "prettier", stop_after_first = true }, + html = { "prettierd", "prettier", stop_after_first = true }, + json = { "prettierd", "prettier", stop_after_first = true }, + graphql = { "prettierd", "prettier", stop_after_first = true }, + yaml = { "yamlfmt", "prettierd", stop_after_first = true }, + markdown = { "markdownlint" }, + lua = { "stylua" }, + python = { "black" }, + sh = { "shfmt", "shellharden", stop_after_first = true }, + bash = { "shfmt", "shellharden", stop_after_first = true }, + zsh = { "shfmt", "shellharden", stop_after_first = true }, + ["_"] = { "trim_whitespace" }, + }, + format_on_save = function(bufnr) + -- Disable "format_on_save lsp_fallback" for languages that don't + -- have a well standardized coding style. You can add additional + -- languages here or re-enable it for the disabled ones. + local disable_filetypes = { c = true, cpp = true } + local lsp_format_opt + if disable_filetypes[vim.bo[bufnr].filetype] then + lsp_format_opt = 'never' + else + lsp_format_opt = 'fallback' + end + return { quiet = false, + timeout_ms = 500, + lsp_format = lsp_format_opt, + } + end, + formatters = { + injected = { options = { ignore_errors = true } }, + shfmt = { + prepend_args = { "-i", "4" }, }, - formatters = { - injected = { options = { ignore_errors = true } }, - shfmt = { - prepend_args = { "-i", "4" }, - }, - markdownlint = { - prepend_args = { - "--config", - "~/.config/templates/markdownlint.json", - }, - }, - yamlfmt = { - prepend_args = { - "-formatter", - "include_document_start=true,retain_line_breaks_single=true", - "-gitignore_excludes", - }, + markdownlint = { + prepend_args = { + "--config", + "~/.config/templates/markdownlint.json", }, }, - }) - end, + yamlfmt = { + prepend_args = { + "-formatter", + "include_document_start=true,retain_line_breaks_single=true", + "-gitignore_excludes", + }, + }, + }, + } }, } diff --git a/common/.config/nvim/lua/plugins/code-generic.lua b/common/.config/nvim/lua/plugins/code-generic.lua index 0f2487e..9ddd31e 100644 --- a/common/.config/nvim/lua/plugins/code-generic.lua +++ b/common/.config/nvim/lua/plugins/code-generic.lua @@ -1,29 +1,6 @@ return { { "tpope/vim-repeat" }, - -- Better surround than tpope/vim-surround - { - "kylechui/nvim-surround", - version = "*", - event = "VeryLazy", - config = function() - require("nvim-surround").setup({}) - end, - }, - - -- "gc" to comment visual regions/lines - { - "numToStr/Comment.nvim", - cond = require("config.util").is_not_vscode(), - config = function() - require("Comment").setup({ - pre_hook = function() - return vim.bo.commentstring - end, - }) - end, - }, - -- Better code folding { "kevinhwang91/nvim-ufo", @@ -39,8 +16,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" }, }, }) @@ -107,13 +84,6 @@ return { end, }, - -- auto pairs - { - "echasnovski/mini.pairs", - event = "VeryLazy", - opts = {}, - }, - -- indent guides for Neovim { "lukas-reineke/indent-blankline.nvim", @@ -140,6 +110,34 @@ 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", @@ -167,10 +165,11 @@ return { -- Finds and lists all of the TODO, HACK, BUG, etc comment { "folke/todo-comments.nvim", - lazy = false, + event = "VimEnter", dependencies = { "nvim-lua/plenary.nvim" }, config = true, opts = { + signs = false, keywords = { HACK = { alt = { "TIP" } }, }, @@ -245,13 +244,11 @@ return { }, }, keys = { - { "o", "Trouble symbols toggle preview.type=main focus=true", desc = "Code: Toggle Symbol Outline" }, - { "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() @@ -333,8 +330,10 @@ return { }) 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", "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" }) end, diff --git a/common/.config/nvim/lua/plugins/code-git.lua b/common/.config/nvim/lua/plugins/code-git.lua index f8bad38..ef33a53 100644 --- a/common/.config/nvim/lua/plugins/code-git.lua +++ b/common/.config/nvim/lua/plugins/code-git.lua @@ -10,8 +10,8 @@ return { }, config = true, keys = { - { "gg", "Neogit", desc = "Git: Open Neogit", mode = { "n" } }, - { "gL", "Neogit log", desc = "Git: Open Neogit Log", mode = { "n" } }, + { "gg", "Neogit", desc = "Git: Open Neogit", mode = { "n" } }, + { "gL", "Neogit log", desc = "Git: Open Log", mode = { "n" } }, }, }, @@ -20,9 +20,9 @@ return { "sindrets/diffview.nvim", keys = { - { "gd", "DiffviewOpen", desc = "Git: Open Diffview", mode = { "n" } }, - { "gD", "DiffviewOpen", desc = "Git: Open Diffview against master", mode = { "n" } }, - { "gh", "DiffviewFileHistory", desc = "Git: Show file history", mode = { "n" } }, + { "gd", "DiffviewOpen", desc = "Git: Open Diffview", mode = { "n" } }, + { "gD", "DiffviewOpen", desc = "Git: Open Diffview against master", mode = { "n" } }, + { "gh", "DiffviewFileHistory", desc = "Git: Show file history", mode = { "n" } }, }, -- TODO: -- Toggle Diffview keymap @@ -116,7 +116,8 @@ return { -- 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()") + 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 5324175..5656a59 100644 --- a/common/.config/nvim/lua/plugins/code-lsp.lua +++ b/common/.config/nvim/lua/plugins/code-lsp.lua @@ -42,6 +42,9 @@ return { -- Useful status updates for LSP { "j-hui/fidget.nvim", opts = {} }, + + -- Allows extra capabilities provided by nvim-cmp + 'hrsh7th/cmp-nvim-lsp', }, }, diff --git a/common/.config/nvim/lua/plugins/navigate-files.lua b/common/.config/nvim/lua/plugins/navigate-files.lua index 9d38cf9..4d60392 100644 --- a/common/.config/nvim/lua/plugins/navigate-files.lua +++ b/common/.config/nvim/lua/plugins/navigate-files.lua @@ -156,10 +156,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() @@ -169,7 +169,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 = "", @@ -189,7 +189,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) @@ -259,7 +259,8 @@ return { pcall(require("telescope").load_extension, "fzf") -- Special Things: Telescope - vim.keymap.set("n", "nc", require("telescope.builtin").colorscheme, { desc = "List Neovim Colorschemes (with preview)" }) + vim.keymap.set("n", "nc", require("telescope.builtin").colorscheme, + { desc = "List Neovim Colorschemes (with preview)" }) -- Grep things -> Search vim.keymap.set("n", "sb", function() diff --git a/common/.config/nvim/lua/plugins/ui.lua b/common/.config/nvim/lua/plugins/ui.lua index dbff39a..567f128 100644 --- a/common/.config/nvim/lua/plugins/ui.lua +++ b/common/.config/nvim/lua/plugins/ui.lua @@ -288,7 +288,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 3b1f1e1..5badf0c 100644 --- a/common/.config/nvim/lua/plugins/utility-plugs.lua +++ b/common/.config/nvim/lua/plugins/utility-plugs.lua @@ -19,10 +19,10 @@ return { "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"} }, + { "", 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") @@ -114,13 +114,13 @@ return { }, groups = { default = { - augend.integer.alias.decimal, -- nonnegative decimal number (0, 1, 2, 3, ...) - augend.integer.alias.hex, -- nonnegative hex number (0x01, 0x1a1f, etc.) + 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) + augend.constant.alias.bool, -- boolean value (true <-> false) logical_alias, augend.constant.new({ elements = { "let", "const" } }), ordinal_numbers, @@ -144,14 +144,14 @@ return { }, json = { augend.integer.alias.decimal, -- nonnegative and negative decimal number - augend.semver.alias.semver, -- versioning (v1.1.2) + 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.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. + word = true, -- if false, "sand" is incremented into "sor", "doctor" into "doctand", etc. cyclic = true, -- "or" is incremented into "and". }), ordinal_numbers, @@ -234,24 +234,62 @@ return { dependencies = { "echasnovski/mini.icons", }, - config = function() - -- document existing key chains - require("which-key").add({ + 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" }, { "b", group = "Buffer Operations" }, { "d", group = "Diagnostics" }, { "f", group = "File Operations" }, { "g", group = "Git" }, - { "h", group = "Harpoon" }, - { "l", group = "List Things" }, + { "f", group = "Find and List Things" }, { "n", group = "NVIM Things" }, { "q", group = "Database Query" }, - { "r", group = "Refactor Code" }, { "s", group = "Search/Grep Things" }, { "t", group = "Unit Test Operations" }, { "x", group = "Delete/Remove Something" }, - }) - end, + }, + }, }, -- Session management. Saves your session in the background