From 251eaec92ba21e6e7f811adcc07ddfc2e87f6357 Mon Sep 17 00:00:00 2001 From: Einherjar Date: Fri, 15 Sep 2023 06:11:08 -0300 Subject: [PATCH] feat!: modularize all things way easier to maintain, this `init.lua` was getting too big. --- init.lua | 1035 +-------------------------------- lua/config/highlight_yank.lua | 12 + lua/config/init.lua | 5 + lua/config/keymaps.lua | 63 ++ lua/config/netrw.lua | 18 + lua/config/options.lua | 75 +++ lua/config/restore_cursor.lua | 10 + lua/plugins/colorscheme.lua | 32 + lua/plugins/comment.lua | 5 + lua/plugins/flash.lua | 11 + lua/plugins/format.lua | 57 ++ lua/plugins/git.lua | 126 ++++ lua/plugins/lint.lua | 24 + lua/plugins/lsp.lua | 263 +++++++++ lua/plugins/markdown.lua | 12 + lua/plugins/rust.lua | 31 + lua/plugins/telescope.lua | 70 +++ lua/plugins/treesitter.lua | 113 ++++ lua/plugins/ui.lua | 103 ++++ lua/plugins/undo.lua | 5 + lua/plugins/utils.lua | 10 + 21 files changed, 1048 insertions(+), 1032 deletions(-) create mode 100644 lua/config/highlight_yank.lua create mode 100644 lua/config/init.lua create mode 100644 lua/config/keymaps.lua create mode 100644 lua/config/netrw.lua create mode 100644 lua/config/options.lua create mode 100644 lua/config/restore_cursor.lua create mode 100644 lua/plugins/colorscheme.lua create mode 100644 lua/plugins/comment.lua create mode 100644 lua/plugins/flash.lua create mode 100644 lua/plugins/format.lua create mode 100644 lua/plugins/git.lua create mode 100644 lua/plugins/lint.lua create mode 100644 lua/plugins/lsp.lua create mode 100644 lua/plugins/markdown.lua create mode 100644 lua/plugins/rust.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/treesitter.lua create mode 100644 lua/plugins/ui.lua create mode 100644 lua/plugins/undo.lua create mode 100644 lua/plugins/utils.lua diff --git a/init.lua b/init.lua index cd212c4..2532fd4 100644 --- a/init.lua +++ b/init.lua @@ -1,185 +1,7 @@ ------------------------------------------------------------------------------- --- Options +-- Modular Config ------------------------------------------------------------------------------- --- Set highlight on search -vim.opt.hlsearch = false -vim.opt.incsearch = true - --- Make line numbers default -vim.opt.nu = true -vim.opt.relativenumber = true - --- Tab settings -vim.opt.tabstop = 4 -vim.opt.softtabstop = 4 -vim.opt.shiftwidth = 4 -vim.opt.expandtab = true - --- Lazy redraw for crazy macros ---vim.opt.lazyredraw = true - --- A lot of plugins depends on hidden true -vim.opt.hidden = true - --- set command line height to zero/two lines --- vim.opt.cmdheight = 2 -vim.opt.cmdheight = 0 - --- Statusbar -vim.opt.laststatus = 3 - --- Winbar on top of the windows -vim.opt.winbar = "%=%m %f" - --- Enable mouse mode -vim.opt.mouse = "a" - --- Scrolling -vim.opt.scrolloff = 8 -vim.opt.sidescrolloff = 8 - --- Time in milliseconds to wait for a mapped sequence to complete -vim.opt.timeoutlen = 50 - --- No wrap -vim.opt.wrap = false - --- Enable break indent -vim.opt.breakindent = true - --- Better undo history -vim.opt.swapfile = false -vim.opt.backup = false -vim.opt.undodir = vim.fn.stdpath("data") .. "undo" -vim.opt.undofile = true - --- Case insensitive searching UNLESS /C or capital in search -vim.opt.ignorecase = true -vim.opt.smartcase = true - --- Decrease update time -vim.opt.updatetime = 250 -vim.wo.signcolumn = "yes" - --- color column -vim.opt.colorcolumn = "80" - --- Window splitting -vim.opt.splitbelow = true -vim.opt.splitright = true - --- [[ Basic Keymaps ]] --- Set as the leader key --- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) -vim.g.mapleader = " " -vim.g.maplocalleader = " " - --- Keymaps for better default experience --- See `:help vim.keymap.set()` -vim.keymap.set({ "n", "v" }, "", "", { silent = true }) -vim.keymap.set("n", "Q", "") - --- File explorer -vim.keymap.set("n", "", vim.cmd.Ex) - --- Move to window using the hjkl keys -vim.keymap.set("n", "", "h", { desc = "Go to left window", remap = true }) -vim.keymap.set("n", "", "j", { desc = "Go to lower window", remap = true }) -vim.keymap.set("n", "", "k", { desc = "Go to upper window", remap = true }) -vim.keymap.set("n", "", "l", { desc = "Go to right window", remap = true }) - --- Resize window using arrow keys -vim.keymap.set("n", "", "resize +2", { desc = "Increase window height" }) -vim.keymap.set("n", "", "resize -2", { desc = "Decrease window height" }) -vim.keymap.set("n", "", "vertical resize -2", { desc = "Decrease window width" }) -vim.keymap.set("n", "", "vertical resize +2", { desc = "Increase window width" }) - --- Better movement -vim.keymap.set("n", "J", "mzJ`z") -vim.keymap.set("n", "", "zz") -vim.keymap.set("n", "", "zz") -vim.keymap.set("n", "n", "nzzzv") -vim.keymap.set("n", "N", "Nzzzv") - --- better indenting -vim.keymap.set("v", "<", "", ">gv") - --- Clear search, diff update and redraw --- taken from runtime/lua/_editor.lua -vim.keymap.set( - "n", - "R", - "nohlsearchdiffupdatenormal! ", - { desc = "[R]edraw / clear hlsearch / diff update" } -) - --- J/K to move up/down visual lines -vim.keymap.set("v", "J", ":m '>+1gv=gv") -vim.keymap.set("v", "K", ":m '<-2gv=gv") - --- Remap for dealing with word wrap -vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) -vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) - --- Easy save -vim.keymap.set("n", "w", "w", { silent = true, desc = "[S]ave File" }) - --- Easy Quit -vim.keymap.set("n", "q", "q", { silent = true, desc = "[Q]uit" }) -vim.keymap.set("n", "Q", "qa!", { silent = true, desc = "[Q]uit Force All" }) - --- Global Yank/Paste -vim.keymap.set( - { "n", "v" }, - "y", - '"*y :let @+=@*', - { noremap = true, silent = true, desc = "Global [Y]ank" } -) -vim.keymap.set({ "n", "v" }, "p", '"+p', { noremap = true, silent = true, desc = "Global [P]aste" }) - -------------------------------------------------------------------------------- --- Netrw Customizations -------------------------------------------------------------------------------- - -vim.g.netrw_browse_split = 0 -vim.g.netrw_banner = 0 -vim.g.netrw_winsize = 25 - -vim.api.nvim_create_autocmd("filetype", { - pattern = "netrw", - desc = "Better mappings for netrw", - callback = function() - -- edit new file - vim.keymap.set("n", "n", "%", { remap = true, buffer = true }) - -- rename file - vim.keymap.set("n", "r", "R", { remap = true, buffer = true }) - end, -}) - -------------------------------------------------------------------------------- --- Highlight on Yank -------------------------------------------------------------------------------- --- See `:help vim.highlight.on_yank()` -local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true }) -vim.api.nvim_create_autocmd("TextYankPost", { - callback = function() - vim.highlight.on_yank() - end, - group = highlight_group, - pattern = "*", -}) - -------------------------------------------------------------------------------- --- Restore Cursors -------------------------------------------------------------------------------- --- See `:help restore-cursor` -local restore_group = vim.api.nvim_create_augroup("RestoreGroup", { clear = true }) -vim.api.nvim_create_autocmd("BufRead", { - command = [[call setpos(".", getpos("'\""))]], - group = restore_group, - pattern = "*", -}) +require("config") ------------------------------------------------------------------------------- -- Bootstrap Package Manager @@ -200,858 +22,7 @@ vim.opt.rtp:prepend(lazypath) ------------------------------------------------------------------------------- -- Plugins ------------------------------------------------------------------------------- -require("lazy").setup({ - { - "folke/tokyonight.nvim", -- Set colorscheme to Gruvbox Theme - lazy = false, -- make sure we load this during startup if it is your main colorscheme - priority = 1000, -- make sure to load this before all - config = function() - require("tokyonight").setup({ - transparent = true, - }) - vim.o.termguicolors = true - vim.cmd.colorscheme("tokyonight") - end, - keys = { - { "l", "Lazy", desc = "[L]azy" }, - }, - }, - { - "nvim-lualine/lualine.nvim", -- Fancier statusline - event = "VeryLazy", - dependencies = { "folke/tokyonight.nvim" }, - config = function() - require("lualine").setup({ - options = { - icons_enabled = false, - theme = "tokyonight", - component_separators = "|", - section_separators = "", - }, - }) - end, - }, - { - "nvim-telescope/telescope.nvim", -- Telescope - branch = "0.1.x", - dependencies = "nvim-lua/plenary.nvim", - keys = { - { "?", "Telescope oldfiles", desc = "[?] Find recently opened files" }, - { "", "Telescope buffers", desc = "[ ] Find existing buffers" }, - { - "/", - "Telescope current_buffer_fuzzy_find", - desc = "[/] Fuzzily search in current buffer]", - }, - { "sr", "Telescope resume", desc = "[R]esume Previous Seasch" }, - { "sf", "Telescope git_files", desc = "[F]iles" }, - { "sF", "Telescope find_files", desc = "[F]iles All" }, - { "sh", "Telescope help_tags", desc = "[H]elp" }, - { "sw", "Telescope grep_string", desc = "Current [W]ord" }, - { "sg", "Telescope live_grep", desc = "[G]rep" }, - { "sd", "Telescope diagnostics", desc = "[D]iagnostics" }, - { "sm", "Telescope marks", desc = "[M]arks" }, - { "sc", "Telescope git_bcommits", desc = "[C]ommits File" }, - { "sC", "Telescope git_commits", desc = "[C]ommits" }, - { "ss", "Telescope git_status", desc = "[S]tatus" }, - { "sS", "Telescope git_stash", desc = "[S]tash" }, - { "sT", "Telescope git_stash", desc = "[T]reesitter" }, - }, - config = function() - -- See `:help telescope` and `:help telescope.setup()` - require("telescope").setup({ - defaults = { - mappings = { - i = { - [""] = false, - [""] = false, - [""] = "move_selection_next", - [""] = "move_selection_previous", - [""] = function(...) - return require("telescope.actions").cycle_history_next(...) - end, - [""] = function(...) - return require("telescope.actions").cycle_history_prev(...) - end, - [""] = function(...) - return require("telescope.actions").preview_scrolling_down(...) - end, - [""] = function(...) - return require("telescope.actions").preview_scrolling_up(...) - end, - }, - n = { - ["q"] = function(...) - return require("telescope.actions").close(...) - end, - }, - }, - }, - }) - end, - }, - { - -- LSP Configuration & Plugins - "neovim/nvim-lspconfig", - event = { "BufReadPre", "BufNewFile" }, - dependencies = { - "hrsh7th/cmp-nvim-lsp", -- LSP source for nvim-cmp - "hrsh7th/nvim-cmp", -- Autocompletion plugin - "hrsh7th/cmp-buffer", -- nvim-cmp source for buffer words - "hrsh7th/cmp-path", -- nvim-cmp source for filesystem paths - "hrsh7th/cmp-nvim-lua", -- nvim-cmp source for neovim Lua API - "saadparwaiz1/cmp_luasnip", -- Snippets source for nvim-cmp - "L3MON4D3/LuaSnip", -- Snippets plugin - "folke/neodev.nvim", -- Neovim development Lua utils - "petertriho/cmp-git", -- nvim-cmp source for git - -- Copilot - { - "zbirenbaum/copilot.lua", - cmd = "Copilot", - build = ":Copilot auth", - opts = { - suggestion = { enabled = false }, - panel = { enabled = false }, - filetypes = { - markdown = true, - help = true, - }, - }, - keys = { - { - "cp", - function() - if require("copilot.client").is_disabled() then - vim.cmd("Copilot enable") - else - vim.cmd("Copilot disable") - end - end, - desc = "Co[p]ilot Toggle", - }, - }, - }, - { - "zbirenbaum/copilot-cmp", - dependencies = "copilot.lua", - config = true, - }, - }, - config = function() - -- IMPORTANT: make sure to setup neodev BEFORE lspconfig - require("neodev").setup() - local lsp = require("lspconfig") - -- Global mappings. - -- See `:help vim.diagnostic.*` for documentation on any of the below functions - vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Previous [D]iagnostics" }) - vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Next [D]iagnostics" }) - vim.keymap.set("n", "e", vim.diagnostic.open_float, { desc = "[D]iagnostics: Op[e]n Float" }) - vim.keymap.set("n", "k", vim.diagnostic.setloclist, { desc = "[D]iagnostics: List" }) - -- Use LspAttach autocommand to only map the following keys - -- after the language server attaches to the current buffer - vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("UserLspConfig", {}), - callback = function(ev) - -- Enable completion triggered by - vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" - -- Buffer local mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - -- Code Actions - vim.keymap.set("n", "cr", vim.lsp.buf.rename, { desc = "[R]ename" }) - vim.keymap.set("n", "ca", vim.lsp.buf.code_action, { desc = "Code [A]ction" }) - -- Definitions - vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "[G]oto [D]efinition" }) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { desc = "[G]oto [I]mplementation" }) - vim.keymap.set("n", "gr", require("telescope.builtin").lsp_references) - vim.keymap.set( - "n", - "sD", - require("telescope.builtin").lsp_document_symbols, - { desc = "[D]ocument [S]ymbols" } - ) - vim.keymap.set( - "n", - "sy", - require("telescope.builtin").lsp_dynamic_workspace_symbols, - { desc = "S[y]mbols" } - ) - -- See `:help K` for why this keymap - vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Hover Documentation" }) - vim.keymap.set("n", "gS", vim.lsp.buf.signature_help, { desc = "[S]ignature Documentation" }) - -- Lesser used LSP functionality - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { desc = "[G]oto [D]eclaration" }) - vim.keymap.set("n", "D", vim.lsp.buf.type_definition, { desc = "Type [D]efinition" }) - vim.keymap.set("n", "cwa", vim.lsp.buf.add_workspace_folder, { desc = "[A]dd Folder" }) - vim.keymap.set("n", "cwr", vim.lsp.buf.remove_workspace_folder, { desc = "[R]emove Folder" }) - vim.keymap.set("n", "cwl", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, { desc = "[L]ist Folders" }) - end, - }) - -- nvim-cmp supports additional completion capabilities, so broadcast that to servers - -- Add additional capabilities supported by nvim-cmp - local capabilities = require("cmp_nvim_lsp").default_capabilities() - -- nvim-cmp setup - local cmp = require("cmp") - -- luasnip setup - local luasnip = require("luasnip") - require("luasnip.loaders.from_vscode").lazy_load() - luasnip.config.setup({}) - -- tab fix for copilot - local has_words_before = function() - if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then - return false - end - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil - end - cmp.setup({ - completion = { - completeopt = "menu,menuone,noinsert", - }, - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - enabled = function() - -- disable completion in comments - local context = require("cmp.config.context") - -- keep command mode completion enabled when cursor is in a comment - if vim.api.nvim_get_mode().mode == "c" then - return true - else - return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment") - end - end, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.scroll_docs(-4), -- Up - [""] = cmp.mapping.scroll_docs(4), -- Down - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }), - [""] = cmp.mapping.abort(), - [""] = vim.schedule_wrap(function(fallback) - if cmp.visible() and has_words_before() then - cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select }) - elseif luasnip.jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - }), - sources = { - { name = "copilot", group_index = 2 }, - { name = "nvim_lsp", group_index = 2 }, - { name = "luasnip", group_index = 2 }, - -- { name = "buffer", group_index = 2 }, - { name = "path", group_index = 2 }, - }, - sorting = { -- copilot_cmp suggestion - priority_weight = 2, - comparators = { - require("copilot_cmp.comparators").prioritize, - -- Below is the default comparator list and order for nvim-cmp - cmp.config.compare.offset, - -- cmp.config.compare.scopes, --this is commented in nvim-cmp too - cmp.config.compare.exact, - cmp.config.compare.score, - cmp.config.compare.recently_used, - cmp.config.compare.locality, - cmp.config.compare.kind, - cmp.config.compare.sort_text, - cmp.config.compare.length, - cmp.config.compare.order, - }, - }, - }) - -- If you want insert `(` after select function or method item - local cmp_autopairs = require("nvim-autopairs.completion.cmp") - cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) - -- Set configuration for specific filetype. - cmp.setup.filetype("gitcommit", { - sources = cmp.config.sources({ - { name = "git", group_index = 2 }, - { name = "buffer", group_index = 2 }, - { name = "copilot", group_index = 2 }, - }), - }) - cmp.setup.filetype({ "markdown", "text", "sql" }, { - sources = cmp.config.sources({ - { name = "buffer", group_index = 2 }, - { name = "copilot", group_index = 2 }, - }), - }) - -- Use buffer source for `/` and `?` - cmp.setup.cmdline({ "/", "?" }, { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = "buffer", group_index = 2 }, - }, - }) - -- Enable some language servers with the additional completion capabilities offered by nvim-cmp - lsp.pyright.setup({ capabilities = capabilities }) -- requires pyright to be installed - lsp.tsserver.setup({ capabilities = capabilities }) -- requires typescript-language-server to be installed - lsp.bashls.setup({ capabilities = capabilities }) -- requires bash-language-server to be installed - lsp.html.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed - lsp.cssls.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed - lsp.jsonls.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed - lsp.eslint.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed - lsp.rnix.setup({ capabilities = capabilities }) -- requires rnix-lsp to be installed - lsp.lua_ls.setup({ -- requires lua-language-server to be installed - capabilities = capabilities, - settings = { - Lua = { - telemetry = { enable = false }, - }, - }, - }) - lsp.rust_analyzer.setup({ -- requires rust-analyzer to be installed - capabilities = capabilities, - settings = { - ["rust-analyzer"] = { - cargo = { - allFeatures = true, - loadOutDirsFromCheck = true, - runBuildScripts = true, - }, - checkOnSave = true, - -- Add clippy lints for Rust - check = { - allFeatures = true, - command = "clippy", - extraArgs = { "--no-deps" }, - }, - imports = { - granularity = { - enforce = true, - group = "crate", - }, - }, - }, - }, - }) - end, - }, - { - "simrat39/rust-tools.nvim", - event = { "BufReadPre", "BufNewFile" }, - lazy = true, - opts = { - on_initialized = function() - vim.cmd([[ - augroup RustLSP - autocmd CursorHold *.rs silent! lua vim.lsp.buf.document_highlight() - autocmd CursorMoved,InsertEnter *.rs silent! lua vim.lsp.buf.clear_references() - autocmd BufEnter,CursorHold,InsertLeave *.rs silent! lua vim.lsp.codelens.refresh() - augroup END - ]]) - end, - }, - config = function() - local rt = require("rust-tools") - rt.setup({ - server = { - on_attach = function(_, bufnr) - -- Hover actions - vim.keymap.set("n", "K", "RustHoverActions", { buffer = bufnr, desc = "Hover Documentation" }) - -- Code action groups - vim.keymap.set("n", "ca", "RustCodeAction", { buffer = bufnr, desc = "Code [A]ction" }) - -- Run tests - vim.keymap.set("n", "ct", "RustRunnables", { buffer = bufnr, desc = "[T]est" }) - end, - }, - }) - end, - }, - -- LSP Formatters and Linters - -- null-ls is archived - { - "stevearc/conform.nvim", - event = "VeryLazy", - config = function() - require("conform").setup({ - formatters_by_ft = { - lua = { "stylua" }, - rust = { "rustfmt" }, - python = { "isort", "black" }, -- Conform will run multiple formatters sequentially - sh = { "shfmt", "shellharden" }, - fish = { "fish_indent" }, - nix = { "nixfmt" }, - markdown = { { "prettierd", "prettier" }, "markdownlint" }, -- Use a sub-list to run only the first available formatter - html = { { "prettierd", "prettier" } }, - css = { { "prettierd", "prettier" } }, - javascript = { { "prettierd", "prettier" } }, - typescript = { { "prettierd", "prettier" } }, - ["*"] = { "trim_whitespace" }, - }, - format_on_save = function(bufnr) - -- Disable with a global or buffer-local variable - if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then - return - end - return { timeout_ms = 500, lsp_fallback = true } - end, - }) - require("conform.formatters.markdownlint").command = "markdownlint-cli2" - vim.api.nvim_create_user_command("FormatDisable", function(args) - if args.bang then - -- FormatDisable! will disable formatting just for this buffer - vim.b.disable_autoformat = true - else - vim.g.disable_autoformat = true - end - end, { - desc = "Disable autoformat-on-save", - bang = true, - }) - vim.keymap.set("", "f", function() - require("conform").format({ async = true, lsp_fallback = true }) - end, { desc = "[F]ormat" }) - vim.api.nvim_create_user_command("FormatEnable", function() - vim.b.disable_autoformat = false - vim.g.disable_autoformat = false - end, { - desc = "Re-enable autoformat-on-save", - }) - vim.keymap.set("n", "F", function() - if vim.b.disable_autoformat or vim.g.disable_autoformat then - vim.cmd("FormatEnable") - else - vim.cmd("FormatDisable") - end - end, { desc = "Toggle [F]ormat" }) - end, - }, - { - "mfussenegger/nvim-lint", - config = function() - local lint = require("lint") - local markdownlint = require("lint").linters.markdownlint - markdownlint.cmd = "markdownlint-cli2" - lint.linters_by_ft = { - python = { "ruff" }, -- requires ruff to be installed - lua = { "luacheck" }, -- requires luacheck to be installed - sh = { "shellcheck" }, -- requires shellcheck to be installed - nix = { "nix" }, -- requires nix to be installed - markdown = { "markdownlint" }, -- requires markdownlint to be installed - javascript = { "eslint" }, -- requires eslint to be installed - javascriptreact = { "eslint" }, -- requires eslint to be installe - typescript = { "eslint" }, -- requires eslint to be installed - typescriptreact = { "eslint" }, -- requires eslint to be installed - } - vim.api.nvim_create_autocmd({ "InsertLeave", "BufWritePost" }, { - callback = function() - lint.try_lint() - end, - }) - end, - }, - { - "nvim-treesitter/nvim-treesitter", - event = { "BufReadPost", "BufNewFile" }, - build = ":TSUpdate", - config = function() - require("nvim-treesitter.configs").setup({ - ensure_installed = { - "bash", - "c", - "css", - "cpp", - "fish", - "html", - "javascript", - "jsdoc", - "json", - "lua", - "luadoc", - "luap", - "markdown", - "markdown_inline", - "python", - "query", - "regex", - "rust", - "tsx", - "typescript", - "toml", - "vim", - "vimdoc", - "yaml", - }, - auto_install = true, - highlight = { enable = true }, - indent = { enable = true, disable = { "python" } }, - 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 - ["aa"] = "@parameter.outer", - ["ia"] = "@parameter.inner", - ["af"] = "@function.outer", - ["if"] = "@function.inner", - ["ac"] = "@class.outer", - ["ic"] = "@class.inner", - }, - }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - ["]m"] = "@function.outer", - ["]]"] = "@class.outer", - }, - goto_next_end = { - ["]M"] = "@function.outer", - ["]["] = "@class.outer", - }, - goto_previous_start = { - ["[m"] = "@function.outer", - ["[["] = "@class.outer", - }, - goto_previous_end = { - ["[M"] = "@function.outer", - ["[]"] = "@class.outer", - }, - }, - swap = { - enable = true, - swap_next = { ["a"] = "@parameter.inner" }, - swap_previous = { ["A"] = "@parameter.inner" }, - }, - }, - extensions = { - fzf = { - fuzzy = true, -- false will only do exact matching - override_generic_sorter = true, -- override the generic sorter - override_file_sorter = true, -- override the file sorter - case_mode = "smart_case", -- or "ignore_case" or "respect_case" - }, - }, - }) - require("telescope").load_extension("fzf") - end, - }, - { - "nvim-treesitter/nvim-treesitter-context", - dependencies = "nvim-treesitter/nvim-treesitter", - event = { "BufReadPost", "BufNewFile" }, - config = true, - keys = { - { - "[c", - function() - require("treesitter-context").go_to_context() - end, - desc = "Go to [C]ontext", - }, - }, - }, - -- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available - { - "nvim-telescope/telescope-fzf-native.nvim", - build = "make", - cond = vim.fn.executable("make") == 1, - dependencies = { "nvim-treesitter/nvim-treesitter" }, - config = function() - require("telescope").load_extension("fzf") - end, - }, - -- Undotree - { - "mbbill/undotree", - evenvt = "VeryLazy", - keys = { { "u", "UndotreeToggle", desc = "[U]ndo Tree" } }, - }, - -- Git related plugins - { - "lewis6991/gitsigns.nvim", - event = { "BufReadPre", "BufNewFile" }, - config = function() - require("gitsigns").setup({ - signs = { - add = { text = "+" }, - change = { text = "~" }, - delete = { text = "_" }, - topdelete = { text = "‾" }, - changedelete = { text = "~" }, - }, - on_attach = function(bufnr) - local gs = package.loaded.gitsigns - -- Navigation - vim.keymap.set("n", "]h", function() - if vim.wo.diff then - return "]c" - end - vim.schedule(function() - gs.next_hunk() - end) - return "" - end, { expr = true, buffer = bufnr, desc = "Next [H]unk" }) - vim.keymap.set("n", "[h", function() - if vim.wo.diff then - return "[c" - end - vim.schedule(function() - gs.prev_hunk() - end) - return "" - end, { expr = true, buffer = bufnr, desc = "Previous [H]unk" }) - -- Actions - vim.keymap.set( - { "n", "v" }, - "hs", - "Gitsigns stage_hunk", - { buffer = bufnr, desc = "[S]tage" } - ) - vim.keymap.set( - { "n", "v" }, - "hr", - "Gitsigns reset_hunk", - { buffer = bufnr, desc = "[R]eset" } - ) - vim.keymap.set("n", "hS", gs.stage_buffer, { buffer = bufnr, desc = "[S]tage File" }) - vim.keymap.set("n", "hu", gs.undo_stage_hunk, { buffer = bufnr, desc = "[U]ndo" }) - vim.keymap.set("n", "hR", gs.reset_buffer, { buffer = bufnr, desc = "[R]eset File" }) - vim.keymap.set("n", "hp", gs.preview_hunk, { buffer = bufnr, desc = "[P]review" }) - vim.keymap.set("n", "hb", function() - gs.blame_line({ full = true }) - end, { buffer = bufnr, desc = "[B]lame line" }) - vim.keymap.set( - "n", - "hB", - gs.toggle_current_line_blame, - { buffer = bufnr, desc = "Toggle [B]lame Line" } - ) - vim.keymap.set("n", "hd", gs.diffthis, { buffer = bufnr, desc = "[D]iff This" }) - vim.keymap.set("n", "hD", function() - gs.diffthis("~") - end, { buffer = bufnr, desc = "[D]iff This ~" }) - vim.keymap.set("n", "ht", gs.toggle_deleted, { buffer = bufnr, desc = "[T]oggle Deleted" }) - -- Text object - vim.keymap.set( - { "o", "x" }, - "ih", - "Gitsigns select_hunk", - { buffer = bufnr, desc = "GitSigns Select Hunk" } - ) - end, - }) - end, - }, - { - "tpope/vim-fugitive", - event = "VeryLazy", - keys = { - { "gi", "Git", desc = "Fug[i]tive" }, - -- It allows me to easily set the branch I am pushing and any tracking - { "gt", "Git push -u origin ", desc = "Git Push [T]agging" }, - }, - config = function() - vim.api.nvim_create_autocmd({ "Filetype" }, { - pattern = { "fugitive" }, - callback = function() - -- Better commit remaps with no "enter" dialog - vim.keymap.set("n", "cc", "silent! Git commit --quiet", { silent = true, buffer = true }) - vim.keymap.set("n", "ca", "silent! Git commit --quiet --amend", { silent = true, buffer = true }) - vim.keymap.set( - "n", - "ce", - "silent! Git commit --quiet --amend --no-edit", - { silent = true, buffer = true } - ) - -- Push and Pull - vim.keymap.set("n", "p", "silent! Git pull", { silent = true, buffer = true }) - vim.keymap.set("n", "P", "silent! Git push", { silent = true, buffer = true }) - end, - }) - end, - }, - { - "tpope/vim-rhubarb", -- Fugitive-companion to interact with github - event = "VeryLazy", - config = function() - vim.api.nvim_create_autocmd({ "Filetype" }, { - pattern = { "gitcommit" }, - callback = function() - -- Autocompletion for @ and # - vim.keymap.set("i", "@", "@", { silent = true, buffer = true }) - vim.keymap.set("i", "#", "#", { silent = true, buffer = true }) - end, - }) - end, - }, - { - "kdheepak/lazygit.nvim", - dependencies = { - "nvim-lua/plenary.nvim", - }, - keys = { { "gg", "LazyGit", desc = "Lazy[g]it" } }, - }, - -- Miscellaneous - "tpope/vim-sleuth", -- Detect tabstop and shiftwidth automatically - { - "folke/which-key.nvim", -- popup with possible key bindings of the command you started typing - event = "VeryLazy", - opts = { - plugins = { spelling = true }, - defaults = { - mode = { "n", "v" }, - ["g"] = { name = "+goto" }, - ["]"] = { name = "+next" }, - ["["] = { name = "+prev" }, - ["c"] = { name = "+code" }, - ["cw"] = { name = "+workspace" }, - ["g"] = { name = "+git" }, - ["h"] = { name = "+hunks" }, - ["s"] = { name = "+search" }, - ["n"] = { name = "+noice" }, - }, - }, - config = function(_, opts) - local wk = require("which-key") - wk.setup(opts) - wk.register(opts.defaults) - end, - }, - { "numToStr/Comment.nvim", config = true, event = "VeryLazy" }, -- 'gc' to comment visual regions/lines - { "windwp/nvim-autopairs", config = true }, -- Autopair stuff like ({["' - { - "kylechui/nvim-surround", -- Surround selections - dependencies = { "nvim-treesitter/nvim-treesitter" }, - version = "*", - config = true, - }, - { - "lukas-reineke/indent-blankline.nvim", -- Indent guides - event = { "BufReadPost", "BufNewFile" }, - opts = { - char = "│", - filetype_exclude = { - "help", - "netrw", - "Trouble", - "lazy", - "notify", - }, - show_trailing_blankline_indent = false, - show_current_context = true, - }, - }, - { - "j-hui/fidget.nvim", -- Status for LSP stuff - tag = "legacy", - event = "LspAttach", - config = true, - }, - { - "folke/todo-comments.nvim", -- Highlight TODO, NOTE, FIX, WARN, HACK, PERF, and TEST - dependencies = { "nvim-lua/plenary.nvim" }, - event = { "BufReadPre", "BufNewFile" }, - config = true, - -- stylua: ignore - keys = { - { "st", "TodoTelescope", desc = "[T]odo" }, - { "K", "TodoLocList", desc = "Todo: List" }, - { "[t", "require('todo-comments').jump_prev()", desc = "Previous [T]odo" }, - { "]t", "require('todo-comments').jump_next()", desc = "Next [T]odo" }, - }, - }, - { - "folke/noice.nvim", -- Better UI - event = "VeryLazy", - dependencies = { - "MunifTanjim/nui.nvim", - "rcarriga/nvim-notify", - }, - config = function() - require("telescope").load_extension("noice") - require("noice").setup({ - lsp = { - -- override markdown rendering so that cmp and other plugins use Treesitter - override = { - ["vim.lsp.util.convert_input_to_markdown_lines"] = true, - ["vim.lsp.util.stylize_markdown"] = true, - ["cmp.entry.get_documentation"] = true, - }, - }, - presets = { - bottom_search = false, -- use a classic bottom cmdline for search - command_palette = true, -- position the cmdline and popupmenu together - long_message_to_split = true, -- long messages will be sent to a split - inc_rename = false, -- enables an input dialog for inc-rename.nvim - lsp_doc_border = true, -- add a border to hover docs and signature help - }, - }) - end, - -- stylua: ignore - keys = { - { "sn", "Telescope noice", desc = "[N]oice" }, - { "nl", function() require("noice").cmd("last") end, desc = - "[L]ast Message" }, - { "nh", function() require("noice").cmd("history") end, desc = "[H]istory" }, - { "na", function() require("noice").cmd("all") end, desc = "[A]ll" }, - { "nd", function() require("noice").cmd("dismiss") end, desc = - "[D]ismiss All" }, - { "", function() if not require("noice.lsp").scroll(4) then return "" end end, silent = true, - expr = true, - desc = - "Scroll [F]orward", mode = { - "i", "n", "s" } }, - { "", function() if not require("noice.lsp").scroll(-4) then return "" end end, silent = true, - expr = true, - desc = - "Scroll [B]ackward", mode = { - "i", "n", "s" } }, - }, - }, - { - "folke/flash.nvim", -- Amazing movements - event = "VeryLazy", - -- stylua: ignore - keys = { - { "s", mode = { "n", "o", "x" }, function() require("flash").jump() end, desc = "Flash" }, - -- { "S", mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, -- conflicts with nvim.surround `S`. - { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, - { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, - }, - }, - { - "iamcco/markdown-preview.nvim", - ft = "markdown", - event = "VeryLazy", - cmd = { "MarkdownPreview", "MarkdownPreviewStop" }, - build = function() - vim.fn["mkdp#util#install"]() - end, - keys = { - { "m", "MarkdownPreview", desc = "[M]arkdown Preview" }, - }, - }, -}) +require("lazy").setup("plugins") -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/config/highlight_yank.lua b/lua/config/highlight_yank.lua new file mode 100644 index 0000000..738e33a --- /dev/null +++ b/lua/config/highlight_yank.lua @@ -0,0 +1,12 @@ +------------------------------------------------------------------------------- +-- Highlight on Yank +------------------------------------------------------------------------------- +-- See `:help vim.highlight.on_yank()` +local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true }) +vim.api.nvim_create_autocmd("TextYankPost", { + callback = function() + vim.highlight.on_yank() + end, + group = highlight_group, + pattern = "*", +}) diff --git a/lua/config/init.lua b/lua/config/init.lua new file mode 100644 index 0000000..ca0a035 --- /dev/null +++ b/lua/config/init.lua @@ -0,0 +1,5 @@ +require("config.options") +require("config.keymaps") +require("config.netrw") +require("config.highlight_yank") +require("config.restore_cursor") diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua new file mode 100644 index 0000000..806a21b --- /dev/null +++ b/lua/config/keymaps.lua @@ -0,0 +1,63 @@ +-- Keymaps for better default experience +-- See `:help vim.keymap.set()` +vim.keymap.set({ "n", "v" }, "", "", { silent = true }) +vim.keymap.set("n", "Q", "") + +-- File explorer +vim.keymap.set("n", "", vim.cmd.Ex) + +-- Move to window using the hjkl keys +vim.keymap.set("n", "", "h", { desc = "Go to left window", remap = true }) +vim.keymap.set("n", "", "j", { desc = "Go to lower window", remap = true }) +vim.keymap.set("n", "", "k", { desc = "Go to upper window", remap = true }) +vim.keymap.set("n", "", "l", { desc = "Go to right window", remap = true }) + +-- Resize window using arrow keys +vim.keymap.set("n", "", "resize +2", { desc = "Increase window height" }) +vim.keymap.set("n", "", "resize -2", { desc = "Decrease window height" }) +vim.keymap.set("n", "", "vertical resize -2", { desc = "Decrease window width" }) +vim.keymap.set("n", "", "vertical resize +2", { desc = "Increase window width" }) + +-- Better movement +vim.keymap.set("n", "J", "mzJ`z") +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "n", "nzzzv") +vim.keymap.set("n", "N", "Nzzzv") + +-- better indenting +vim.keymap.set("v", "<", "", ">gv") + +-- Clear search, diff update and redraw +-- taken from runtime/lua/_editor.lua +vim.keymap.set( + "n", + "R", + "nohlsearchdiffupdatenormal! ", + { desc = "[R]edraw / clear hlsearch / diff update" } +) + +-- J/K to move up/down visual lines +vim.keymap.set("v", "J", ":m '>+1gv=gv") +vim.keymap.set("v", "K", ":m '<-2gv=gv") + +-- Remap for dealing with word wrap +vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) +vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) + +-- Easy save +vim.keymap.set("n", "w", "w", { silent = true, desc = "[S]ave File" }) + +-- Easy Quit +vim.keymap.set("n", "q", "q", { silent = true, desc = "[Q]uit" }) +vim.keymap.set("n", "Q", "qa!", { silent = true, desc = "[Q]uit Force All" }) + +-- Global Yank/Paste +vim.keymap.set( + { "n", "v" }, + "y", + '"*y :let @+=@*', + { noremap = true, silent = true, desc = "Global [Y]ank" } +) +vim.keymap.set({ "n", "v" }, "p", '"+p', { noremap = true, silent = true, desc = "Global [P]aste" }) diff --git a/lua/config/netrw.lua b/lua/config/netrw.lua new file mode 100644 index 0000000..1789640 --- /dev/null +++ b/lua/config/netrw.lua @@ -0,0 +1,18 @@ +------------------------------------------------------------------------------- +-- Netrw Customizations +------------------------------------------------------------------------------- + +vim.g.netrw_browse_split = 0 +vim.g.netrw_banner = 0 +vim.g.netrw_winsize = 25 + +vim.api.nvim_create_autocmd("filetype", { + pattern = "netrw", + desc = "Better mappings for netrw", + callback = function() + -- edit new file + vim.keymap.set("n", "n", "%", { remap = true, buffer = true }) + -- rename file + vim.keymap.set("n", "r", "R", { remap = true, buffer = true }) + end, +}) diff --git a/lua/config/options.lua b/lua/config/options.lua new file mode 100644 index 0000000..bcd7dff --- /dev/null +++ b/lua/config/options.lua @@ -0,0 +1,75 @@ +------------------------------------------------------------------------------- +-- Options +------------------------------------------------------------------------------- +-- Set highlight on search +vim.opt.hlsearch = false +vim.opt.incsearch = true + +-- Make line numbers default +vim.opt.nu = true +vim.opt.relativenumber = true + +-- Tab settings +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true + +-- Lazy redraw for crazy macros +--vim.opt.lazyredraw = true + +-- A lot of plugins depends on hidden true +vim.opt.hidden = true + +-- set command line height to zero/two lines +-- vim.opt.cmdheight = 2 +vim.opt.cmdheight = 0 + +-- Statusbar +vim.opt.laststatus = 3 + +-- Winbar on top of the windows +vim.opt.winbar = "%=%m %f" + +-- Enable mouse mode +vim.opt.mouse = "a" + +-- Scrolling +vim.opt.scrolloff = 8 +vim.opt.sidescrolloff = 8 + +-- Time in milliseconds to wait for a mapped sequence to complete +vim.opt.timeoutlen = 50 + +-- No wrap +vim.opt.wrap = false + +-- Enable break indent +vim.opt.breakindent = true + +-- Better undo history +vim.opt.swapfile = false +vim.opt.backup = false +vim.opt.undodir = vim.fn.stdpath("data") .. "undo" +vim.opt.undofile = true + +-- Case insensitive searching UNLESS /C or capital in search +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- Decrease update time +vim.opt.updatetime = 250 +vim.wo.signcolumn = "yes" + +-- color column +vim.opt.colorcolumn = "80" + +-- Window splitting +vim.opt.splitbelow = true +vim.opt.splitright = true + +-- [[ Basic Keymaps ]] +-- Set as the leader key +-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) +vim.g.mapleader = " " +vim.g.maplocalleader = " " diff --git a/lua/config/restore_cursor.lua b/lua/config/restore_cursor.lua new file mode 100644 index 0000000..a420251 --- /dev/null +++ b/lua/config/restore_cursor.lua @@ -0,0 +1,10 @@ +------------------------------------------------------------------------------- +-- Restore Cursors +------------------------------------------------------------------------------- +-- See `:help restore-cursor` +local restore_group = vim.api.nvim_create_augroup("RestoreGroup", { clear = true }) +vim.api.nvim_create_autocmd("BufRead", { + command = [[call setpos(".", getpos("'\""))]], + group = restore_group, + pattern = "*", +}) diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..829e8ad --- /dev/null +++ b/lua/plugins/colorscheme.lua @@ -0,0 +1,32 @@ +return { + { + "folke/tokyonight.nvim", -- Set colorscheme to Gruvbox Theme + lazy = false, -- make sure we load this during startup if it is your main colorscheme + priority = 1000, -- make sure to load this before all + config = function() + require("tokyonight").setup({ + transparent = true, + }) + vim.o.termguicolors = true + vim.cmd.colorscheme("tokyonight") + end, + keys = { + { "l", "Lazy", desc = "[L]azy" }, + }, + }, + { + "nvim-lualine/lualine.nvim", -- Fancier statusline + event = "VeryLazy", + dependencies = { "folke/tokyonight.nvim" }, + config = function() + require("lualine").setup({ + options = { + icons_enabled = false, + theme = "tokyonight", + component_separators = "|", + section_separators = "", + }, + }) + end, + }, +} diff --git a/lua/plugins/comment.lua b/lua/plugins/comment.lua new file mode 100644 index 0000000..1d4426c --- /dev/null +++ b/lua/plugins/comment.lua @@ -0,0 +1,5 @@ +return { + "numToStr/Comment.nvim", + config = true, + event = "VeryLazy", +} diff --git a/lua/plugins/flash.lua b/lua/plugins/flash.lua new file mode 100644 index 0000000..6ad08f2 --- /dev/null +++ b/lua/plugins/flash.lua @@ -0,0 +1,11 @@ +return { + "folke/flash.nvim", -- Amazing movements + event = "VeryLazy", + -- stylua: ignore + keys = { + { "s", mode = { "n", "o", "x" }, function() require("flash").jump() end, desc = "Flash" }, + -- { "S", mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, -- conflicts with nvim.surround `S`. + { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, + { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, + }, +} diff --git a/lua/plugins/format.lua b/lua/plugins/format.lua new file mode 100644 index 0000000..eeb02e6 --- /dev/null +++ b/lua/plugins/format.lua @@ -0,0 +1,57 @@ +return { + "stevearc/conform.nvim", + event = "VeryLazy", + config = function() + require("conform").setup({ + formatters_by_ft = { + lua = { "stylua" }, + rust = { "rustfmt" }, + python = { "isort", "black" }, -- Conform will run multiple formatters sequentially + sh = { "shfmt", "shellharden" }, + fish = { "fish_indent" }, + nix = { "nixfmt" }, + markdown = { { "prettierd", "prettier" }, "markdownlint" }, -- Use a sub-list to run only the first available formatter + html = { { "prettierd", "prettier" } }, + css = { { "prettierd", "prettier" } }, + javascript = { { "prettierd", "prettier" } }, + typescript = { { "prettierd", "prettier" } }, + ["*"] = { "trim_whitespace" }, + }, + format_on_save = function(bufnr) + -- Disable with a global or buffer-local variable + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + return { timeout_ms = 500, lsp_fallback = true } + end, + }) + require("conform.formatters.markdownlint").command = "markdownlint-cli2" + vim.api.nvim_create_user_command("FormatDisable", function(args) + if args.bang then + -- FormatDisable! will disable formatting just for this buffer + vim.b.disable_autoformat = true + else + vim.g.disable_autoformat = true + end + end, { + desc = "Disable autoformat-on-save", + bang = true, + }) + vim.keymap.set("", "f", function() + require("conform").format({ async = true, lsp_fallback = true }) + end, { desc = "[F]ormat" }) + vim.api.nvim_create_user_command("FormatEnable", function() + vim.b.disable_autoformat = false + vim.g.disable_autoformat = false + end, { + desc = "Re-enable autoformat-on-save", + }) + vim.keymap.set("n", "F", function() + if vim.b.disable_autoformat or vim.g.disable_autoformat then + vim.cmd("FormatEnable") + else + vim.cmd("FormatDisable") + end + end, { desc = "Toggle [F]ormat" }) + end, +} diff --git a/lua/plugins/git.lua b/lua/plugins/git.lua new file mode 100644 index 0000000..fd71a8b --- /dev/null +++ b/lua/plugins/git.lua @@ -0,0 +1,126 @@ +return { + { + "lewis6991/gitsigns.nvim", + event = { "BufReadPre", "BufNewFile" }, + config = function() + require("gitsigns").setup({ + signs = { + add = { text = "+" }, + change = { text = "~" }, + delete = { text = "_" }, + topdelete = { text = "‾" }, + changedelete = { text = "~" }, + }, + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + -- Navigation + vim.keymap.set("n", "]h", function() + if vim.wo.diff then + return "]c" + end + vim.schedule(function() + gs.next_hunk() + end) + return "" + end, { expr = true, buffer = bufnr, desc = "Next [H]unk" }) + vim.keymap.set("n", "[h", function() + if vim.wo.diff then + return "[c" + end + vim.schedule(function() + gs.prev_hunk() + end) + return "" + end, { expr = true, buffer = bufnr, desc = "Previous [H]unk" }) + -- Actions + vim.keymap.set( + { "n", "v" }, + "hs", + "Gitsigns stage_hunk", + { buffer = bufnr, desc = "[S]tage" } + ) + vim.keymap.set( + { "n", "v" }, + "hr", + "Gitsigns reset_hunk", + { buffer = bufnr, desc = "[R]eset" } + ) + vim.keymap.set("n", "hS", gs.stage_buffer, { buffer = bufnr, desc = "[S]tage File" }) + vim.keymap.set("n", "hu", gs.undo_stage_hunk, { buffer = bufnr, desc = "[U]ndo" }) + vim.keymap.set("n", "hR", gs.reset_buffer, { buffer = bufnr, desc = "[R]eset File" }) + vim.keymap.set("n", "hp", gs.preview_hunk, { buffer = bufnr, desc = "[P]review" }) + vim.keymap.set("n", "hb", function() + gs.blame_line({ full = true }) + end, { buffer = bufnr, desc = "[B]lame line" }) + vim.keymap.set( + "n", + "hB", + gs.toggle_current_line_blame, + { buffer = bufnr, desc = "Toggle [B]lame Line" } + ) + vim.keymap.set("n", "hd", gs.diffthis, { buffer = bufnr, desc = "[D]iff This" }) + vim.keymap.set("n", "hD", function() + gs.diffthis("~") + end, { buffer = bufnr, desc = "[D]iff This ~" }) + vim.keymap.set("n", "ht", gs.toggle_deleted, { buffer = bufnr, desc = "[T]oggle Deleted" }) + -- Text object + vim.keymap.set( + { "o", "x" }, + "ih", + "Gitsigns select_hunk", + { buffer = bufnr, desc = "GitSigns Select Hunk" } + ) + end, + }) + end, + }, + { + "tpope/vim-fugitive", + event = "VeryLazy", + keys = { + { "gi", "Git", desc = "Fug[i]tive" }, + -- It allows me to easily set the branch I am pushing and any tracking + { "gt", "Git push -u origin ", desc = "Git Push [T]agging" }, + }, + config = function() + vim.api.nvim_create_autocmd({ "Filetype" }, { + pattern = { "fugitive" }, + callback = function() + -- Better commit remaps with no "enter" dialog + vim.keymap.set("n", "cc", "silent! Git commit --quiet", { silent = true, buffer = true }) + vim.keymap.set("n", "ca", "silent! Git commit --quiet --amend", { silent = true, buffer = true }) + vim.keymap.set( + "n", + "ce", + "silent! Git commit --quiet --amend --no-edit", + { silent = true, buffer = true } + ) + -- Push and Pull + vim.keymap.set("n", "p", "silent! Git pull", { silent = true, buffer = true }) + vim.keymap.set("n", "P", "silent! Git push", { silent = true, buffer = true }) + end, + }) + end, + }, + { + "tpope/vim-rhubarb", -- Fugitive-companion to interact with github + event = "VeryLazy", + config = function() + vim.api.nvim_create_autocmd({ "Filetype" }, { + pattern = { "gitcommit" }, + callback = function() + -- Autocompletion for @ and # + vim.keymap.set("i", "@", "@", { silent = true, buffer = true }) + vim.keymap.set("i", "#", "#", { silent = true, buffer = true }) + end, + }) + end, + }, + { + "kdheepak/lazygit.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + }, + keys = { { "gg", "LazyGit", desc = "Lazy[g]it" } }, + }, +} diff --git a/lua/plugins/lint.lua b/lua/plugins/lint.lua new file mode 100644 index 0000000..5d3b9ef --- /dev/null +++ b/lua/plugins/lint.lua @@ -0,0 +1,24 @@ +return { + "mfussenegger/nvim-lint", + config = function() + local lint = require("lint") + local markdownlint = require("lint").linters.markdownlint + markdownlint.cmd = "markdownlint-cli2" + lint.linters_by_ft = { + python = { "ruff" }, -- requires ruff to be installed + lua = { "luacheck" }, -- requires luacheck to be installed + sh = { "shellcheck" }, -- requires shellcheck to be installed + nix = { "nix" }, -- requires nix to be installed + markdown = { "markdownlint" }, -- requires markdownlint to be installed + javascript = { "eslint" }, -- requires eslint to be installed + javascriptreact = { "eslint" }, -- requires eslint to be installe + typescript = { "eslint" }, -- requires eslint to be installed + typescriptreact = { "eslint" }, -- requires eslint to be installed + } + vim.api.nvim_create_autocmd({ "InsertLeave", "BufWritePost" }, { + callback = function() + lint.try_lint() + end, + }) + end, +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..dd4e6fa --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,263 @@ +return { + { + -- LSP Configuration & Plugins + "neovim/nvim-lspconfig", + event = { "BufReadPre", "BufNewFile" }, + dependencies = { + "hrsh7th/cmp-nvim-lsp", -- LSP source for nvim-cmp + "hrsh7th/nvim-cmp", -- Autocompletion plugin + "hrsh7th/cmp-buffer", -- nvim-cmp source for buffer words + "hrsh7th/cmp-path", -- nvim-cmp source for filesystem paths + "hrsh7th/cmp-nvim-lua", -- nvim-cmp source for neovim Lua API + "saadparwaiz1/cmp_luasnip", -- Snippets source for nvim-cmp + "L3MON4D3/LuaSnip", -- Snippets plugin + "folke/neodev.nvim", -- Neovim development Lua utils + "petertriho/cmp-git", -- nvim-cmp source for git + -- Copilot + { + "zbirenbaum/copilot.lua", + cmd = "Copilot", + build = ":Copilot auth", + opts = { + suggestion = { enabled = false }, + panel = { enabled = false }, + filetypes = { + markdown = true, + help = true, + }, + }, + keys = { + { + "cp", + function() + if require("copilot.client").is_disabled() then + vim.cmd("Copilot enable") + else + vim.cmd("Copilot disable") + end + end, + desc = "Co[p]ilot Toggle", + }, + }, + }, + { + "zbirenbaum/copilot-cmp", + dependencies = "copilot.lua", + config = true, + }, + }, + config = function() + -- IMPORTANT: make sure to setup neodev BEFORE lspconfig + require("neodev").setup() + local lsp = require("lspconfig") + -- Global mappings. + -- See `:help vim.diagnostic.*` for documentation on any of the below functions + vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Previous [D]iagnostics" }) + vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Next [D]iagnostics" }) + vim.keymap.set("n", "e", vim.diagnostic.open_float, { desc = "[D]iagnostics: Op[e]n Float" }) + vim.keymap.set("n", "k", vim.diagnostic.setloclist, { desc = "[D]iagnostics: List" }) + -- Use LspAttach autocommand to only map the following keys + -- after the language server attaches to the current buffer + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("UserLspConfig", {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + -- Code Actions + vim.keymap.set("n", "cr", vim.lsp.buf.rename, { desc = "[R]ename" }) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, { desc = "Code [A]ction" }) + -- Definitions + vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "[G]oto [D]efinition" }) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { desc = "[G]oto [I]mplementation" }) + vim.keymap.set("n", "gr", require("telescope.builtin").lsp_references) + vim.keymap.set( + "n", + "sD", + require("telescope.builtin").lsp_document_symbols, + { desc = "[D]ocument [S]ymbols" } + ) + vim.keymap.set( + "n", + "sy", + require("telescope.builtin").lsp_dynamic_workspace_symbols, + { desc = "S[y]mbols" } + ) + -- See `:help K` for why this keymap + vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Hover Documentation" }) + vim.keymap.set("n", "gS", vim.lsp.buf.signature_help, { desc = "[S]ignature Documentation" }) + -- Lesser used LSP functionality + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { desc = "[G]oto [D]eclaration" }) + vim.keymap.set("n", "D", vim.lsp.buf.type_definition, { desc = "Type [D]efinition" }) + vim.keymap.set("n", "cwa", vim.lsp.buf.add_workspace_folder, { desc = "[A]dd Folder" }) + vim.keymap.set("n", "cwr", vim.lsp.buf.remove_workspace_folder, { desc = "[R]emove Folder" }) + vim.keymap.set("n", "cwl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, { desc = "[L]ist Folders" }) + end, + }) + -- nvim-cmp supports additional completion capabilities, so broadcast that to servers + -- Add additional capabilities supported by nvim-cmp + local capabilities = require("cmp_nvim_lsp").default_capabilities() + -- nvim-cmp setup + local cmp = require("cmp") + -- luasnip setup + local luasnip = require("luasnip") + require("luasnip.loaders.from_vscode").lazy_load() + luasnip.config.setup({}) + -- tab fix for copilot + local has_words_before = function() + if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then + return false + end + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil + end + cmp.setup({ + completion = { + completeopt = "menu,menuone,noinsert", + }, + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + enabled = function() + -- disable completion in comments + local context = require("cmp.config.context") + -- keep command mode completion enabled when cursor is in a comment + if vim.api.nvim_get_mode().mode == "c" then + return true + else + return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment") + end + end, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), -- Up + [""] = cmp.mapping.scroll_docs(4), -- Down + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + [""] = cmp.mapping.abort(), + [""] = vim.schedule_wrap(function(fallback) + if cmp.visible() and has_words_before() then + cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select }) + elseif luasnip.jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + }), + sources = { + { name = "copilot", group_index = 2 }, + { name = "nvim_lsp", group_index = 2 }, + { name = "luasnip", group_index = 2 }, + -- { name = "buffer", group_index = 2 }, + { name = "path", group_index = 2 }, + }, + sorting = { -- copilot_cmp suggestion + priority_weight = 2, + comparators = { + require("copilot_cmp.comparators").prioritize, + -- Below is the default comparator list and order for nvim-cmp + cmp.config.compare.offset, + -- cmp.config.compare.scopes, --this is commented in nvim-cmp too + cmp.config.compare.exact, + cmp.config.compare.score, + cmp.config.compare.recently_used, + cmp.config.compare.locality, + cmp.config.compare.kind, + cmp.config.compare.sort_text, + cmp.config.compare.length, + cmp.config.compare.order, + }, + }, + }) + -- If you want insert `(` after select function or method item + local cmp_autopairs = require("nvim-autopairs.completion.cmp") + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) + -- Set configuration for specific filetype. + cmp.setup.filetype("gitcommit", { + sources = cmp.config.sources({ + { name = "git", group_index = 2 }, + { name = "buffer", group_index = 2 }, + { name = "copilot", group_index = 2 }, + }), + }) + cmp.setup.filetype({ "markdown", "text", "sql" }, { + sources = cmp.config.sources({ + { name = "buffer", group_index = 2 }, + { name = "copilot", group_index = 2 }, + }), + }) + -- Use buffer source for `/` and `?` + cmp.setup.cmdline({ "/", "?" }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer", group_index = 2 }, + }, + }) + -- Enable some language servers with the additional completion capabilities offered by nvim-cmp + lsp.pyright.setup({ capabilities = capabilities }) -- requires pyright to be installed + lsp.tsserver.setup({ capabilities = capabilities }) -- requires typescript-language-server to be installed + lsp.bashls.setup({ capabilities = capabilities }) -- requires bash-language-server to be installed + lsp.html.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed + lsp.cssls.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed + lsp.jsonls.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed + lsp.eslint.setup({ capabilities = capabilities }) -- requires vscode-langservers-extracted to be installed + lsp.rnix.setup({ capabilities = capabilities }) -- requires rnix-lsp to be installed + lsp.lua_ls.setup({ -- requires lua-language-server to be installed + capabilities = capabilities, + settings = { + Lua = { + telemetry = { enable = false }, + }, + }, + }) + lsp.rust_analyzer.setup({ -- requires rust-analyzer to be installed + capabilities = capabilities, + settings = { + ["rust-analyzer"] = { + cargo = { + allFeatures = true, + loadOutDirsFromCheck = true, + runBuildScripts = true, + }, + checkOnSave = true, + -- Add clippy lints for Rust + check = { + allFeatures = true, + command = "clippy", + extraArgs = { "--no-deps" }, + }, + imports = { + granularity = { + enforce = true, + group = "crate", + }, + }, + }, + }, + }) + end, + }, + { + "j-hui/fidget.nvim", -- Status for LSP stuff + tag = "legacy", + event = "LspAttach", + config = true, + }, +} diff --git a/lua/plugins/markdown.lua b/lua/plugins/markdown.lua new file mode 100644 index 0000000..18d1354 --- /dev/null +++ b/lua/plugins/markdown.lua @@ -0,0 +1,12 @@ +return { + "iamcco/markdown-preview.nvim", + ft = "markdown", + event = "VeryLazy", + cmd = { "MarkdownPreview", "MarkdownPreviewStop" }, + build = function() + vim.fn["mkdp#util#install"]() + end, + keys = { + { "m", "MarkdownPreview", desc = "[M]arkdown Preview" }, + }, +} diff --git a/lua/plugins/rust.lua b/lua/plugins/rust.lua new file mode 100644 index 0000000..43e2d19 --- /dev/null +++ b/lua/plugins/rust.lua @@ -0,0 +1,31 @@ +return { + "simrat39/rust-tools.nvim", + event = { "BufReadPre", "BufNewFile" }, + lazy = true, + opts = { + on_initialized = function() + vim.cmd([[ + augroup RustLSP + autocmd CursorHold *.rs silent! lua vim.lsp.buf.document_highlight() + autocmd CursorMoved,InsertEnter *.rs silent! lua vim.lsp.buf.clear_references() + autocmd BufEnter,CursorHold,InsertLeave *.rs silent! lua vim.lsp.codelens.refresh() + augroup END + ]]) + end, + }, + config = function() + local rt = require("rust-tools") + rt.setup({ + server = { + on_attach = function(_, bufnr) + -- Hover actions + vim.keymap.set("n", "K", "RustHoverActions", { buffer = bufnr, desc = "Hover Documentation" }) + -- Code action groups + vim.keymap.set("n", "ca", "RustCodeAction", { buffer = bufnr, desc = "Code [A]ction" }) + -- Run tests + vim.keymap.set("n", "ct", "RustRunnables", { buffer = bufnr, desc = "[T]est" }) + end, + }, + }) + end, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..25f8c0c --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,70 @@ +return { + { + "nvim-telescope/telescope.nvim", -- Telescope + branch = "0.1.x", + dependencies = "nvim-lua/plenary.nvim", + keys = { + { "?", "Telescope oldfiles", desc = "[?] Find recently opened files" }, + { "", "Telescope buffers", desc = "[ ] Find existing buffers" }, + { + "/", + "Telescope current_buffer_fuzzy_find", + desc = "[/] Fuzzily search in current buffer]", + }, + { "sr", "Telescope resume", desc = "[R]esume Previous Seasch" }, + { "sf", "Telescope git_files", desc = "[F]iles" }, + { "sF", "Telescope find_files", desc = "[F]iles All" }, + { "sh", "Telescope help_tags", desc = "[H]elp" }, + { "sw", "Telescope grep_string", desc = "Current [W]ord" }, + { "sg", "Telescope live_grep", desc = "[G]rep" }, + { "sd", "Telescope diagnostics", desc = "[D]iagnostics" }, + { "sm", "Telescope marks", desc = "[M]arks" }, + { "sc", "Telescope git_bcommits", desc = "[C]ommits File" }, + { "sC", "Telescope git_commits", desc = "[C]ommits" }, + { "ss", "Telescope git_status", desc = "[S]tatus" }, + { "sS", "Telescope git_stash", desc = "[S]tash" }, + { "sT", "Telescope git_stash", desc = "[T]reesitter" }, + }, + config = function() + -- See `:help telescope` and `:help telescope.setup()` + require("telescope").setup({ + defaults = { + mappings = { + i = { + [""] = false, + [""] = false, + [""] = "move_selection_next", + [""] = "move_selection_previous", + [""] = function(...) + return require("telescope.actions").cycle_history_next(...) + end, + [""] = function(...) + return require("telescope.actions").cycle_history_prev(...) + end, + [""] = function(...) + return require("telescope.actions").preview_scrolling_down(...) + end, + [""] = function(...) + return require("telescope.actions").preview_scrolling_up(...) + end, + }, + n = { + ["q"] = function(...) + return require("telescope.actions").close(...) + end, + }, + }, + }, + }) + end, + }, + { + "nvim-telescope/telescope-fzf-native.nvim", + build = "make", + cond = vim.fn.executable("make") == 1, + dependencies = { "nvim-treesitter/nvim-treesitter" }, + config = function() + require("telescope").load_extension("fzf") + end, + }, +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..e173c8b --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,113 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + event = { "BufReadPost", "BufNewFile" }, + build = ":TSUpdate", + config = function() + require("nvim-treesitter.configs").setup({ + ensure_installed = { + "bash", + "c", + "css", + "cpp", + "fish", + "html", + "javascript", + "jsdoc", + "json", + "lua", + "luadoc", + "luap", + "markdown", + "markdown_inline", + "python", + "query", + "regex", + "rust", + "tsx", + "typescript", + "toml", + "vim", + "vimdoc", + "yaml", + }, + auto_install = true, + highlight = { enable = true }, + indent = { enable = true, disable = { "python" } }, + 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 + ["aa"] = "@parameter.outer", + ["ia"] = "@parameter.inner", + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + ["]m"] = "@function.outer", + ["]]"] = "@class.outer", + }, + goto_next_end = { + ["]M"] = "@function.outer", + ["]["] = "@class.outer", + }, + goto_previous_start = { + ["[m"] = "@function.outer", + ["[["] = "@class.outer", + }, + goto_previous_end = { + ["[M"] = "@function.outer", + ["[]"] = "@class.outer", + }, + }, + swap = { + enable = true, + swap_next = { ["a"] = "@parameter.inner" }, + swap_previous = { ["A"] = "@parameter.inner" }, + }, + }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + }, + }, + }) + require("telescope").load_extension("fzf") + end, + }, + { + "nvim-treesitter/nvim-treesitter-context", + dependencies = "nvim-treesitter/nvim-treesitter", + event = { "BufReadPost", "BufNewFile" }, + config = true, + keys = { + { + "[c", + function() + require("treesitter-context").go_to_context() + end, + desc = "Go to [C]ontext", + }, + }, + }, +} diff --git a/lua/plugins/ui.lua b/lua/plugins/ui.lua new file mode 100644 index 0000000..5a34d00 --- /dev/null +++ b/lua/plugins/ui.lua @@ -0,0 +1,103 @@ +return { + { + "folke/which-key.nvim", -- popup with possible key bindings of the command you started typing + event = "VeryLazy", + opts = { + plugins = { spelling = true }, + defaults = { + mode = { "n", "v" }, + ["g"] = { name = "+goto" }, + ["]"] = { name = "+next" }, + ["["] = { name = "+prev" }, + ["c"] = { name = "+code" }, + ["cw"] = { name = "+workspace" }, + ["g"] = { name = "+git" }, + ["h"] = { name = "+hunks" }, + ["s"] = { name = "+search" }, + ["n"] = { name = "+noice" }, + }, + }, + config = function(_, opts) + local wk = require("which-key") + wk.setup(opts) + wk.register(opts.defaults) + end, + }, + { + "lukas-reineke/indent-blankline.nvim", -- Indent guides + event = { "BufReadPost", "BufNewFile" }, + opts = { + char = "│", + filetype_exclude = { + "help", + "netrw", + "Trouble", + "lazy", + "notify", + }, + show_trailing_blankline_indent = false, + show_current_context = true, + }, + }, + { + "folke/todo-comments.nvim", -- Highlight TODO, NOTE, FIX, WARN, HACK, PERF, and TEST + dependencies = { "nvim-lua/plenary.nvim" }, + event = { "BufReadPre", "BufNewFile" }, + config = true, + -- stylua: ignore + keys = { + { "st", "TodoTelescope", desc = "[T]odo" }, + { "K", "TodoLocList", desc = "Todo: List" }, + { "[t", "require('todo-comments').jump_prev()", desc = "Previous [T]odo" }, + { "]t", "require('todo-comments').jump_next()", desc = "Next [T]odo" }, + }, + }, + { + "folke/noice.nvim", -- Better UI + event = "VeryLazy", + dependencies = { + "MunifTanjim/nui.nvim", + "rcarriga/nvim-notify", + }, + config = function() + require("telescope").load_extension("noice") + require("noice").setup({ + lsp = { + -- override markdown rendering so that cmp and other plugins use Treesitter + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + ["cmp.entry.get_documentation"] = true, + }, + }, + presets = { + bottom_search = false, -- use a classic bottom cmdline for search + command_palette = true, -- position the cmdline and popupmenu together + long_message_to_split = true, -- long messages will be sent to a split + inc_rename = false, -- enables an input dialog for inc-rename.nvim + lsp_doc_border = true, -- add a border to hover docs and signature help + }, + }) + end, + -- stylua: ignore + keys = { + { "sn", "Telescope noice", desc = "[N]oice" }, + { "nl", function() require("noice").cmd("last") end, desc = + "[L]ast Message" }, + { "nh", function() require("noice").cmd("history") end, desc = "[H]istory" }, + { "na", function() require("noice").cmd("all") end, desc = "[A]ll" }, + { "nd", function() require("noice").cmd("dismiss") end, desc = + "[D]ismiss All" }, + { "", function() if not require("noice.lsp").scroll(4) then return "" end end, silent = true, + expr = true, + desc = + "Scroll [F]orward", mode = { + "i", "n", "s" } }, + { "", function() if not require("noice.lsp").scroll(-4) then return "" end end, silent = true, + expr = true, + desc = + "Scroll [B]ackward", mode = { + "i", "n", "s" } }, + }, + }, +} diff --git a/lua/plugins/undo.lua b/lua/plugins/undo.lua new file mode 100644 index 0000000..904112d --- /dev/null +++ b/lua/plugins/undo.lua @@ -0,0 +1,5 @@ +return { + "mbbill/undotree", + evenvt = "VeryLazy", + keys = { { "u", "UndotreeToggle", desc = "[U]ndo Tree" } }, +} diff --git a/lua/plugins/utils.lua b/lua/plugins/utils.lua new file mode 100644 index 0000000..87dcc73 --- /dev/null +++ b/lua/plugins/utils.lua @@ -0,0 +1,10 @@ +return { + "tpope/vim-sleuth", -- Detect tabstop and shiftwidth automatically + { "windwp/nvim-autopairs", config = true }, -- Autopair stuff like ({["' + { + "kylechui/nvim-surround", -- Surround selections + dependencies = { "nvim-treesitter/nvim-treesitter" }, + version = "*", + config = true, + }, +}