From 29efb5d53207d4a67cbcd6515c99021f05d9dfbe Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Sat, 7 Dec 2024 03:41:14 -0500 Subject: [PATCH] refactor plugins into directory --- README.md | 2 +- init.lua | 489 ++--------------------------------- lua/plugins/autocomplete.lua | 83 ++++++ lua/plugins/colorscheme.lua | 10 + lua/plugins/conform.lua | 35 +++ lua/plugins/gitsigns.lua | 14 + lua/plugins/indentguess.lua | 3 + lua/plugins/lsp.lua | 153 +++++++++++ lua/plugins/misc.lua | 28 ++ lua/plugins/neovimacs.lua | 6 + lua/plugins/tabnine.lua | 24 ++ lua/plugins/telescope.lua | 78 ++++++ lua/plugins/todo.lua | 3 + lua/plugins/treesitter.lua | 51 ++++ lua/plugins/venv.lua | 17 ++ lua/plugins/which-key.lua | 19 ++ 16 files changed, 541 insertions(+), 474 deletions(-) create mode 100644 lua/plugins/autocomplete.lua create mode 100644 lua/plugins/colorscheme.lua create mode 100644 lua/plugins/conform.lua create mode 100644 lua/plugins/gitsigns.lua create mode 100644 lua/plugins/indentguess.lua create mode 100644 lua/plugins/lsp.lua create mode 100644 lua/plugins/misc.lua create mode 100644 lua/plugins/neovimacs.lua create mode 100644 lua/plugins/tabnine.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/todo.lua create mode 100644 lua/plugins/treesitter.lua create mode 100644 lua/plugins/venv.lua create mode 100644 lua/plugins/which-key.lua diff --git a/README.md b/README.md index cf1e767f..8e067214 100644 --- a/README.md +++ b/README.md @@ -72,4 +72,4 @@ nvim commands to help you track down key bindings and resolve conflicts: Kickstart: [kickstart.nvim](https://github.com/nvim-lua/kickstart.nvim) Kickstart Video: [Get Started with Neovim](https://youtu.be/m8C0Cq9Uv9o) - +Docs: [https://neovim.io/doc/user/](Manual) diff --git a/init.lua b/init.lua index 2e026377..23b42ce0 100644 --- a/init.lua +++ b/init.lua @@ -104,489 +104,32 @@ vim.opt.rtp:prepend(lazypath) -- :Lazy require('lazy').setup({ - -- Detect tabstop and shiftwidth automatically - 'tpope/vim-sleuth', - -- Emacs-style keybindings in insert mode - { - 'millerjason/neovimacs.nvim', - opts = {}, - }, - -- { - -- dir = '/Users/jason/github/neovimacs.nvim', - -- name = 'neovimacs.nvim', - -- opts = {}, - -- }, + require 'plugins.indentguess', -- Detects tabstop and shiftwidth to match orig + require 'plugins.neovimacs', -- Emacs-style keybindings while in insert mode + require 'plugins.gitsigns', -- Add git changes to gutter + require 'plugins.which-key', -- Show keybindings as you go + require 'plugins.telescope', -- Fuzzy finder (file & LSP search) + require 'plugins.lsp', -- Language server (types, errors, signatures) + require 'plugins.conform', -- Auto-reformat files on save + require 'plugins.venv', -- Virtual environment selection + require 'plugins.autocomplete', -- Auto-completion + require 'plugins.colorscheme', -- Color scheme + require 'plugins.misc', -- Misc small plugins + require 'plugins.treesitter', -- Code highlights and reference navigation + require 'plugins.todo', -- Highlight todo, notes in comments + require 'plugins.tabnine', -- Tabnine LLM coding assistant - -- Add git changes to gutter - { - 'lewis6991/gitsigns.nvim', - opts = { - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - }, - }, - - -- Shows keybindings as you go - -- this technically requires >= 0.9.4 - unpack(nvim_ver(0, 10) and { - 'folke/which-key.nvim', - event = 'VimEnter', - config = function() - require('which-key').setup() - -- Document existing key chains - require('which-key').add { - { 'c', group = '[C]ode' }, - { 'd', group = '[D]ocument' }, - { 'r', group = '[R]ename' }, - { 's', group = '[S]earch' }, - { 'w', group = '[W]orkspace' }, - { 't', group = '[T]oggle' }, - { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, - } - end, - } or {}), - - -- Fuzzy finder (file & lsp) + -- Treesitter navigation + -- :help nvim-treesitter -- :Telescope help_tags -- See `:help telescope` and `:help telescope.setup()` -- To see keymaps do this: -- - Insert mode: -- - Normal mode: ? - { - 'nvim-telescope/telescope.nvim', - event = 'VimEnter', - branch = '0.1.x', - dependencies = { - 'nvim-lua/plenary.nvim', - { - 'nvim-telescope/telescope-fzf-native.nvim', - build = 'make', - cond = function() - return vim.fn.executable 'make' == 1 - end, - }, - { 'nvim-telescope/telescope-ui-select.nvim' }, - { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, - }, - config = function() - require('telescope').setup { - -- defaults = { - -- mappings = { - -- i = { [''] = 'to_fuzzy_refine' }, - -- }, - -- }, - -- pickers = {} - extensions = { - ['ui-select'] = { - require('telescope.themes').get_dropdown(), - }, - }, - } - - -- Enable Telescope extensions if they are installed - pcall(require('telescope').load_extension, 'fzf') - pcall(require('telescope').load_extension, 'ui-select') - - -- See `:help telescope.builtin` - local builtin = require 'telescope.builtin' - vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) - vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) - vim.keymap.set('n', 'ff', builtin.find_files, { desc = 'Find [F]iles' }) - vim.keymap.set('n', 'fg', builtin.live_grep, { desc = 'Find [G]rep' }) - vim.keymap.set('n', 'fb', builtin.buffers, { desc = 'Find [B]uffers' }) - vim.keymap.set('n', 'fh', builtin.help_tags, { desc = 'Find [H]elp tags' }) - vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) - - -- Slightly advanced example of overriding default behavior and theme - vim.keymap.set('n', '/', function() - -- You can pass additional configuration to Telescope to change the theme, layout, etc. - builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) - end, { desc = '[/] Fuzzily search in current buffer' }) - - -- Prompting - vim.keymap.set('n', 'fG', function() - builtin.grep_string { search = vim.fn.input 'grep> ' } - end) - - -- It's also possible to pass additional configuration options. - -- See `:help telescope.builtin.live_grep()` for information about particular keys - vim.keymap.set('n', 's/', function() - builtin.live_grep { - grep_open_files = true, - prompt_title = 'Live Grep in Open Files', - } - end, { desc = '[S]earch [/] in Open Files' }) - end, - }, - - -- LSP Plugins - { - 'folke/lazydev.nvim', - ft = 'lua', - opts = { - library = { - -- Load luvit types when the `vim.uv` word is found - { path = 'luvit-meta/library', words = { 'vim%.uv' } }, - }, - }, - }, - { 'Bilal2453/luvit-meta', lazy = true }, - { - -- Main LSP Configuration - 'neovim/nvim-lspconfig', - dependencies = { - -- Automatically install LSPs and related tools to stdpath for Neovim - { 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants - 'williamboman/mason-lspconfig.nvim', - 'WhoIsSethDaniel/mason-tool-installer.nvim', - - -- Useful status updates for LSP. - -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` - { 'j-hui/fidget.nvim', opts = {} }, - - -- Allows extra capabilities provided by nvim-cmp - 'hrsh7th/cmp-nvim-lsp', - }, - config = function() - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), - callback = function(event) - local map = function(keys, func, desc) - vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) - end - - map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - map('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') - map('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') - map('rn', vim.lsp.buf.rename, '[R]e[n]ame') - map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - - -- :help CursorHold - local client = vim.lsp.get_client_by_id(event.data.client_id) - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then - local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) - vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { - buffer = event.buf, - group = highlight_augroup, - callback = vim.lsp.buf.document_highlight, - }) - - vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { - buffer = event.buf, - group = highlight_augroup, - callback = vim.lsp.buf.clear_references, - }) - - vim.api.nvim_create_autocmd('LspDetach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), - callback = function(event2) - vim.lsp.buf.clear_references() - vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } - end, - }) - end - - -- Inlay hints - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then - map('th', function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) - end, '[T]oggle Inlay [H]ints') - end - end, - }) - - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) - - local servers = { - clangd = {}, - pyright = {}, - black = {}, - isort = {}, - taplo = {}, - -- rust_analyzer = {}, - lua_ls = { - -- cmd = {...}, - -- filetypes = { ...}, - -- capabilities = {}, - settings = { - Lua = { - completion = { - callSnippet = 'Replace', - }, - }, - }, - }, - } - - -- Ensure the servers and tools above are installed - -- :Mason - require('mason').setup() - - -- You can add other tools here that you want Mason to install - -- for you, so that they are available from within Neovim. - local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { - 'stylua', -- Used to format Lua code - 'ruff', -- lint and format for python - 'debugpy', -- debugger - 'taplo', -- LSP for toml files - }) - require('mason-tool-installer').setup { ensure_installed = ensure_installed } - - require('mason-lspconfig').setup { - handlers = { - function(server_name) - local server = servers[server_name] or {} - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - require('lspconfig')[server_name].setup(server) - end, - }, - } - end, - }, - - -- Auto-format - { - 'stevearc/conform.nvim', - event = { 'BufWritePre' }, - cmd = { 'ConformInfo' }, - keys = { - { - 'f', - function() - require('conform').format { async = true, lsp_fallback = true } - end, - mode = '', - desc = '[F]ormat buffer', - }, - }, - opts = { - notify_on_error = false, - format_on_save = function(bufnr) - -- Disable "format_on_save lsp_fallback" for languages that don't - -- have a well standardized coding style. You can add additional - -- languages here or re-enable it for the disabled ones. - local disable_filetypes = { c = true, cpp = true } - return { - timeout_ms = 500, - lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], - } - end, - formatters_by_ft = { - lua = { 'stylua' }, - python = { 'pyright', 'isort', 'black' }, - md = { 'prettier' }, - }, - }, - }, - -- Venv selector -- WIP: https://github.com/linux-cultist/venv-selector.nvim/tree/regexp -- Wait for a updated release - - -- Auto-completion - { - 'hrsh7th/nvim-cmp', - event = 'InsertEnter', - dependencies = { - { - 'L3MON4D3/LuaSnip', - build = (function() - if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then - return - end - return 'make install_jsregexp' - end)(), - dependencies = { - -- `friendly-snippets` contains a variety of premade snippets. - -- See the README about individual language/framework/plugin snippets: - -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, - }, - }, - 'saadparwaiz1/cmp_luasnip', - - -- Other completions - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-path', - }, - config = function() - -- See `:help cmp` - local cmp = require 'cmp' - local luasnip = require 'luasnip' - luasnip.config.setup {} - - cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - completion = { - autocomplete = false, -- Use C-Space - completeopt = 'menu,menuone,noinsert', - }, - -- `:help ins-completion` - mapping = cmp.mapping.preset.insert { - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.confirm { select = true }, - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.complete {}, - [''] = cmp.mapping(function() - if luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - end - end, { 'i', 's' }), - [''] = cmp.mapping(function() - if luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - end - end, { 'i', 's' }), - [''] = cmp.config.disable, - [''] = cmp.config.disable, - }, - sources = { - { - name = 'lazydev', - -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it - group_index = 0, - }, - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - }, - } - end, - }, - - -- Color scheme - { - 'folke/tokyonight.nvim', - priority = 1000, -- Make sure to load this before all the other start plugins. - init = function() - vim.cmd.colorscheme 'tokyonight-night' - -- vim.cmd.hi 'Comment gui=none' - end, - }, - - -- Highlight todo, notes, etc in comments - { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, - - -- Small plugings - { - 'echasnovski/mini.nvim', - config = function() - -- Better Around/Inside textobjects - -- - -- Examples: - -- - va) - [V]isually select [A]round [)]paren - -- - yinq - [Y]ank [I]nside [N]ext [Q]uote - -- - ci' - [C]hange [I]nside [']quote - require('mini.ai').setup { n_lines = 500 } - - -- Add/delete/replace surroundings (brackets, quotes, etc.) - -- - -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren - -- - sd' - [S]urround [D]elete [']quotes - -- - sr)' - [S]urround [R]eplace [)] ['] - require('mini.surround').setup() - - local statusline = require 'mini.statusline' - statusline.setup { use_icons = vim.g.have_nerd_font } - ---@diagnostic disable-next-line: duplicate-set-field - statusline.section_location = function() - return '%2l:%-2v' - end - end, - }, - - -- Treesitter navigation - -- :help nvim-treesitter - { - 'nvim-treesitter/nvim-treesitter', - build = ':TSUpdate', - opts = { - ensure_installed = { - 'bash', - 'c', - 'cmake', - 'cpp', - 'css', - 'cuda', - 'diff', - 'dockerfile', - 'dot', - 'go', - 'gomod', - 'html', - 'java', - 'javascript', - 'json', - 'json5', - 'latex', - 'llvm', - 'lua', - 'luadoc', - 'make', - 'markdown', - 'markdown_inline', - 'nix', - 'python', - 'query', - 'rst', - 'toml', - 'vim', - 'vimdoc', - 'yaml', - }, - auto_install = true, - highlight = { - enable = true, - additional_vim_regex_highlighting = { 'ruby' }, - }, - indent = { enable = true, disable = { 'ruby' } }, - }, - config = function(_, opts) - ---@diagnostic disable-next-line: missing-fields - require('nvim-treesitter.configs').setup(opts) - end, - }, - - -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', - -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', - -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the diff --git a/lua/plugins/autocomplete.lua b/lua/plugins/autocomplete.lua new file mode 100644 index 00000000..cf7a041c --- /dev/null +++ b/lua/plugins/autocomplete.lua @@ -0,0 +1,83 @@ +return { + { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + dependencies = { + { + 'L3MON4D3/LuaSnip', + build = (function() + if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then + return + end + return 'make install_jsregexp' + end)(), + dependencies = { + -- `friendly-snippets` contains a variety of premade snippets. + -- See the README about individual language/framework/plugin snippets: + -- https://github.com/rafamadriz/friendly-snippets + -- { + -- 'rafamadriz/friendly-snippets', + -- config = function() + -- require('luasnip.loaders.from_vscode').lazy_load() + -- end, + -- }, + }, + }, + 'saadparwaiz1/cmp_luasnip', + + -- Other completions + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', + }, + config = function() + -- See `:help cmp` + local cmp = require 'cmp' + local luasnip = require 'luasnip' + luasnip.config.setup {} + + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + completion = { + autocomplete = false, -- Use C-Space + completeopt = 'menu,menuone,noinsert', + }, + -- `:help ins-completion` + mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.complete {}, + [''] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { 'i', 's' }), + [''] = cmp.config.disable, + [''] = cmp.config.disable, + }, + sources = { + { + name = 'lazydev', + -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it + group_index = 0, + }, + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + }, + } + end, + }, +} diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua new file mode 100644 index 00000000..6df156ed --- /dev/null +++ b/lua/plugins/colorscheme.lua @@ -0,0 +1,10 @@ +return { + { + 'folke/tokyonight.nvim', + priority = 1000, -- Make sure to load this before all the other start plugins. + init = function() + vim.cmd.colorscheme 'tokyonight-night' + -- vim.cmd.hi 'Comment gui=none' + end, + }, +} diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua new file mode 100644 index 00000000..5f6f6aeb --- /dev/null +++ b/lua/plugins/conform.lua @@ -0,0 +1,35 @@ +return { + { + 'stevearc/conform.nvim', + event = { 'BufWritePre' }, + cmd = { 'ConformInfo' }, + keys = { + { + 'fo', + function() + require('conform').format { async = true, lsp_fallback = true } + end, + mode = '', + desc = '[Fo]rmat Buffer', + }, + }, + opts = { + notify_on_error = false, + format_on_save = function(bufnr) + local disable_filetypes = { c = true, cpp = true, sh = true } + return { + timeout_ms = 500, + lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], + } + end, + formatters_by_ft = { + lua = { 'stylua' }, + python = { 'pyright', 'isort', 'black' }, + md = { 'prettier' }, + nix = { 'nixfmt' }, + yaml = { 'yamlfmt' }, + sh = { 'shfmt' }, + }, + }, + }, +} diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 00000000..363477eb --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,14 @@ +return { + { -- Add git changes to gutter + 'lewis6991/gitsigns.nvim', + opts = { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, + }, + }, +} diff --git a/lua/plugins/indentguess.lua b/lua/plugins/indentguess.lua new file mode 100644 index 00000000..0884e6ba --- /dev/null +++ b/lua/plugins/indentguess.lua @@ -0,0 +1,3 @@ +return { + 'tpope/vim-sleuth', +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 00000000..1486d448 --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,153 @@ +return { + { + 'folke/lazydev.nvim', + ft = 'lua', + opts = { + library = { + -- Load luvit types when the `vim.uv` word is found + { path = 'luvit-meta/library', words = { 'vim%.uv' } }, + }, + }, + }, + { 'Bilal2453/luvit-meta', lazy = true }, + { + -- Main LSP Configuration + 'neovim/nvim-lspconfig', + dependencies = { + -- Automatically install LSPs and related tools to stdpath for Neovim + { 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants + 'williamboman/mason-lspconfig.nvim', + 'WhoIsSethDaniel/mason-tool-installer.nvim', + + -- Useful status updates for LSP. + -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` + { 'j-hui/fidget.nvim', opts = {} }, + + -- Allows extra capabilities provided by nvim-cmp + 'hrsh7th/cmp-nvim-lsp', + }, + config = function() + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), + callback = function(event) + local map = function(keys, func, desc) + vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) + end + + map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + map('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') + map('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + map('rn', vim.lsp.buf.rename, '[R]e[n]ame') + map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + + -- :help CursorHold + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then + local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) + vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.document_highlight, + }) + + vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.clear_references, + }) + + vim.api.nvim_create_autocmd('LspDetach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), + callback = function(event2) + vim.lsp.buf.clear_references() + vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } + end, + }) + end + + -- Inlay hints + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then + map('th', function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) + end, '[T]oggle Inlay [H]ints') + end + end, + }) + + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) + + local servers = { + clangd = {}, + pyright = {}, + black = {}, + isort = {}, + taplo = {}, + -- rust_analyzer = {}, + lua_ls = { + -- cmd = {...}, + -- filetypes = { ...}, + -- capabilities = {}, + settings = { + Lua = { + completion = { + callSnippet = 'Replace', + }, + }, + }, + }, + } + + -- Ensure the servers and tools above are installed + -- :Mason + require('mason').setup() + + -- You can add other tools here that you want Mason to install + -- for you, so that they are available from within Neovim. + local ensure_installed = vim.tbl_keys(servers or {}) + vim.list_extend(ensure_installed, { + 'bashls', -- bash + 'black', -- python format + 'cmake', -- cmake + 'clangd', -- cpp + 'debugpy', -- debugger + 'dockerls', -- docker + 'golangci-lint', -- go + 'isort', -- python sorting + 'jedi-language-server', -- jedi completion + 'jsonls', -- json + 'lua_ls', -- lua + 'marksman', -- markdown + 'mypy', -- python checking + 'nixpkgs-fmt', -- Nix + 'prettier', -- md + 'pyright', -- python lsp + 'ruff', -- lint and format for python + 'rust-analyzer', -- rust + 'shfmt', -- shell + 'stylua', -- Used to format Lua code + 'taplo', -- LSP for toml files + 'tree-sitter-cli', -- treesitter + 'ts_ls', -- typescript + 'yamllint', -- yaml + 'yamlfmt', -- yaml + 'yamlls', -- yaml + }) + require('mason-tool-installer').setup { ensure_installed = ensure_installed } + + require('mason-lspconfig').setup { + handlers = { + function(server_name) + local server = servers[server_name] or {} + server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + require('lspconfig')[server_name].setup(server) + end, + }, + } + end, + }, +} diff --git a/lua/plugins/misc.lua b/lua/plugins/misc.lua new file mode 100644 index 00000000..5da43b32 --- /dev/null +++ b/lua/plugins/misc.lua @@ -0,0 +1,28 @@ +return { + { + 'echasnovski/mini.nvim', + config = function() + -- Better Around/Inside textobjects + -- + -- Examples: + -- - va) - [V]isually select [A]round [)]paren + -- - yinq - [Y]ank [I]nside [N]ext [Q]uote + -- - ci' - [C]hange [I]nside [']quote + require('mini.ai').setup { n_lines = 500 } + + -- Add/delete/replace surroundings (brackets, quotes, etc.) + -- + -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren + -- - sd' - [S]urround [D]elete [']quotes + -- - sr)' - [S]urround [R]eplace [)] ['] + require('mini.surround').setup() + + local statusline = require 'mini.statusline' + statusline.setup { use_icons = vim.g.have_nerd_font } + ---@diagnostic disable-next-line: duplicate-set-field + statusline.section_location = function() + return '%2l:%-2v' + end + end, + }, +} diff --git a/lua/plugins/neovimacs.lua b/lua/plugins/neovimacs.lua new file mode 100644 index 00000000..15c74e3f --- /dev/null +++ b/lua/plugins/neovimacs.lua @@ -0,0 +1,6 @@ +return { + { -- Emacs-style keybindings in insert mode + 'millerjason/neovimacs.nvim', + opts = {}, + }, +} diff --git a/lua/plugins/tabnine.lua b/lua/plugins/tabnine.lua new file mode 100644 index 00000000..1d255a37 --- /dev/null +++ b/lua/plugins/tabnine.lua @@ -0,0 +1,24 @@ +return { + 'codota/tabnine-nvim', + name = 'tabnine', + build = './dl_binaries.sh', + config = function() + require('tabnine').setup { + disable_auto_comment = true, + accept_keymap = '', + dismiss_keymap = '', + debounce_ms = 800, + suggestion_color = { gui = '#808080', cterm = 244 }, + exclude_filetypes = { 'TelescopePrompt', 'NvimTree' }, + log_file_path = nil, + ignore_certificate_errors = false, + } + require('tabnine.status').disable_tabnine() + end, + lazy = false, + keys = { + { 'lc', 'TabnineChat', desc = '[L]LM [C]hat' }, + { 'lt', 'TabnineToggle', desc = '[L]LM [T]oggle' }, + { 'ls', 'TabnineStatus', desc = '[L]LM [S]tatus' }, + }, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 00000000..f7aac271 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,78 @@ +return { + { + 'nvim-telescope/telescope.nvim', + event = 'VimEnter', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim', + { + 'nvim-telescope/telescope-fzf-native.nvim', + build = 'make', + cond = function() + return vim.fn.executable 'make' == 1 + end, + }, + { 'nvim-telescope/telescope-ui-select.nvim' }, + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, + }, + config = function() + require('telescope').setup { + -- defaults = { + -- mappings = { + -- i = { [''] = 'to_fuzzy_refine' }, + -- }, + -- }, + -- pickers = {} + extensions = { + ['ui-select'] = { + require('telescope.themes').get_dropdown(), + }, + }, + } + + -- Enable Telescope extensions if they are installed + pcall(require('telescope').load_extension, 'fzf') + pcall(require('telescope').load_extension, 'ui-select') + + -- See `:help telescope.builtin` + local builtin = require 'telescope.builtin' + vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) + vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) + vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) + vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) + vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) + vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) + vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) + vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set('n', 'ff', builtin.find_files, { desc = 'Find [F]iles' }) + vim.keymap.set('n', 'fg', builtin.live_grep, { desc = 'Find [G]rep' }) + vim.keymap.set('n', 'fb', builtin.buffers, { desc = 'Find [B]uffers' }) + vim.keymap.set('n', 'fh', builtin.help_tags, { desc = 'Find [H]elp tags' }) + vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + + -- Slightly advanced example of overriding default behavior and theme + vim.keymap.set('n', '/', function() + -- You can pass additional configuration to Telescope to change the theme, layout, etc. + builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) + end, { desc = '[/] Fuzzily search in current buffer' }) + + -- Prompting + vim.keymap.set('n', 'fG', function() + builtin.grep_string { search = vim.fn.input 'grep> ' } + end) + + -- It's also possible to pass additional configuration options. + -- See `:help telescope.builtin.live_grep()` for information about particular keys + vim.keymap.set('n', 's/', function() + builtin.live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end, { desc = '[S]earch [/] in Open Files' }) + end, + }, +} diff --git a/lua/plugins/todo.lua b/lua/plugins/todo.lua new file mode 100644 index 00000000..fd4b5ce8 --- /dev/null +++ b/lua/plugins/todo.lua @@ -0,0 +1,3 @@ +return { + { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 00000000..9b1c8ded --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,51 @@ +return { + { + 'nvim-treesitter/nvim-treesitter', + build = ':TSUpdate', + opts = { + ensure_installed = { + 'bash', + 'c', + 'cmake', + 'cpp', + 'css', + 'cuda', + 'diff', + 'dockerfile', + 'dot', + 'go', + 'gomod', + 'html', + 'java', + 'javascript', + 'json', + 'json5', + 'latex', + 'llvm', + 'lua', + 'luadoc', + 'make', + 'markdown', + 'markdown_inline', + 'nix', + 'python', + 'query', + 'rst', + 'toml', + 'vim', + 'vimdoc', + 'yaml', + }, + auto_install = true, + highlight = { + enable = true, + additional_vim_regex_highlighting = { 'ruby' }, + }, + indent = { enable = true, disable = { 'ruby' } }, + }, + config = function(_, opts) + ---@diagnostic disable-next-line: missing-fields + require('nvim-treesitter.configs').setup(opts) + end, + }, +} diff --git a/lua/plugins/venv.lua b/lua/plugins/venv.lua new file mode 100644 index 00000000..addb1a88 --- /dev/null +++ b/lua/plugins/venv.lua @@ -0,0 +1,17 @@ +return { + 'linux-cultist/venv-selector.nvim', + branch = 'regexp', + dependencies = { + 'neovim/nvim-lspconfig', + 'mfussenegger/nvim-dap', + 'mfussenegger/nvim-dap-python', + 'nvim-telescope/telescope.nvim', + }, + lazy = false, + config = function() + require('venv-selector').setup() + end, + keys = { + { ',v', 'VenvSelect' }, + }, +} diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua new file mode 100644 index 00000000..5e83e6dd --- /dev/null +++ b/lua/plugins/which-key.lua @@ -0,0 +1,19 @@ +return { + { -- Shows keybindings as you go + 'folke/which-key.nvim', + event = 'VimEnter', + config = function() + require('which-key').setup() + -- Document existing key chains + require('which-key').add { + { 'c', group = '[C]ode' }, + { 'd', group = '[D]ocument' }, + { 'r', group = '[R]ename' }, + { 's', group = '[S]earch' }, + { 'w', group = '[W]orkspace' }, + { 't', group = '[T]oggle' }, + { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + } + end, + }, +}