From a99b211b3bec43ebe3cdfa1899cba227d1d569a4 Mon Sep 17 00:00:00 2001 From: Ibrahim Muftee Date: Thu, 11 Apr 2024 23:20:57 -0500 Subject: Initial commit --- dot_config/nvim/lua/ibrahim/icons.lua | 62 ++++++++++ dot_config/nvim/lua/ibrahim/keys.lua | 124 +++++++++++++++++++ dot_config/nvim/lua/ibrahim/set.lua | 64 ++++++++++ dot_config/nvim/lua/plugins/commenter.lua | 11 ++ dot_config/nvim/lua/plugins/conform.lua | 47 ++++++++ dot_config/nvim/lua/plugins/fugitive.lua | 6 + dot_config/nvim/lua/plugins/gitsigns.lua | 19 +++ dot_config/nvim/lua/plugins/gruvbox.lua | 34 ++++++ dot_config/nvim/lua/plugins/harpoon.lua | 15 +++ dot_config/nvim/lua/plugins/lsp-lines.lua | 41 +++++++ dot_config/nvim/lua/plugins/lsp-zero.lua | 183 +++++++++++++++++++++++++++++ dot_config/nvim/lua/plugins/neotest.lua | 40 +++++++ dot_config/nvim/lua/plugins/oil.lua | 14 +++ dot_config/nvim/lua/plugins/telescope.lua | 10 ++ dot_config/nvim/lua/plugins/treesitter.lua | 144 +++++++++++++++++++++++ dot_config/nvim/lua/plugins/undotree.lua | 8 ++ dot_config/nvim/lua/plugins/which-key.lua | 41 +++++++ 17 files changed, 863 insertions(+) create mode 100644 dot_config/nvim/lua/ibrahim/icons.lua create mode 100644 dot_config/nvim/lua/ibrahim/keys.lua create mode 100644 dot_config/nvim/lua/ibrahim/set.lua create mode 100644 dot_config/nvim/lua/plugins/commenter.lua create mode 100644 dot_config/nvim/lua/plugins/conform.lua create mode 100644 dot_config/nvim/lua/plugins/fugitive.lua create mode 100644 dot_config/nvim/lua/plugins/gitsigns.lua create mode 100644 dot_config/nvim/lua/plugins/gruvbox.lua create mode 100644 dot_config/nvim/lua/plugins/harpoon.lua create mode 100644 dot_config/nvim/lua/plugins/lsp-lines.lua create mode 100644 dot_config/nvim/lua/plugins/lsp-zero.lua create mode 100644 dot_config/nvim/lua/plugins/neotest.lua create mode 100644 dot_config/nvim/lua/plugins/oil.lua create mode 100644 dot_config/nvim/lua/plugins/telescope.lua create mode 100644 dot_config/nvim/lua/plugins/treesitter.lua create mode 100644 dot_config/nvim/lua/plugins/undotree.lua create mode 100644 dot_config/nvim/lua/plugins/which-key.lua (limited to 'dot_config/nvim/lua') diff --git a/dot_config/nvim/lua/ibrahim/icons.lua b/dot_config/nvim/lua/ibrahim/icons.lua new file mode 100644 index 0000000..d6573ab --- /dev/null +++ b/dot_config/nvim/lua/ibrahim/icons.lua @@ -0,0 +1,62 @@ +return { + diagnostics = { + -- Error = " ", + -- Warn = " ", + -- Hint = " ", + -- Info = " ", + Error = " ", + Warn = " ", + -- Hint = " ", + Hint = "󰌵 ", + Info = " ", + }, + git = { + -- Change type + added = " ", + -- added = "✚" + modified = " ", + -- modified = "" + removed = " ", + deleted = "󱂑", + renamed = "󰑕", + -- Status type + untracked = "", + ignored = "", + unstaged = "", + staged = "", + conflict = "", + }, + gitsigns = { + -- Signs that will appear in the statusline column + added = "✚", + modified = "", + deleted = "", + }, + lsp = { + Text = "", + Method = "", + Function = "󰡱", + Constructor = "", + Field = "", + Variable = "󰫧", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", + }, +} diff --git a/dot_config/nvim/lua/ibrahim/keys.lua b/dot_config/nvim/lua/ibrahim/keys.lua new file mode 100644 index 0000000..fa44e69 --- /dev/null +++ b/dot_config/nvim/lua/ibrahim/keys.lua @@ -0,0 +1,124 @@ +-- Set leader key as Space +vim.g.mapleader = " " + +local function map(mode, left, right, opts) + local default_opts = { + noremap = true, + silent = true, + } + opts = opts or {} + -- "keep" mode preserves the values from the leftmost table, + -- so prioritize any options provided over the defaults + local full_opts = vim.tbl_extend("keep", opts, default_opts) + vim.keymap.set(mode, left, right, full_opts) +end + +-- Clear any highlighted searches when pressing Esc +-- This lets me leave hlsearch on by default while having an easy way to clear +-- it again. +map({ "i", "n" }, "", "noh", { desc = "Escape and clear hlsearch" }) + +-- Move lines while in visual mode with J and K +map("v", "J", ":m '>+1gv=gv") +map("v", "K", ":m '<-2gv=gv") + +-- Keep cursor in the same place when using J to join lines +map("n", "J", "mzJ`z") + +-- Center the screen when jumping around with C-d and C-u +map("n", "", "zz") +map("n", "", "zz") + +-- Center the screen when jumping to next / previous search terms +map("n", "n", "nzzzv") +map("n", "N", "Nzzzv") + +-- Quick maps to paste/delete without overwriting the current buffer +map("x", "p", '"_dP') +map({ "n", "v" }, "d", '"_dP') + +-- Easier split navigation +map("n", "", "h") +map("n", "", "j") +map("n", "", "k") +map("n", "", "l") + +-- System clipboard +map({ "n", "v" }, "cd", '"+d', { desc = "Clipboard delete" }) +map({ "n", "v" }, "cp", '"+p', { desc = "Clipboard paste" }) +map({ "n", "v" }, "cy", '"+y', { desc = "Clipboard yank" }) + +-- Map g- to netrw (temporary placeholder for oil) +-- map("n", "g-", vim.cmd.Ex, { desc = "Open netrw" }) + +vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("IbrahimLspConfig", {}), + callback = function(evt) + local function lsp_map(mode, lhs, rhs, desc) + local opts = { buffer = evt.buf, desc = "LSP: " .. (desc or "") } + map(mode, lhs, rhs, opts) + end + + local has_telescope, _ = pcall(require, "telescope") + local function lsp_telescope_map(mode, lhs, with_telescope_rhs, no_telescope_rhs, desc) + if has_telescope then + desc = desc .. " (Telescope)" + lsp_map(mode, lhs, with_telescope_rhs, desc) + else + lsp_map(mode, lhs, no_telescope_rhs, desc) + end + end + local function tele_builtin(name, opts) + return function() + require("telescope.builtin")[name](opts) + end + end + + -- Navigation + lsp_map("n", "gd", vim.lsp.buf.definition, "[G]oto [D]efinition") + lsp_map("n", "gt", vim.lsp.buf.type_definition, "[G]oto [t]ype Definition") + lsp_map("n", "gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") + lsp_map("n", "gr", vim.lsp.buf.references, "[G]oto [R]eferences") + lsp_map("n", "gI", vim.lsp.buf.implementation, "[G]oto [I]mplementation") + + lsp_telescope_map("n", "gr", tele_builtin("lsp_references"), vim.lsp.buf.references, "Go to references") + lsp_telescope_map( + "n", + "sn", + tele_builtin("lsp_document_symbols"), + vim.lsp.buf.document_symbol, + "Search document symbols" + ) + lsp_telescope_map( + "n", + "sN", + tele_builtin("lsp_dynamic_workspace_symbols"), + vim.lsp.buf.workspace_symbol, + "Search workspace symbols" + ) + + -- Code changes + lsp_map("n", "cr", vim.lsp.buf.rename, "Rename") + lsp_map("n", "ca", vim.lsp.buf.code_action, "Code actions") + + -- Diagnostics + lsp_map("n", "ds", vim.diagnostic.open_float, "[s]how [d]iagnostic window") + lsp_map("n", "dn", function() + vim.diagnostic.goto_next({ float = true }) + end, "Go to [n]ext [d]iagnostic") + lsp_map("n", "dp", function() + vim.diagnostic.goto_prev({ float = true }) + end, "Go to [p]revious [d]iagnostic") + + -- See `:help K` for why this keymap + lsp_map("n", "K", vim.lsp.buf.hover, "Hover Documentation") + lsp_map("n", "", vim.lsp.buf.signature_help, "Signature Documentation") + + -- Workspace + lsp_map("n", "wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") + lsp_map("n", "wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") + lsp_map("n", "wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, "[W]orkspace [L]ist Folders") + end, +}) diff --git a/dot_config/nvim/lua/ibrahim/set.lua b/dot_config/nvim/lua/ibrahim/set.lua new file mode 100644 index 0000000..280033f --- /dev/null +++ b/dot_config/nvim/lua/ibrahim/set.lua @@ -0,0 +1,64 @@ +local opt = vim.opt + +-- Begin searching as I type a search string instead of waiting for me to press Enter +opt.incsearch = true + +-- Make line numbers default +opt.number = true +opt.relativenumber = true + +-- Highlight only the line number for the current line. +-- Disable the second line here to highlight the entire line where the +-- cursor is. +opt.cursorline = true +opt.cursorlineopt = "number" + +-- Try to keep this many lines visible above and below the cursor. +-- This makes the window scroll sooner if mashing j / k. +opt.scrolloff = 8 + +-- Don't fold absolutely everything when opening a new file +opt.foldlevelstart = 1 + +-- Enable mouse mode +opt.mouse = "a" + +-- Tab settings +opt.tabstop = 4 +opt.softtabstop = 4 +opt.shiftwidth = 0 +opt.expandtab = true + +-- Automatically set the same indent level on a new line +opt.autoindent = true + +-- Increase or decrease indent based on braces or language keywords +opt.smartindent = true + +-- Enable break indent +opt.breakindent = true + +-- Don't make local backup files. Instead, write undo history to disk. +-- This works especially well with the undotree plugin. +opt.swapfile = false +opt.backup = false +opt.undodir = vim.fn.expand("~/.vim/undodir") +opt.undofile = true + +-- Case insensitive searching UNLESS /C or capital in search +opt.ignorecase = true +opt.smartcase = true + +-- Decrease update time +opt.updatetime = 250 + +-- Enable signcolumn (used for diagnostics and gitsigns) +opt.signcolumn = "yes" + +-- Colored columns at 72 and 88 are for line lengths, and are based on +-- Python conventions. Docstrings in Python should terminate at 72 +-- characters, and 88 is the max line length for the Black formatter. +opt.colorcolumn = { 72, 88 } + +-- Set completeopt to have a better completion experience +opt.completeopt = "menuone,noselect" diff --git a/dot_config/nvim/lua/plugins/commenter.lua b/dot_config/nvim/lua/plugins/commenter.lua new file mode 100644 index 0000000..cdc88fe --- /dev/null +++ b/dot_config/nvim/lua/plugins/commenter.lua @@ -0,0 +1,11 @@ +return { + 'echasnovski/mini.nvim', + version = false, + config = function(_, opts) + -- I'm not sure why this is requireed. I thought Lazy.nvim didn't require the + -- config key if the only line in the function was to call setup(). + -- However, without this key, this plugin fails to load with the error + -- "mini" could not be found + require("mini.comment").setup(opts) + end, +} diff --git a/dot_config/nvim/lua/plugins/conform.lua b/dot_config/nvim/lua/plugins/conform.lua new file mode 100644 index 0000000..25512bd --- /dev/null +++ b/dot_config/nvim/lua/plugins/conform.lua @@ -0,0 +1,47 @@ +-- Use prettierd if it's available or prettier otherwise, but don't +-- try to run them both. +local prettier = { { "prettierd", "prettier" } } + +return { + "stevearc/conform.nvim", + event = { "BufReadPre", "BufNewFile" }, + cmd = { "ConformInfo", "Format" }, + opts = { + formatters = { + sqlfluff = { + -- By default, SQLFluff uses "ansi" formatting. My projects + -- right now use MySQL formatting instead. + -- Still looking for a better way to manage this. + args = { "fix", "--force", "--dialect=mysql", "-" }, + }, + }, + formatters_by_ft = { + lua = { "stylua" }, + + -- Ruff LSP handles formatting for Python code + -- -- Multiple items in one table will be run sequentially + -- python = { "ruff_format", "black" }, + + css = prettier, + html = prettier, + javascript = prettier, + json = prettier, + markdown = prettier, + typescript = prettier, + yaml = prettier, + + sql = { "sqlfluff" }, + }, + }, + config = function(_, opts) + local conform = require("conform") + require("conform").setup(opts) + + local function format() + conform.format({ async = true, lsp_fallback = true }) + end + + vim.keymap.set({ "n", "v" }, "rf", format, { desc = "Reformat" }) + vim.api.nvim_create_user_command("Format", format, {}) + end, +} diff --git a/dot_config/nvim/lua/plugins/fugitive.lua b/dot_config/nvim/lua/plugins/fugitive.lua new file mode 100644 index 0000000..13a8f18 --- /dev/null +++ b/dot_config/nvim/lua/plugins/fugitive.lua @@ -0,0 +1,6 @@ +return { + "tpope/vim-fugitive", + keys = { -- load the plugin only when using it's keybinding: + { "gs", vim.cmd.Git, desc = "Vim Fugitive" }, + }, +} diff --git a/dot_config/nvim/lua/plugins/gitsigns.lua b/dot_config/nvim/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..44cd9f7 --- /dev/null +++ b/dot_config/nvim/lua/plugins/gitsigns.lua @@ -0,0 +1,19 @@ +return { + "lewis6991/gitsigns.nvim", + config = function() + require("gitsigns").setup({ + current_line_blame = true, + current_line_blame_opts = { + virt_text = true, + delay = 1000 / 3, + }, + signs = { + add = { text = "+" }, + change = { text = "~" }, + delete = { text = "_" }, + topdelete = { text = "‾" }, + changedelete = { text = "~" }, + }, + }) + end, +} diff --git a/dot_config/nvim/lua/plugins/gruvbox.lua b/dot_config/nvim/lua/plugins/gruvbox.lua new file mode 100644 index 0000000..81389a5 --- /dev/null +++ b/dot_config/nvim/lua/plugins/gruvbox.lua @@ -0,0 +1,34 @@ +return { + "ellisonleao/gruvbox.nvim", + priority = 1000 , + init = function() + require("gruvbox").setup({ + terminal_colors = true, -- add neovim terminal colors + undercurl = true, + underline = true, + bold = true, + italic = { + strings = true, + emphasis = true, + comments = true, + operators = false, + folds = true, + }, + strikethrough = true, + invert_selection = false, + invert_signs = false, + invert_tabline = false, + invert_intend_guides = false, + inverse = true, -- invert background for search, diffs, statuslines and errors + contrast = "", -- can be "hard", "soft" or empty string + palette_overrides = {}, + overrides = {}, + dim_inactive = false, + transparent_mode = true, + }) + + vim.opt.termguicolors = true + vim.opt.background = "dark" + vim.cmd.colorscheme("gruvbox") + end, +} diff --git a/dot_config/nvim/lua/plugins/harpoon.lua b/dot_config/nvim/lua/plugins/harpoon.lua new file mode 100644 index 0000000..797abdd --- /dev/null +++ b/dot_config/nvim/lua/plugins/harpoon.lua @@ -0,0 +1,15 @@ +return { + "ThePrimeagen/harpoon", + dependencies = { + "nvim-lua/plenary.nvim", + }, + keys = { + { "a", function() require("harpoon.mark").add_file() end, desc = "Mark file with Harpoon" }, + { "", function() require("harpoon.ui").toggle_quick_menu() end, desc = "Open Harpoon menu" }, + { "j", function() require("harpoon.ui").nav_file(1) end, desc = "Open Harpoon file 1" }, + { "k", function() require("harpoon.ui").nav_file(2) end, desc = "Open Harpoon file 2" }, + { "l", function() require("harpoon.ui").nav_file(3) end, desc = "Open Harpoon file 3" }, + { ";", function() require("harpoon.ui").nav_file(4) end, desc = "Open Harpoon file 4" }, + }, + config = true +} diff --git a/dot_config/nvim/lua/plugins/lsp-lines.lua b/dot_config/nvim/lua/plugins/lsp-lines.lua new file mode 100644 index 0000000..41c6ece --- /dev/null +++ b/dot_config/nvim/lua/plugins/lsp-lines.lua @@ -0,0 +1,41 @@ +-- lsp_lines +-- +-- A neat little plugin that shows diagnostics as separate lines instead of +-- virtual text at the end of each line. This makes it easier to read. + +return { + url = "https://git.sr.ht/~whynothugo/lsp_lines.nvim", + event = { "BufReadPre", "BufNewFile" }, + cond = not vim.g.vscode, + keys = { + -- The keys table here supports anything in the opts table for + -- vim.keymap.set, but be careful not to nest it in another table + -- like you would for that function. + -- { "di", desc = "Toggle [d]iagnostic [i]nline" }, + "di", + }, + opts = { + enabled = { + virtual_lines = true, + virtual_text = false, + }, + disabled = { + virtual_lines = false, + virtual_text = { spacing = 4, prefix = "●" }, + }, + }, + config = function(_, opts) + require("lsp_lines").setup() + local is_enabled = true + vim.diagnostic.config(opts.enabled) + + vim.keymap.set("n", "di", function() + is_enabled = not is_enabled + if is_enabled then + vim.diagnostic.config(opts.enabled) + else + vim.diagnostic.config(opts.disabled) + end + end, { desc = "Toggle [d]iagnostics [i]nline" }) + end, +} diff --git a/dot_config/nvim/lua/plugins/lsp-zero.lua b/dot_config/nvim/lua/plugins/lsp-zero.lua new file mode 100644 index 0000000..d627abf --- /dev/null +++ b/dot_config/nvim/lua/plugins/lsp-zero.lua @@ -0,0 +1,183 @@ +return { + + { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v3.x', + lazy = true, + config = false, + init = function() + -- Disable automatic setup, we are doing it manually + vim.g.lsp_zero_extend_cmp = 0 + vim.g.lsp_zero_extend_lspconfig = 0 + end, + }, + + { + 'williamboman/mason.nvim', + lazy = false, + config = true, + }, + + -- Autocompletion + { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + dependencies = { + { 'L3MON4D3/LuaSnip' }, + }, + config = function() + -- Here is where you configure the autocompletion settings. + local lsp_zero = require('lsp-zero') + lsp_zero.extend_cmp() + + -- And you can configure cmp even more, if you want to. + local cmp = require('cmp') + local cmp_action = lsp_zero.cmp_action() + + cmp.setup({ + formatting = lsp_zero.cmp_format({details = true}), + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.scroll_docs(-8), + [''] = cmp.mapping.scroll_docs(8), + -- [''] = cmp.mapping.luasnip_jump_forward(), + -- [''] = cmp.mapping.luasnip_jump_backward(), + }) + }) + end + }, + + -- LSP + { + 'neovim/nvim-lspconfig', + cmd = {'LspInfo', 'LspInstall', 'LspStart'}, + event = {'BufReadPre', 'BufNewFile'}, + dependencies = { + { 'hrsh7th/cmp-nvim-lsp' }, + { 'williamboman/mason-lspconfig.nvim' }, + { "j-hui/fidget.nvim", tag = "legacy", opts = {} }, + }, + config = function() + -- This is where all the LSP shenanigans will live + local lsp_zero = require('lsp-zero') + lsp_zero.extend_lspconfig() + + -- if you want to know more about lsp-zero and mason.nvim + -- read this: https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guides/integrate-with-mason-nvim.md + lsp_zero.on_attach(function(client, bufnr) + -- see :help lsp_zero_keybindings + -- to learn the available actions + lsp_zero.default_keymaps({buffer = bufnr}) + end) + + require('mason-lspconfig').setup({ + ensure_installed = { + 'pyright', + 'ruff_lsp', + 'tsserver', + 'lua_ls', + }, + handlers = { + lsp_zero.default_setup, + lua_ls = function() + -- (Optional) Configure lua langauge server for neovim + local lua_opts = lsp_zero.nvim_lua_ls() + require('lspconfig').lua_ls.setup(lua_opts) + end, + }, + }) + end, + }, + + -- Lint + { + "mfussenegger/nvim-lint", + cond = not vim.g.vscode, + dependencies = { + -- Additional lua configuration, makes nvim stuff amazing! + "folke/neodev.nvim", + }, + event = { + "BufReadPre", + "BufNewFile", + }, + opts = { + autocmd = { + events = { "BufEnter", "BufWritePost" }, + pattern = { "*.py", "*.lua", "*.js", "*.ts", }, + linters_by_ft = { + python = { "mypy" }, + }, + }, + on_demand = { + linters_by_ft = { + python = { "mypy", "pylint" }, + }, + }, + }, + config = function(_, opts) + local lint = require("lint") + lint.linters_by_ft = { + javascript = { "eslint_d" }, + typescript = { "eslint_d" }, + } + + local function lint_autocmd() + local filetype = vim.bo.filetype + local linter_names = opts.autocmd.linters_by_ft[filetype] or {} + require("lint").try_lint(linter_names) + end + + local function lint_on_demand() + local filetype = vim.bo.filetype + local linter_names = opts.on_demand.linters_by_ft[filetype] or {} + require("lint").try_lint(linter_names) + end + + local lint_augroup = vim.api.nvim_create_augroup("user-nvim-lint", { clear = true }) + vim.api.nvim_create_autocmd(opts.autocmd.events, { + group = lint_augroup, + pattern = opts.autocmd.pattern, + callback = lint_autocmd, + }) + + vim.keymap.set("n", "cl", lint_on_demand, { desc = "[C]ode [l]int" }) + + -- Hate to remove this because I was pretty proud of it, but I'm removing + -- Pylint altogether. Since this is just my code, I'm leaving it here + -- as a reference if I want to mess with it again later. + -- -- I use Pylint consistently, and I have some projects that enforce + -- -- that Pylint must be passing. However, I don't always want to see + -- -- low-severity Pylint warnings like "missing docstring" for things + -- -- I'm still actively writing. They can be distracting. + -- -- + -- -- Build out a simple behavior that switches the Pylint arguments + -- -- to include or exclude Pylint's complexity (C) and conventions (R) + -- -- messages. + -- -- + -- -- I intentionally make this a global user command instead of a + -- -- buffer-specific one. + -- + -- local default_pylint_args = vim.deepcopy(lint.linters.pylint.args) + -- local simple_pylint_args = vim.deepcopy(lint.linters.pylint.args) + -- table.insert(simple_pylint_args, "--disable=C,R") + -- + -- local disable_pylint_low_severity = false + -- local function toggle_pylint_severity_mode() + -- disable_pylint_low_severity = not disable_pylint_low_severity + -- if disable_pylint_low_severity then + -- lint.linters.pylint.args = simple_pylint_args + -- print("Pylint mode changed to error/warning only") + -- else + -- lint.linters.pylint.args = default_pylint_args + -- print("Pylint mode reset to default") + -- end + -- -- Run the linter again to remove leftover messages or restore + -- -- newly added ones + -- lint.try_lint() + -- end + -- + -- vim.api.nvim_create_user_command("PylintSeverityToggle", toggle_pylint_severity_mode, {}) + end, + } +} diff --git a/dot_config/nvim/lua/plugins/neotest.lua b/dot_config/nvim/lua/plugins/neotest.lua new file mode 100644 index 0000000..e2ad2ce --- /dev/null +++ b/dot_config/nvim/lua/plugins/neotest.lua @@ -0,0 +1,40 @@ +return { + "nvim-neotest/neotest", + cond = not vim.g.vscode, + ft = { "python" }, + dependencies = { + "nvim-lua/plenary.nvim", + "antoinemadec/FixCursorHold.nvim", + "nvim-treesitter/nvim-treesitter", + "nvim-neotest/neotest-python", + "nvim-neotest/nvim-nio", + }, + opts = function() + return { + adapters = { + require("neotest-python")({ + -- Use the current Python binary on the path. + -- This will usually be a virtual environment. + python = "python", + runner = "pytest", + is_test_file = function(file_path) ---@param file_path string + -- I place all of my Python test files in a + -- `tests` directory, and they all start with + -- `test_` per Pytest conventions. + local normalized_path = vim.fs.normalize(file_path) + return normalized_path:match("tests/.*%/test_.*%.py$") ~= nil + end, + }), + }, + } + end, + config = function(_, opts) + require("neotest").setup(opts) + + vim.keymap.set({ "n" }, "tr", require("neotest").run.run, { desc = "Neotest: run test at cursor" }) + vim.keymap.set({ "n" }, "tf", function() + require("neotest").run.run(vim.fn.expand("%")) + end, { desc = "Neotest: run all tests in current file" }) + vim.keymap.set({ "n", }, "ts", require("neotest").summary.toggle, { desc = "Neotest: toggle summary panel" }) + end, +} diff --git a/dot_config/nvim/lua/plugins/oil.lua b/dot_config/nvim/lua/plugins/oil.lua new file mode 100644 index 0000000..3daab43 --- /dev/null +++ b/dot_config/nvim/lua/plugins/oil.lua @@ -0,0 +1,14 @@ +return { + "stevearc/oil.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + keys = { + { "g-", function() require("oil").open() end, desc = "Open Oil fil browser" }, + }, + lazy = false, + opts = { + keymaps = { + -- Disabling because I want Telescope to use this + [""] = false + } + } +} diff --git a/dot_config/nvim/lua/plugins/telescope.lua b/dot_config/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..afe61b8 --- /dev/null +++ b/dot_config/nvim/lua/plugins/telescope.lua @@ -0,0 +1,10 @@ +return { + 'nvim-telescope/telescope.nvim', branch = '0.1.x', + dependencies = { 'nvim-lua/plenary.nvim' }, + keys = { + { "", "Telescope find_files", desc = "Telescope Find Files" }, + { "/", "Telescope live_grep", desc = "Telescope Live Grep" }, + { "tb", "Telescope buffers initial_mode=normal", desc = "Telescope Buffers" }, -- Opens initally in normal mode for ease of previewing buffers + }, +} + diff --git a/dot_config/nvim/lua/plugins/treesitter.lua b/dot_config/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..de3ad90 --- /dev/null +++ b/dot_config/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,144 @@ +return { + "nvim-treesitter/nvim-treesitter", + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + -- Playground is integrated into nvim-treesitter itself now + -- "nvim-treesitter/playground", + }, + build = ":TSUpdate", + event = { "BufReadPre", "BufNewFile" }, + opts = { + -- List of parsers to install automatically + ensure_installed = { "bash", "javascript", "java", "json", "lua", "python", "html", "typescript", "vim", "vimdoc" }, + auto_install = true, + highlight = { + enable = true, + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, + indent = { + -- Syntax-aware indentation with the = operator + enable = true, + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "vn", + node_incremental = "n", + node_decremental = "", + scope_incremental = false, + }, + }, + textobjects = { + move = { + enable = true, + + -- Add jumps to the jumplist for navigating with Ctrl+I/O + set_jumps = true, + goto_next_start = { + ["]m"] = { query = "@call.outer", desc = "Next method/function call start" }, + ["]f"] = { query = "@function.outer", desc = "Next function def start" }, + ["]c"] = { query = "@class.outer", desc = "Next class start" }, + ["]i"] = { query = "@conditional.outer", desc = "Next conditional start" }, + ["]l"] = { query = "@loop.outer", desc = "Next loop start" }, + + -- You can pass a query group to use query from `queries//.scm file in your runtime path. + -- Below example nvim-treesitter's `locals.scm` and `folds.scm`. They also provide highlights.scm and indent.scm. + ["]s"] = { query = "@scope", query_group = "locals", desc = "Next scope" }, + ["]z"] = { query = "@fold", query_group = "folds", desc = "Next fold" }, + }, + goto_next_end = { + ["]M"] = { query = "@call.outer", desc = "Next method/function call end" }, + ["]F"] = { query = "@function.outer", desc = "Next function def end" }, + ["]C"] = { query = "@class.outer", desc = "Next class end" }, + ["]I"] = { query = "@conditional.outer", desc = "Next conditional end" }, + ["]L"] = { query = "@loop.outer", desc = "Next loop end" }, + }, + goto_previous_start = { + ["[m"] = { query = "@call.outer", desc = "Previous method/function call start" }, + ["[f"] = { query = "@function.outer", desc = "Previous function def start" }, + ["[c"] = { query = "@class.outer", desc = "Previous class start" }, + ["[i"] = { query = "@conditional.outer", desc = "Previous conditional start" }, + ["[l"] = { query = "@loop.outer", desc = "Previous loop start" }, + }, + goto_previous_end = { + ["[M"] = { query = "@call.outer", desc = "Previous method/function call end" }, + ["[F"] = { query = "@function.outer", desc = "Previous function def end" }, + ["[C"] = { query = "@class.outer", desc = "Previous class end" }, + ["[I"] = { query = "@conditional.outer", desc = "Previous conditional end" }, + ["[L"] = { query = "@loop.outer", desc = "Previous loop end" }, + }, + }, + + select = { + enable = true, + + -- automatically jump forward to a text object if the + -- cursor isn't on one when triggering the plugin + lookahead = true, + + keymaps = { + -- Use = as an "assignment" text object + ["a="] = { query = "@assignment.outer", desc = "Select outer part of an assignment" }, + ["i="] = { query = "@assignment.inner", desc = "Select inner part of an assignment" }, + ["l="] = { query = "@assignment.lhs", desc = "Select left hand side of an assignment" }, + ["r="] = { query = "@assignment.rhs", desc = "Select right hand side of an assignment" }, + + -- Use "a" for "argument" + ["aa"] = { query = "@parameter.outer", desc = "Select outer part of an argument / parameter" }, + ["ia"] = { query = "@parameter.inner", desc = "Select inner part of an argument / parameter" }, + + -- Use "i" for "conditional" (saving c for class) + ["ai"] = { query = "@conditional.outer", desc = "Select outer part of a conditional" }, + ["ii"] = { query = "@conditional.inner", desc = "Select inner part of a conditional" }, + + -- Use "l" for "loop" + ["al"] = { query = "@loop.outer", desc = "Select outer part of a loop" }, + ["ij"] = { query = "@loop.inner", desc = "Select inner part of a loop" }, + + -- Use "f" for "function definition" (body of a function) + ["af"] = { query = "@function.outer", desc = "Select outer part of a function definition" }, + ["if"] = { query = "@function.inner", desc = "Select inner part of a function definition" }, + + -- Use "m" for "method call" (invocation of a function) + ["am"] = { query = "@call.outer", desc = "Select outer part of a method/function call" }, + ["im"] = { query = "@call.inner", desc = "Select inner part of a method/function call" }, + + -- Use "c" for "class" + ["ac"] = { query = "@class.outer", desc = "Select outer part of a class" }, + ["ic"] = { query = "@class.inner", desc = "Select inner part of a class" }, + }, + }, + + swap = { + enable = true, + swap_next = { + ["na"] = "@parameter.inner", -- Swap parameter with next + ["nf"] = "@function.outer", -- Swap function with next + }, + swap_previous = { + ["pa"] = "@parameter.inner", -- Swap parameter with previous + ["pf"] = "@function.outer", -- Swap function with previous + }, + }, + }, + }, + config = function(_, opts) + require("nvim-treesitter.configs").setup(opts) + vim.opt.foldmethod = "expr" + vim.opt.foldexpr = "nvim_treesitter#foldexpr()" + + -- Allow , and ; to repeat motions... + local ts_repeat_move = require("nvim-treesitter.textobjects.repeatable_move") + vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move) + vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_opposite) + -- ...but make sure they still work for the built-in f/t jumps + vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f) + vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F) + vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t) + vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T) + end, +} diff --git a/dot_config/nvim/lua/plugins/undotree.lua b/dot_config/nvim/lua/plugins/undotree.lua new file mode 100644 index 0000000..3a6d160 --- /dev/null +++ b/dot_config/nvim/lua/plugins/undotree.lua @@ -0,0 +1,8 @@ +return { + "jiaoshijie/undotree", + dependencies = "nvim-lua/plenary.nvim", + config = true, + keys = { -- load the plugin only when using it's keybinding: + { "u", "lua require('undotree').toggle()", desc = "Toggle Undotree" }, + }, +} diff --git a/dot_config/nvim/lua/plugins/which-key.lua b/dot_config/nvim/lua/plugins/which-key.lua new file mode 100644 index 0000000..0cfcf14 --- /dev/null +++ b/dot_config/nvim/lua/plugins/which-key.lua @@ -0,0 +1,41 @@ +-- which-key +-- https://github.com/folke/which-key.nvim +-- +-- Shows a popup window with key bindings when the native vim +-- timeout length has expired. +-- +-- I go back and forth on whether I like this plugin, but right now I +-- think it's nice as an occasional referenc for stuff I don't use +-- frequently. + +return { + "folke/which-key.nvim", + event = "VeryLazy", + config = function() + vim.opt.timeout = true + vim.opt.timeoutlen = 1000 + local wk = require("which-key") + wk.setup({ + window = { + border = "double", + position = "bottom", + margin = { 1, 0, 1, 0 }, + padding = { 3, 2, 3, 2 }, + winblend = 20, + }, + layout = { + height = { min = 4, max = 25 }, + width = { min = 20, max = 50 }, + spacing = 8, + align = "center", + }, + }) + wk.register({ + [""] = { + c = { name = "+code / clipboard" }, + -- d = { name = "+diagnostics" }, + s = { name = "+search" }, + }, + }) + end +} -- cgit v1.2.3