diff --git a/init.lua b/init.lua index 8d1f19a10d4..74a1a4ca5a4 100644 --- a/init.lua +++ b/init.lua @@ -1,990 +1,16 @@ --[[ + Path: init.lua (Neovim config root) + Module: none — Neovim executes this file before any Lua `require`. -===================================================================== -==================== READ THIS BEFORE CONTINUING ==================== -===================================================================== -======== .-----. ======== -======== .----------------------. | === | ======== -======== |.-""""""""""""""""""-.| |-----| ======== -======== || || | === | ======== -======== || KICKSTART.NVIM || |-----| ======== -======== || || | === | ======== -======== || || |-----| ======== -======== ||:Tutor || |:::::| ======== -======== |'-..................-'| |____o| ======== -======== `"")----------------(""` ___________ ======== -======== /::::::::::| |::::::::::\ \ no mouse \ ======== -======== /:::========| |==hjkl==:::\ \ required \ ======== -======== '""""""""""""' '""""""""""""' '""""""""""' ======== -======== ======== -===================================================================== -===================================================================== + Purpose + Single entrypoint for your configuration. Everything else lives under + `lua/` so this file stays small and easy to skim. -What is Kickstart? + Rationale + A minimal root `init.lua` avoids duplicating logic that belongs in modular + Lua modules and matches common Neovim + lazy.nvim layouts. - Kickstart.nvim is *not* a distribution. + See `:help config` and `:help lua-require`. +]] - Kickstart.nvim is a starting point for your own configuration. - The goal is that you can read every line of code, top-to-bottom, understand - what your configuration is doing, and modify it to suit your needs. - - Once you've done that, you can start exploring, configuring and tinkering to - make Neovim your own! That might mean leaving Kickstart just the way it is for a while - or immediately breaking it into modular pieces. It's up to you! - - If you don't know anything about Lua, I recommend taking some time to read through - a guide. One possible example which will only take 10-15 minutes: - - https://learnxinyminutes.com/docs/lua/ - - After understanding a bit more about Lua, you can use `:help lua-guide` as a - reference for how Neovim integrates Lua. - - :help lua-guide - - (or HTML version): https://neovim.io/doc/user/lua-guide.html - -Kickstart Guide: - - TODO: The very first thing you should do is to run the command `:Tutor` in Neovim. - - If you don't know what this means, type the following: - - - - : - - Tutor - - - - (If you already know the Neovim basics, you can skip this step.) - - Once you've completed that, you can continue working through **AND READING** the rest - of the kickstart init.lua. - - Next, run AND READ `:help`. - This will open up a help window with some basic information - about reading, navigating and searching the builtin help documentation. - - This should be the first place you go to look when you're stuck or confused - with something. It's one of my favorite Neovim features. - - MOST IMPORTANTLY, we provide a keymap "sh" to [s]earch the [h]elp documentation, - which is very useful when you're not exactly sure of what you're looking for. - - I have left several `:help X` comments throughout the init.lua - These are hints about where to find more information about the relevant settings, - plugins or Neovim features used in Kickstart. - - NOTE: Look for lines like this - - Throughout the file. These are for you, the reader, to help you understand what is happening. - Feel free to delete them once you know what you're doing, but they should serve as a guide - for when you are first encountering a few different constructs in your Neovim config. - -If you experience any errors while trying to install kickstart, run `:checkhealth` for more info. - -I hope you enjoy your Neovim journey, -- TJ - -P.S. You can delete this when you're done too. It's your config now! :) ---]] - --- Set as the leader key --- See `:help mapleader` --- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' - --- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false - --- [[ Setting options ]] --- See `:help vim.o` --- NOTE: You can change these options as you wish! --- For more options, you can see `:help option-list` - --- Make line numbers default -vim.o.number = true --- You can also add relative line numbers, to help with jumping. --- Experiment for yourself to see if you like it! --- vim.o.relativenumber = true - --- Enable mouse mode, can be useful for resizing splits for example! -vim.o.mouse = 'a' - --- Don't show the mode, since it's already in the status line -vim.o.showmode = false - --- Sync clipboard between OS and Neovim. --- Schedule the setting after `UiEnter` because it can increase startup-time. --- Remove this option if you want your OS clipboard to remain independent. --- See `:help 'clipboard'` -vim.schedule(function() vim.o.clipboard = 'unnamedplus' end) - --- Enable break indent -vim.o.breakindent = true - --- Enable undo/redo changes even after closing and reopening a file -vim.o.undofile = true - --- Case-insensitive searching UNLESS \C or one or more capital letters in the search term -vim.o.ignorecase = true -vim.o.smartcase = true - --- Keep signcolumn on by default -vim.o.signcolumn = 'yes' - --- Decrease update time -vim.o.updatetime = 250 - --- Decrease mapped sequence wait time -vim.o.timeoutlen = 300 - --- Configure how new splits should be opened -vim.o.splitright = true -vim.o.splitbelow = true - --- Sets how neovim will display certain whitespace characters in the editor. --- See `:help 'list'` --- and `:help 'listchars'` --- --- Notice listchars is set using `vim.opt` instead of `vim.o`. --- It is very similar to `vim.o` but offers an interface for conveniently interacting with tables. --- See `:help lua-options` --- and `:help lua-guide-options` -vim.o.list = true -vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } - --- Preview substitutions live, as you type! -vim.o.inccommand = 'split' - --- Show which line your cursor is on -vim.o.cursorline = true - --- Minimal number of screen lines to keep above and below the cursor. -vim.o.scrolloff = 10 - --- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`), --- instead raise a dialog asking if you wish to save the current file(s) --- See `:help 'confirm'` -vim.o.confirm = true - --- [[ Basic Keymaps ]] --- See `:help vim.keymap.set()` - --- Clear highlights on search when pressing in normal mode --- See `:help hlsearch` -vim.keymap.set('n', '', 'nohlsearch') - --- Diagnostic Config & Keymaps --- See :help vim.diagnostic.Opts -vim.diagnostic.config { - update_in_insert = false, - severity_sort = true, - float = { border = 'rounded', source = 'if_many' }, - underline = { severity = { min = vim.diagnostic.severity.WARN } }, - - -- Can switch between these as you prefer - virtual_text = true, -- Text shows up at the end of the line - virtual_lines = false, -- Text shows up underneath the line, with virtual lines - - -- Auto open the float, so you can easily read the errors when jumping with `[d` and `]d` - jump = { float = true }, -} - -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) - --- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier --- for people to discover. Otherwise, you normally need to press , which --- is not what someone will guess without a bit more experience. --- --- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping --- or just use to exit terminal mode -vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) - --- TIP: Disable arrow keys in normal mode --- vim.keymap.set('n', '', 'echo "Use h to move!!"') --- vim.keymap.set('n', '', 'echo "Use l to move!!"') --- vim.keymap.set('n', '', 'echo "Use k to move!!"') --- vim.keymap.set('n', '', 'echo "Use j to move!!"') - --- Keybinds to make split navigation easier. --- Use CTRL+ to switch between windows --- --- See `:help wincmd` for a list of all window commands -vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) - --- NOTE: Some terminals have colliding keymaps or are not able to send distinct keycodes --- vim.keymap.set("n", "", "H", { desc = "Move window to the left" }) --- vim.keymap.set("n", "", "L", { desc = "Move window to the right" }) --- vim.keymap.set("n", "", "J", { desc = "Move window to the lower" }) --- vim.keymap.set("n", "", "K", { desc = "Move window to the upper" }) - --- [[ Basic Autocommands ]] --- See `:help lua-guide-autocommands` - --- Highlight when yanking (copying) text --- Try it with `yap` in normal mode --- See `:help vim.hl.on_yank()` -vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Highlight when yanking (copying) text', - group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), - callback = function() vim.hl.on_yank() end, -}) - --- [[ Install `lazy.nvim` plugin manager ]] --- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info -local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' -if not (vim.uv or vim.loop).fs_stat(lazypath) then - local lazyrepo = 'https://github.com/folke/lazy.nvim.git' - local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } - if vim.v.shell_error ~= 0 then error('Error cloning lazy.nvim:\n' .. out) end -end - ----@type vim.Option -local rtp = vim.opt.rtp -rtp:prepend(lazypath) - --- [[ Configure and install plugins ]] --- --- To check the current status of your plugins, run --- :Lazy --- --- You can press `?` in this menu for help. Use `:q` to close the window --- --- To update plugins you can run --- :Lazy update --- --- NOTE: Here is where you install your plugins. -require('lazy').setup({ - -- NOTE: Plugins can be added via a link or github org/name. To run setup automatically, use `opts = {}` - { 'NMAC427/guess-indent.nvim', opts = {} }, - - -- Alternatively, use `config = function() ... end` for full control over the configuration. - -- If you prefer to call `setup` explicitly, use: - -- { - -- 'lewis6991/gitsigns.nvim', - -- config = function() - -- require('gitsigns').setup({ - -- -- Your gitsigns configuration here - -- }) - -- end, - -- } - -- - -- Here is a more advanced example where we pass configuration - -- options to `gitsigns.nvim`. - -- - -- See `:help gitsigns` to understand what the configuration keys do - { -- Adds git related signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - ---@module 'gitsigns' - ---@type Gitsigns.Config - ---@diagnostic disable-next-line: missing-fields - opts = { - signs = { - add = { text = '+' }, ---@diagnostic disable-line: missing-fields - change = { text = '~' }, ---@diagnostic disable-line: missing-fields - delete = { text = '_' }, ---@diagnostic disable-line: missing-fields - topdelete = { text = '‾' }, ---@diagnostic disable-line: missing-fields - changedelete = { text = '~' }, ---@diagnostic disable-line: missing-fields - }, - }, - }, - - -- NOTE: Plugins can also be configured to run Lua code when they are loaded. - -- - -- This is often very useful to both group configuration, as well as handle - -- lazy loading plugins that don't need to be loaded immediately at startup. - -- - -- For example, in the following configuration, we use: - -- event = 'VimEnter' - -- - -- which loads which-key before all the UI elements are loaded. Events can be - -- normal autocommands events (`:help autocmd-events`). - -- - -- Then, because we use the `opts` key (recommended), the configuration runs - -- after the plugin has been loaded as `require(MODULE).setup(opts)`. - - { -- Useful plugin to show you pending keybinds. - 'folke/which-key.nvim', - event = 'VimEnter', - ---@module 'which-key' - ---@type wk.Opts - ---@diagnostic disable-next-line: missing-fields - opts = { - -- delay between pressing a key and opening which-key (milliseconds) - delay = 0, - icons = { mappings = vim.g.have_nerd_font }, - - -- Document existing key chains - spec = { - { 's', group = '[S]earch', mode = { 'n', 'v' } }, - { 't', group = '[T]oggle' }, - { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, -- Enable gitsigns recommended keymaps first - { 'gr', group = 'LSP Actions', mode = { 'n' } }, - }, - }, - }, - - -- NOTE: Plugins can specify dependencies. - -- - -- The dependencies are proper plugin specifications as well - anything - -- you do for a plugin at the top level, you can do for a dependency. - -- - -- Use the `dependencies` key to specify the dependencies of a particular plugin - - { -- Fuzzy Finder (files, lsp, etc) - 'nvim-telescope/telescope.nvim', - -- By default, Telescope is included and acts as your picker for everything. - - -- If you would like to switch to a different picker (like snacks, or fzf-lua) - -- you can disable the Telescope plugin by setting enabled to false and enable - -- your replacement picker by requiring it explicitly (e.g. 'custom.plugins.snacks') - - -- Note: If you customize your config for yourself, - -- it’s best to remove the Telescope plugin config entirely - -- instead of just disabling it here, to keep your config clean. - enabled = true, - event = 'VimEnter', - dependencies = { - 'nvim-lua/plenary.nvim', - { -- If encountering errors, see telescope-fzf-native README for installation instructions - 'nvim-telescope/telescope-fzf-native.nvim', - - -- `build` is used to run some command when the plugin is installed/updated. - -- This is only run then, not every time Neovim starts up. - build = 'make', - - -- `cond` is a condition used to determine whether this plugin should be - -- installed and loaded. - cond = function() return vim.fn.executable 'make' == 1 end, - }, - { 'nvim-telescope/telescope-ui-select.nvim' }, - - -- Useful for getting pretty icons, but requires a Nerd Font. - { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, - }, - config = function() - -- Telescope is a fuzzy finder that comes with a lot of different things that - -- it can fuzzy find! It's more than just a "file finder", it can search - -- many different aspects of Neovim, your workspace, LSP, and more! - -- - -- The easiest way to use Telescope, is to start by doing something like: - -- :Telescope help_tags - -- - -- After running this command, a window will open up and you're able to - -- type in the prompt window. You'll see a list of `help_tags` options and - -- a corresponding preview of the help. - -- - -- Two important keymaps to use while in Telescope are: - -- - Insert mode: - -- - Normal mode: ? - -- - -- This opens a window that shows you all of the keymaps for the current - -- Telescope picker. This is really useful to discover what Telescope can - -- do as well as how to actually do it! - - -- [[ Configure Telescope ]] - -- See `:help telescope` and `:help telescope.setup()` - require('telescope').setup { - -- You can put your default mappings / updates / etc. in here - -- All the info you're looking for is in `:help 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', 'v' }, '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', 'sc', builtin.commands, { desc = '[S]earch [C]ommands' }) - vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) - - -- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info, - -- it is better explained there). This allows easily switching between pickers if you prefer using something else! - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('telescope-lsp-attach', { clear = true }), - callback = function(event) - local buf = event.buf - - -- Find references for the word under your cursor. - vim.keymap.set('n', 'grr', builtin.lsp_references, { buffer = buf, desc = '[G]oto [R]eferences' }) - - -- Jump to the implementation of the word under your cursor. - -- Useful when your language has ways of declaring types without an actual implementation. - vim.keymap.set('n', 'gri', builtin.lsp_implementations, { buffer = buf, desc = '[G]oto [I]mplementation' }) - - -- Jump to the definition of the word under your cursor. - -- This is where a variable was first declared, or where a function is defined, etc. - -- To jump back, press . - vim.keymap.set('n', 'grd', builtin.lsp_definitions, { buffer = buf, desc = '[G]oto [D]efinition' }) - - -- Fuzzy find all the symbols in your current document. - -- Symbols are things like variables, functions, types, etc. - vim.keymap.set('n', 'gO', builtin.lsp_document_symbols, { buffer = buf, desc = 'Open Document Symbols' }) - - -- Fuzzy find all the symbols in your current workspace. - -- Similar to document symbols, except searches over your entire project. - vim.keymap.set('n', 'gW', builtin.lsp_dynamic_workspace_symbols, { buffer = buf, desc = 'Open Workspace Symbols' }) - - -- Jump to the type of the word under your cursor. - -- Useful when you're not sure what type a variable is and you want to see - -- the definition of its *type*, not where it was *defined*. - vim.keymap.set('n', 'grt', builtin.lsp_type_definitions, { buffer = buf, desc = '[G]oto [T]ype Definition' }) - end, - }) - - -- Override default behavior and theme when searching - 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' }) - - -- 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' } - ) - - -- Shortcut for searching your Neovim configuration files - vim.keymap.set('n', 'sn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = '[S]earch [N]eovim files' }) - end, - }, - - -- LSP Plugins - { - -- Main LSP Configuration - 'neovim/nvim-lspconfig', - dependencies = { - -- Automatically install LSPs and related tools to stdpath for Neovim - -- Mason must be loaded before its dependents so we need to set it up here. - -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})` - { - 'mason-org/mason.nvim', - ---@module 'mason.settings' - ---@type MasonSettings - ---@diagnostic disable-next-line: missing-fields - opts = {}, - }, - -- Maps LSP server names between nvim-lspconfig and Mason package names. - 'mason-org/mason-lspconfig.nvim', - 'WhoIsSethDaniel/mason-tool-installer.nvim', - - -- Useful status updates for LSP. - { 'j-hui/fidget.nvim', opts = {} }, - }, - config = function() - -- Brief aside: **What is LSP?** - -- - -- LSP is an initialism you've probably heard, but might not understand what it is. - -- - -- LSP stands for Language Server Protocol. It's a protocol that helps editors - -- and language tooling communicate in a standardized fashion. - -- - -- In general, you have a "server" which is some tool built to understand a particular - -- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc.). These Language Servers - -- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone - -- processes that communicate with some "client" - in this case, Neovim! - -- - -- LSP provides Neovim with features like: - -- - Go to definition - -- - Find references - -- - Autocompletion - -- - Symbol Search - -- - and more! - -- - -- Thus, Language Servers are external tools that must be installed separately from - -- Neovim. This is where `mason` and related plugins come into play. - -- - -- If you're wondering about lsp vs treesitter, you can check out the wonderfully - -- and elegantly composed help section, `:help lsp-vs-treesitter` - - -- This function gets run when an LSP attaches to a particular buffer. - -- That is to say, every time a new file is opened that is associated with - -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this - -- function will be executed to configure the current buffer - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), - callback = function(event) - -- NOTE: Remember that Lua is a real programming language, and as such it is possible - -- to define small helper and utility functions so you don't have to repeat yourself. - -- - -- In this case, we create a function that lets us more easily define mappings specific - -- for LSP related items. It sets the mode, buffer and description for us each time. - local map = function(keys, func, desc, mode) - mode = mode or 'n' - vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) - end - - -- Rename the variable under your cursor. - -- Most Language Servers support renaming across files, etc. - map('grn', vim.lsp.buf.rename, '[R]e[n]ame') - - -- Execute a code action, usually your cursor needs to be on top of an error - -- or a suggestion from your LSP for this to activate. - map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) - - -- WARN: This is not Goto Definition, this is Goto Declaration. - -- For example, in C this would take you to the header. - map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - - -- The following two autocommands are used to highlight references of the - -- word under your cursor when your cursor rests there for a little while. - -- See `:help CursorHold` for information about when this is executed - -- - -- When you move your cursor, the highlights will be cleared (the second autocommand). - local client = vim.lsp.get_client_by_id(event.data.client_id) - if client and client:supports_method('textDocument/documentHighlight', event.buf) 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 - - -- The following code creates a keymap to toggle inlay hints in your - -- code, if the language server you are using supports them - -- - -- This may be unwanted, since they displace some of your code - if client and client:supports_method('textDocument/inlayHint', event.buf) 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, - }) - - -- Enable the following language servers - -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. - -- See `:help lsp-config` for information about keys and how to configure - ---@type table - local servers = { - -- clangd = {}, - -- gopls = {}, - -- pyright = {}, - -- rust_analyzer = {}, - -- - -- Some languages (like typescript) have entire language plugins that can be useful: - -- https://github.com/pmizio/typescript-tools.nvim - -- - -- But for many setups, the LSP (`ts_ls`) will work just fine - -- ts_ls = {}, - - stylua = {}, -- Used to format Lua code - - -- Special Lua Config, as recommended by neovim help docs - lua_ls = { - on_init = function(client) - client.server_capabilities.documentFormattingProvider = false -- Disable formatting (formatting is done by stylua) - - if client.workspace_folders then - local path = client.workspace_folders[1].name - if path ~= vim.fn.stdpath 'config' and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc')) then return end - end - - client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { - runtime = { - version = 'LuaJIT', - path = { 'lua/?.lua', 'lua/?/init.lua' }, - }, - workspace = { - checkThirdParty = false, - -- NOTE: this is a lot slower and will cause issues when working on your own configuration. - -- See https://github.com/neovim/nvim-lspconfig/issues/3189 - library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), { - '${3rd}/luv/library', - '${3rd}/busted/library', - }), - }, - }) - end, - ---@type lspconfig.settings.lua_ls - settings = { - Lua = { - format = { enable = false }, -- Disable formatting (formatting is done by stylua) - }, - }, - }, - } - - -- Ensure the servers and tools above are installed - -- - -- To check the current status of installed tools and/or manually install - -- other tools, you can run - -- :Mason - -- - -- You can press `g?` for help in this menu. - local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { - -- You can add other tools here that you want Mason to install - }) - - require('mason-tool-installer').setup { ensure_installed = ensure_installed } - - for name, server in pairs(servers) do - vim.lsp.config(name, server) - vim.lsp.enable(name) - end - end, - }, - - { -- Autoformat - 'stevearc/conform.nvim', - event = { 'BufWritePre' }, - cmd = { 'ConformInfo' }, - keys = { - { - 'f', - function() require('conform').format { async = true } end, - mode = '', - desc = '[F]ormat buffer', - }, - }, - ---@module 'conform' - ---@type conform.setupOpts - opts = { - notify_on_error = false, - format_on_save = function(bufnr) - -- You can specify filetypes to autoformat on save here: - local enabled_filetypes = { - -- lua = true, - -- python = true, - } - if enabled_filetypes[vim.bo[bufnr].filetype] then - return { timeout_ms = 500 } - else - return nil - end - end, - default_format_opts = { - lsp_format = 'fallback', -- Use external formatters if configured below, otherwise use LSP formatting. Set to `false` to disable LSP formatting entirely. - }, - -- You can also specify external formatters in here. - formatters_by_ft = { - -- rust = { 'rustfmt' }, - -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, - -- - -- You can use 'stop_after_first' to run the first available formatter from the list - -- javascript = { "prettierd", "prettier", stop_after_first = true }, - }, - }, - }, - - { -- Autocompletion - 'saghen/blink.cmp', - event = 'VimEnter', - version = '1.*', - dependencies = { - -- Snippet Engine - { - 'L3MON4D3/LuaSnip', - version = '2.*', - build = (function() - -- Build Step is needed for regex support in snippets. - -- This step is not supported in many windows environments. - -- Remove the below condition to re-enable on windows. - if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then return end - return 'make install_jsregexp' - end)(), - dependencies = { - -- `friendly-snippets` contains a variety of premade snippets. - -- See the README about individual language/framework/plugin snippets: - -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, - }, - opts = {}, - }, - }, - ---@module 'blink.cmp' - ---@type blink.cmp.Config - opts = { - keymap = { - -- 'default' (recommended) for mappings similar to built-in completions - -- to accept ([y]es) the completion. - -- This will auto-import if your LSP supports it. - -- This will expand snippets if the LSP sent a snippet. - -- 'super-tab' for tab to accept - -- 'enter' for enter to accept - -- 'none' for no mappings - -- - -- For an understanding of why the 'default' preset is recommended, - -- you will need to read `:help ins-completion` - -- - -- No, but seriously. Please read `:help ins-completion`, it is really good! - -- - -- All presets have the following mappings: - -- /: move to right/left of your snippet expansion - -- : Open menu or open docs if already open - -- / or /: Select next/previous item - -- : Hide menu - -- : Toggle signature help - -- - -- See :h blink-cmp-config-keymap for defining your own keymap - preset = 'default', - - -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: - -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps - }, - - appearance = { - -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' - -- Adjusts spacing to ensure icons are aligned - nerd_font_variant = 'mono', - }, - - completion = { - -- By default, you may press `` to show the documentation. - -- Optionally, set `auto_show = true` to show the documentation after a delay. - documentation = { auto_show = false, auto_show_delay_ms = 500 }, - }, - - sources = { - default = { 'lsp', 'path', 'snippets' }, - }, - - snippets = { preset = 'luasnip' }, - - -- Blink.cmp includes an optional, recommended rust fuzzy matcher, - -- which automatically downloads a prebuilt binary when enabled. - -- - -- By default, we use the Lua implementation instead, but you may enable - -- the rust implementation via `'prefer_rust_with_warning'` - -- - -- See :h blink-cmp-config-fuzzy for more information - fuzzy = { implementation = 'lua' }, - - -- Shows a signature help window while you type arguments for a function - signature = { enabled = true }, - }, - }, - - { -- You can easily change to a different colorscheme. - -- Change the name of the colorscheme plugin below, and then - -- change the command in the config to whatever the name of that colorscheme is. - -- - -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. - 'folke/tokyonight.nvim', - priority = 1000, -- Make sure to load this before all the other start plugins. - config = function() - ---@diagnostic disable-next-line: missing-fields - require('tokyonight').setup { - styles = { - comments = { italic = false }, -- Disable italics in comments - }, - } - - -- Load the colorscheme here. - -- Like many other themes, this one has different styles, and you could load - -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. - vim.cmd.colorscheme 'tokyonight-night' - end, - }, - - -- Highlight todo, notes, etc in comments - { - 'folke/todo-comments.nvim', - event = 'VimEnter', - dependencies = { 'nvim-lua/plenary.nvim' }, - ---@module 'todo-comments' - ---@type TodoOptions - ---@diagnostic disable-next-line: missing-fields - opts = { signs = false }, - }, - - { -- Collection of various small independent plugins/modules - 'nvim-mini/mini.nvim', - config = function() - -- Better Around/Inside textobjects - -- - -- Examples: - -- - va) - [V]isually select [A]round [)]paren - -- - yiiq - [Y]ank [I]nside [I]+1 [Q]uote - -- - ci' - [C]hange [I]nside [']quote - require('mini.ai').setup { - -- NOTE: Avoid conflicts with the built-in incremental selection mappings on Neovim>=0.12 (see `:help treesitter-incremental-selection`) - mappings = { - around_next = 'aa', - inside_next = 'ii', - }, - 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() - - -- Simple and easy statusline. - -- You could remove this setup call if you don't like it, - -- and try some other statusline plugin - local statusline = require 'mini.statusline' - -- set use_icons to true if you have a Nerd Font - statusline.setup { use_icons = vim.g.have_nerd_font } - - -- You can configure sections in the statusline by overriding their - -- default behavior. For example, here we set the section for - -- cursor location to LINE:COLUMN - ---@diagnostic disable-next-line: duplicate-set-field - statusline.section_location = function() return '%2l:%-2v' end - - -- ... and there is more! - -- Check out: https://github.com/nvim-mini/mini.nvim - end, - }, - - { -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - lazy = false, - build = ':TSUpdate', - branch = 'main', - -- [[ Configure Treesitter ]] See `:help nvim-treesitter-intro` - config = function() - -- ensure basic parser are installed - local parsers = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' } - require('nvim-treesitter').install(parsers) - - ---@param buf integer - ---@param language string - local function treesitter_try_attach(buf, language) - -- check if parser exists and load it - if not vim.treesitter.language.add(language) then return end - -- enables syntax highlighting and other treesitter features - vim.treesitter.start(buf, language) - - -- enables treesitter based folds - -- for more info on folds see `:help folds` - -- vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' - -- vim.wo.foldmethod = 'expr' - - -- check if treesitter indentation is available for this language, and if so enable it - -- in case there is no indent query, the indentexpr will fallback to the vim's built in one - local has_indent_query = vim.treesitter.query.get(language, 'indents') ~= nil - - -- enables treesitter based indentation - if has_indent_query then vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" end - end - - local available_parsers = require('nvim-treesitter').get_available() - vim.api.nvim_create_autocmd('FileType', { - callback = function(args) - local buf, filetype = args.buf, args.match - - local language = vim.treesitter.language.get_lang(filetype) - if not language then return end - - local installed_parsers = require('nvim-treesitter').get_installed 'parsers' - - if vim.tbl_contains(installed_parsers, language) then - -- enable the parser if it is installed - treesitter_try_attach(buf, language) - elseif vim.tbl_contains(available_parsers, language) then - -- if a parser is available in `nvim-treesitter` auto install it, and enable it after the installation is done - require('nvim-treesitter').install(language):await(function() treesitter_try_attach(buf, language) end) - else - -- try to enable treesitter features in case the parser exists but is not available from `nvim-treesitter` - treesitter_try_attach(buf, language) - end - end, - }) - end, - }, - - -- The following comments only work if you have downloaded the kickstart repo, not just copy pasted the - -- init.lua. If you want these files, they are in the repository, so you can just download them and - -- place them in the correct locations. - - -- NOTE: Next step on your Neovim journey: Add/Configure additional plugins for Kickstart - -- - -- Here are some example plugins that I've included in the Kickstart repository. - -- Uncomment any of the lines below to enable them (you will need to restart nvim). - -- - -- 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 recommended keymaps - - -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` - -- This is the easiest way to modularize your config. - -- - -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, - -- - -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` - -- Or use telescope! - -- In normal mode type `sh` then write `lazy.nvim-plugin` - -- you can continue same window with `sr` which resumes last telescope search -}, { ---@diagnostic disable-line: missing-fields - ui = { - -- If you are using a Nerd Font: set icons to an empty table which will use the - -- default lazy.nvim defined Nerd Font icons, otherwise define a unicode icons table - icons = vim.g.have_nerd_font and {} or { - cmd = '⌘', - config = '🛠', - event = '📅', - ft = '📂', - init = '⚙', - keys = '🗝', - plugin = '🔌', - runtime = '💻', - require = '🌙', - source = '📄', - start = '🚀', - task = '📌', - lazy = '💤 ', - }, - }, -}) - --- The line beneath this is called `modeline`. See `:help modeline` --- vim: ts=2 sts=2 sw=2 et +require 'plugins.kickstart' diff --git a/lua/custom/git_links.lua b/lua/custom/git_links.lua new file mode 100644 index 00000000000..88155b03ba8 --- /dev/null +++ b/lua/custom/git_links.lua @@ -0,0 +1,55 @@ +--[[ + Path: lua/custom/git_links.lua + Module: custom.git_links + + Purpose + Opens the current buffer’s file on GitHub (or compatible origin) in the + browser, including a line or range anchor from Normal or Visual mode. + + Rationale + Small, focused utility used by `plugins.kickstart.keymaps` (`go`). + Kept under `custom/` so it stays clearly “yours” vs. generated plugin specs. + + Dependencies: git(1), xdg-open (Linux); file must be tracked by git. +]] + +local M = {} + +M.open_github = function() + -- Get current file path relative to the git project root + local file_path = vim.fn.systemlist('git ls-files --full-name ' .. vim.fn.expand '%')[1] + if not file_path or file_path == '' then + print 'File not tracked by git.' + return + end + + -- Get remote URL and clean it up (handles HTTPS and SSH) + local remote = vim.fn.system('git config --get remote.origin.url'):gsub('\n', ''):gsub('%.git$', '') + if remote:match '^git@' then + remote = remote:gsub(':', '/'):gsub('git@', 'https://') + end + + -- Get current branch + local branch = vim.fn.system('git rev-parse --abbrev-ref HEAD'):gsub('\n', '') + + -- Get line numbers (handles single line or visual selection) + local line_start = vim.fn.line 'v' + local line_end = vim.fn.line '.' + if line_start > line_end then + line_start, line_end = line_end, line_start + end + + local line_anchor = 'L' .. line_end + if vim.fn.mode():match '[vV]' then + line_anchor = 'L' .. line_start .. '-L' .. line_end + end + + -- Build and open the URL + local url = string.format('%s/blob/%s/%s#%s', remote, branch, file_path, line_anchor) + + -- Linux only: using xdg-open in the background to avoid freezing Neovim + vim.fn.jobstart({ 'xdg-open', url }, { detach = true }) + print 'Opened in GitHub' +end + +return M diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index b3ddcfdd3aa..50c494f5fbf 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -1,8 +1,34 @@ --- You can add your own plugins here or in other files in this directory! --- I promise not to create any merge conflicts in this directory :) --- --- See the kickstart.nvim README for more information +--[[ + Path: lua/custom/plugins/init.lua + Module: custom.plugins + + Purpose + Lazy.nvim specs for plugins that are not part of the main `plugins.kickstart` + tree (e.g. HTTP client, experimental additions). + + Rationale + `plugins.kickstart.plugins.spec` appends this module last so your personal + plugins stay merge-friendly and easy to find. Neo-tree and core stack live + under `plugins.kickstart.plugins` instead. + + See `:help lazy.nvim-plugin-spec`. +]] ---@module 'lazy' ---@type LazySpec -return {} +return { + { + 'mistweaverco/kulala.nvim', + keys = { + { 'Rs', desc = 'Send request' }, + { 'Ra', desc = 'Send all requests' }, + { 'Rb', desc = 'Open scratchpad' }, + }, + ft = { 'http', 'rest' }, + opts = { + global_keymaps = false, + global_keymaps_prefix = 'R', + kulala_keymaps_prefix = '', + }, + }, +} diff --git a/lua/kickstart/plugins/autopairs.lua b/lua/kickstart/plugins/autopairs.lua deleted file mode 100644 index 351dad86cd5..00000000000 --- a/lua/kickstart/plugins/autopairs.lua +++ /dev/null @@ -1,10 +0,0 @@ --- autopairs --- https://github.com/windwp/nvim-autopairs - ----@module 'lazy' ----@type LazySpec -return { - 'windwp/nvim-autopairs', - event = 'InsertEnter', - opts = {}, -} diff --git a/lua/kickstart/plugins/gitsigns.lua b/lua/kickstart/plugins/gitsigns.lua deleted file mode 100644 index 500ea6c4085..00000000000 --- a/lua/kickstart/plugins/gitsigns.lua +++ /dev/null @@ -1,63 +0,0 @@ --- Adds git related signs to the gutter, as well as utilities for managing changes --- NOTE: gitsigns is already included in init.lua but contains only the base --- config. This will add also the recommended keymaps. - ----@module 'lazy' ----@type LazySpec -return { - 'lewis6991/gitsigns.nvim', - ---@module 'gitsigns' - ---@type Gitsigns.Config - ---@diagnostic disable-next-line: missing-fields - opts = { - on_attach = function(bufnr) - local gitsigns = require 'gitsigns' - - local function map(mode, l, r, opts) - opts = opts or {} - opts.buffer = bufnr - vim.keymap.set(mode, l, r, opts) - end - - -- Navigation - map('n', ']c', function() - if vim.wo.diff then - vim.cmd.normal { ']c', bang = true } - else - gitsigns.nav_hunk 'next' - end - end, { desc = 'Jump to next git [c]hange' }) - - map('n', '[c', function() - if vim.wo.diff then - vim.cmd.normal { '[c', bang = true } - else - gitsigns.nav_hunk 'prev' - end - end, { desc = 'Jump to previous git [c]hange' }) - - -- Actions - -- visual mode - map('v', 'hs', function() gitsigns.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'git [s]tage hunk' }) - map('v', 'hr', function() gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'git [r]eset hunk' }) - -- normal mode - map('n', 'hs', gitsigns.stage_hunk, { desc = 'git [s]tage hunk' }) - map('n', 'hr', gitsigns.reset_hunk, { desc = 'git [r]eset hunk' }) - map('n', 'hS', gitsigns.stage_buffer, { desc = 'git [S]tage buffer' }) - map('n', 'hR', gitsigns.reset_buffer, { desc = 'git [R]eset buffer' }) - map('n', 'hp', gitsigns.preview_hunk, { desc = 'git [p]review hunk' }) - map('n', 'hi', gitsigns.preview_hunk_inline, { desc = 'git preview hunk [i]nline' }) - map('n', 'hb', function() gitsigns.blame_line { full = true } end, { desc = 'git [b]lame line' }) - map('n', 'hd', gitsigns.diffthis, { desc = 'git [d]iff against index' }) - map('n', 'hD', function() gitsigns.diffthis '@' end, { desc = 'git [D]iff against last commit' }) - map('n', 'hQ', function() gitsigns.setqflist 'all' end, { desc = 'git hunk [Q]uickfix list (all files in repo)' }) - map('n', 'hq', gitsigns.setqflist, { desc = 'git hunk [q]uickfix list (all changes in this file)' }) - -- Toggles - map('n', 'tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' }) - map('n', 'tw', gitsigns.toggle_word_diff, { desc = '[T]oggle git intra-line [w]ord diff' }) - - -- Text object - map({ 'o', 'x' }, 'ih', gitsigns.select_hunk) - end, - }, -} diff --git a/lua/kickstart/plugins/indent_line.lua b/lua/kickstart/plugins/indent_line.lua deleted file mode 100644 index 946ac7932ab..00000000000 --- a/lua/kickstart/plugins/indent_line.lua +++ /dev/null @@ -1,13 +0,0 @@ --- Add indentation guides even on blank lines - ----@module 'lazy' ----@type LazySpec -return { - 'lukas-reineke/indent-blankline.nvim', - -- Enable `lukas-reineke/indent-blankline.nvim` - -- See `:help ibl` - main = 'ibl', - ---@module 'ibl' - ---@type ibl.config - opts = {}, -} diff --git a/lua/kickstart/plugins/neo-tree.lua b/lua/kickstart/plugins/neo-tree.lua deleted file mode 100644 index af8d4495650..00000000000 --- a/lua/kickstart/plugins/neo-tree.lua +++ /dev/null @@ -1,29 +0,0 @@ --- Neo-tree is a Neovim plugin to browse the file system --- https://github.com/nvim-neo-tree/neo-tree.nvim - ----@module 'lazy' ----@type LazySpec -return { - 'nvim-neo-tree/neo-tree.nvim', - version = '*', - dependencies = { - 'nvim-lua/plenary.nvim', - 'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended - 'MunifTanjim/nui.nvim', - }, - lazy = false, - keys = { - { '\\', ':Neotree reveal', desc = 'NeoTree reveal', silent = true }, - }, - ---@module 'neo-tree' - ---@type neotree.Config - opts = { - filesystem = { - window = { - mappings = { - ['\\'] = 'close_window', - }, - }, - }, - }, -} diff --git a/lua/plugins/kickstart/autocmds.lua b/lua/plugins/kickstart/autocmds.lua new file mode 100644 index 00000000000..fd3b2f214fd --- /dev/null +++ b/lua/plugins/kickstart/autocmds.lua @@ -0,0 +1,28 @@ +--[[ + Path: lua/plugins/kickstart/autocmds.lua + Module: plugins.kickstart.autocmds + + Purpose + Small, global autocommand hooks: yank highlight feedback and safer defaults + for Markdown buffers (modelines off in untrusted README-style files). + + Rationale + Autocommands belong next to options/keymaps so “editor shell” behavior is + grouped separately from per-plugin `config = function()` blocks. + + See `:help autocmd`, `:help vim.hl.on_yank()`, `:help 'modeline'`. +]] + +vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), + callback = function() vim.hl.on_yank() end, +}) + +vim.api.nvim_create_autocmd('FileType', { + group = vim.api.nvim_create_augroup('kickstart-markdown-safe-read', { clear = true }), + pattern = 'markdown', + callback = function() + vim.opt_local.modeline = false + end, +}) diff --git a/lua/plugins/kickstart/diagnostics.lua b/lua/plugins/kickstart/diagnostics.lua new file mode 100644 index 00000000000..f9f21ee0a4c --- /dev/null +++ b/lua/plugins/kickstart/diagnostics.lua @@ -0,0 +1,41 @@ +--[[ + Path: lua/plugins/kickstart/diagnostics.lua + Module: plugins.kickstart.diagnostics + + Purpose + One global `vim.diagnostic.config` for how LSP diagnostics render: signs, + virtual text, floating previews, underline, and sort order. + + Rationale + A single module avoids conflicting `vim.diagnostic.config` calls (e.g. one + at startup and another inside LSP setup) overwriting each other. + + See `:help vim.diagnostic.config()`, `:help diagnostic-signs`. +]] + +vim.diagnostic.config { + severity_sort = true, + float = { border = 'rounded', source = 'if_many' }, + underline = true, + signs = vim.g.have_nerd_font and { + text = { + [vim.diagnostic.severity.ERROR] = '󰅚 ', + [vim.diagnostic.severity.WARN] = '󰀪 ', + [vim.diagnostic.severity.INFO] = '󰋽 ', + [vim.diagnostic.severity.HINT] = '󰌶 ', + }, + } or {}, + virtual_text = { + source = 'if_many', + spacing = 2, + format = function(diagnostic) + local diagnostic_message = { + [vim.diagnostic.severity.ERROR] = diagnostic.message, + [vim.diagnostic.severity.WARN] = diagnostic.message, + [vim.diagnostic.severity.INFO] = diagnostic.message, + [vim.diagnostic.severity.HINT] = diagnostic.message, + } + return diagnostic_message[diagnostic.severity] + end, + }, +} diff --git a/lua/kickstart/health.lua b/lua/plugins/kickstart/health.lua similarity index 74% rename from lua/kickstart/health.lua rename to lua/plugins/kickstart/health.lua index ca684516003..01fa319df4f 100644 --- a/lua/kickstart/health.lua +++ b/lua/plugins/kickstart/health.lua @@ -1,9 +1,17 @@ --[[ --- --- This file is not required for your own configuration, --- but helps people determine if their system is setup correctly. --- ---]] + Path: lua/plugins/kickstart/health.lua + Module: plugins.kickstart.health + + Purpose + Optional `:checkhealth` provider: Neovim version gate, common CLI tools + (git, make, unzip, rg), and contextual notes for Mason-related warnings. + + Rationale + Health checks catch environment issues before debugging “mystery” plugin + failures. Safe to ignore if you do not run `:checkhealth`; harmless if loaded. + + See `:help health-dev`, `:checkhealth`. +]] local check_version = function() local verstr = tostring(vim.version()) @@ -20,7 +28,6 @@ local check_version = function() end local check_external_reqs = function() - -- Basic utils: `git`, `make`, `unzip` for _, exe in ipairs { 'git', 'make', 'unzip', 'rg' } do local is_executable = vim.fn.executable(exe) == 1 if is_executable then diff --git a/lua/plugins/kickstart/init.lua b/lua/plugins/kickstart/init.lua new file mode 100644 index 00000000000..27ff215cf6f --- /dev/null +++ b/lua/plugins/kickstart/init.lua @@ -0,0 +1,27 @@ +--[[ + Path: lua/plugins/kickstart/init.lua + Module: plugins.kickstart + + Purpose + Orchestrates core editor setup: globals, options, keymaps, autocommands, + diagnostics, then installs and loads third-party plugins via lazy.nvim. + + Load order + 1. Leader keys and UI flags must be set before lazy.nvim (plugin keymaps). + 2. Options, keymaps, autocommands, and diagnostics run before plugins so + baseline behavior exists even if a plugin fails to load. + 3. `lazy.lua` runs last and pulls in the full Lazy plugin spec list. + + See `:help mapleader`, `:help vim.g`, `:help lazy.nvim.txt`. +]] + +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +vim.g.have_nerd_font = true + +require 'plugins.kickstart.options' +require 'plugins.kickstart.keymaps' +require 'plugins.kickstart.autocmds' +require 'plugins.kickstart.diagnostics' +require 'plugins.kickstart.lazy' diff --git a/lua/plugins/kickstart/keymaps.lua b/lua/plugins/kickstart/keymaps.lua new file mode 100644 index 00000000000..5c7fa4e75ed --- /dev/null +++ b/lua/plugins/kickstart/keymaps.lua @@ -0,0 +1,39 @@ +--[[ + Path: lua/plugins/kickstart/keymaps.lua + Module: plugins.kickstart.keymaps + + Purpose + Non-plugin (or minimally coupled) normal-mode maps: search, diagnostics + quickfix, terminal escape, window navigation, GitHub “open in browser,” + Neo-tree toggles, and visual paste without clobbering a register. + + Rationale + Keeping these maps here avoids scattering `vim.keymap.set` across plugin + config files and ensures they exist even before lazy.nvim finishes loading. + + See `:help vim.keymap.set()`, `:help diagnostic-loclist`. +]] + +vim.keymap.set('n', '', 'nohlsearch') + +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) + +vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) + +vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) +vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) +vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) +vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) + +vim.keymap.set('n', 'th', ':split | terminal', { desc = 'Terminal horizontal split' }) +vim.keymap.set('n', 'tv', ':vsplit | terminal', { desc = 'Terminal vertical split' }) +vim.keymap.set('n', 'tt', ':tabnew | terminal', { desc = 'Terminal in new tab' }) +vim.keymap.set('n', 'tf', ':ToggleTerm', { desc = 'Toggle floating terminal' }) + +vim.keymap.set('x', 'p', '"_dP', { noremap = true, silent = true }) + +local git_links = require 'custom.git_links' +vim.keymap.set({ 'n', 'v' }, 'go', git_links.open_github, { desc = 'Open in GitHub' }) + +vim.keymap.set('n', 'x', 'Neotree toggle', { desc = 'NeoTree Toggle' }) +vim.keymap.set('n', 'z', 'Neotree reveal', { desc = 'NeoTree Reveal' }) diff --git a/lua/plugins/kickstart/lazy.lua b/lua/plugins/kickstart/lazy.lua new file mode 100644 index 00000000000..ae2d9fec902 --- /dev/null +++ b/lua/plugins/kickstart/lazy.lua @@ -0,0 +1,45 @@ +--[[ + Path: lua/plugins/kickstart/lazy.lua + Module: plugins.kickstart.lazy + + Purpose + Bootstraps folke/lazy.nvim if missing, prepends it to runtimepath, and calls + `lazy.setup()` with the aggregated plugin specification plus UI icon prefs. + + Rationale + lazy.nvim must be on `runtimepath` before `require('lazy')`. Keeping clone + + setup here isolates plugin-manager mechanics from editor options/keymaps. + + See `:help lazy.nvim.txt`, `:help rtp`. +]] + +local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = 'https://github.com/folke/lazy.nvim.git' + local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } + if vim.v.shell_error ~= 0 then error('Error cloning lazy.nvim:\n' .. out) end +end + +---@type vim.Option +local rtp = vim.opt.rtp +rtp:prepend(lazypath) + +require('lazy').setup(require 'plugins.kickstart.plugins.spec', { + ui = { + icons = vim.g.have_nerd_font and {} or { + cmd = '⌘', + config = '🛠', + event = '📅', + ft = '📂', + init = '⚙', + keys = '🗝', + plugin = '🔌', + runtime = '💻', + require = '🌙', + source = '📄', + start = '🚀', + task = '📌', + lazy = '💤 ', + }, + }, +}) diff --git a/lua/plugins/kickstart/options.lua b/lua/plugins/kickstart/options.lua new file mode 100644 index 00000000000..e0b5ea83993 --- /dev/null +++ b/lua/plugins/kickstart/options.lua @@ -0,0 +1,54 @@ +--[[ + Path: lua/plugins/kickstart/options.lua + Module: plugins.kickstart.options + + Purpose + Sets buffer-agnostic Neovim options (`vim.o` / `vim.opt`): editing feel, + UI chrome, search, splits, and persistence (e.g. undofile). + + Rationale + Centralizing options keeps behavior predictable and documents defaults in + one place. Clipboard is scheduled after UI enter to avoid slowing startup. + + See `:help vim.o`, `:help option-list`, `:help 'clipboard'`. +]] + +vim.o.number = true + +vim.o.mouse = 'a' + +vim.o.showmode = false + +vim.schedule(function() vim.o.clipboard = 'unnamedplus' end) + +vim.o.breakindent = true + +vim.o.undofile = true + +vim.o.ignorecase = true +vim.o.smartcase = true + +vim.o.signcolumn = 'yes' + +vim.o.updatetime = 250 + +vim.o.timeoutlen = 300 + +vim.o.splitright = true +vim.o.splitbelow = true + +vim.o.list = true +vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } + +vim.o.inccommand = 'split' + +vim.o.cursorline = true + +vim.o.scrolloff = 10 + +vim.o.confirm = true + +vim.opt.number = true +vim.opt.relativenumber = true + +vim.opt.autoread = true diff --git a/lua/plugins/kickstart/plugins/autopairs.lua b/lua/plugins/kickstart/plugins/autopairs.lua new file mode 100644 index 00000000000..35f759c2920 --- /dev/null +++ b/lua/plugins/kickstart/plugins/autopairs.lua @@ -0,0 +1,22 @@ +--[[ + Path: lua/plugins/kickstart/plugins/autopairs.lua + Module: plugins.kickstart.plugins.autopairs + + Purpose + Lazy spec for nvim-autopairs: inserts/closes paired brackets and quotes in + Insert mode; integrates cleanly with completion when configured. + + Rationale + Loaded on `InsertEnter` so startup stays fast. Empty `opts` uses plugin + defaults; customize here if you need rule exceptions or cmp integration. + + See https://github.com/windwp/nvim-autopairs +]] + +---@module 'lazy' +---@type LazySpec +return { + 'windwp/nvim-autopairs', + event = 'InsertEnter', + opts = {}, +} diff --git a/lua/plugins/kickstart/plugins/blink.lua b/lua/plugins/kickstart/plugins/blink.lua new file mode 100644 index 00000000000..d3b6a1b087f --- /dev/null +++ b/lua/plugins/kickstart/plugins/blink.lua @@ -0,0 +1,111 @@ +--[[ + Path: lua/plugins/kickstart/plugins/blink.lua + Module: plugins.kickstart.plugins.blink + + Purpose + Lazy spec for saghen/blink.cmp: completion menu, LSP source, snippets via + LuaSnip, signature help, and keymap preset (`super-tab`). + + Rationale + Standalone entry complements the `blink.cmp` dependency pinned under + `lsp.lua` so capabilities exist before servers start; lazy merges duplicate + plugin IDs by version. + + See `:help blink.cmp`. +]] + +---@type LazySpec +return { +{ -- Autocompletion + 'saghen/blink.cmp', + event = 'VimEnter', + version = '1.*', + dependencies = { + -- Snippet Engine + { + 'L3MON4D3/LuaSnip', + version = '2.*', + build = (function() + -- Build Step is needed for regex support in snippets. + -- This step is not supported in many windows environments. + -- Remove the below condition to re-enable on windows. + if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then return end + return 'make install_jsregexp' + end)(), + dependencies = { + -- `friendly-snippets` contains a variety of premade snippets. + -- See the README about individual language/framework/plugin snippets: + -- https://github.com/rafamadriz/friendly-snippets + -- { + -- 'rafamadriz/friendly-snippets', + -- config = function() + -- require('luasnip.loaders.from_vscode').lazy_load() + -- end, + -- }, + }, + opts = {}, + }, + }, + ---@module 'blink.cmp' + ---@type blink.cmp.Config + opts = { + keymap = { + -- 'default' (recommended) for mappings similar to built-in completions + -- to accept ([y]es) the completion. + -- This will auto-import if your LSP supports it. + -- This will expand snippets if the LSP sent a snippet. + -- 'super-tab' for tab to accept + -- 'enter' for enter to accept + -- 'none' for no mappings + -- + -- For an understanding of why the 'default' preset is recommended, + -- you will need to read `:help ins-completion` + -- + -- No, but seriously. Please read `:help ins-completion`, it is really good! + -- + -- All presets have the following mappings: + -- /: move to right/left of your snippet expansion + -- : Open menu or open docs if already open + -- / or /: Select next/previous item + -- : Hide menu + -- : Toggle signature help + -- + -- See :h blink-cmp-config-keymap for defining your own keymap + preset = 'super-tab', + + -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: + -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps + }, + + appearance = { + -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- Adjusts spacing to ensure icons are aligned + nerd_font_variant = 'mono', + }, + + completion = { + -- By default, you may press `` to show the documentation. + -- Optionally, set `auto_show = true` to show the documentation after a delay. + documentation = { auto_show = false, auto_show_delay_ms = 500 }, + }, + + sources = { + default = { 'lsp', 'path', 'snippets' }, + }, + + snippets = { preset = 'luasnip' }, + + -- Blink.cmp includes an optional, recommended rust fuzzy matcher, + -- which automatically downloads a prebuilt binary when enabled. + -- + -- By default, we use the Lua implementation instead, but you may enable + -- the rust implementation via `'prefer_rust_with_warning'` + -- + -- See :h blink-cmp-config-fuzzy for more information + fuzzy = { implementation = 'lua' }, + + -- Shows a signature help window while you type arguments for a function + signature = { enabled = true }, + }, +}, +} diff --git a/lua/plugins/kickstart/plugins/conform.lua b/lua/plugins/kickstart/plugins/conform.lua new file mode 100644 index 00000000000..a3ef7e4c635 --- /dev/null +++ b/lua/plugins/kickstart/plugins/conform.lua @@ -0,0 +1,76 @@ +--[[ + Path: lua/plugins/kickstart/plugins/conform.lua + Module: plugins.kickstart.plugins.conform + + Purpose + Lazy spec for conform.nvim: formatter orchestration (`f`), per-FT + formatter lists (stylua, sql_formatter, prettier), and format-on-save policy. + + Rationale + Keeps formatting separate from LSP where you explicitly disable or gate LSP + format fallback per filetype. + + See `:help conform.nvim`. +]] + +---@type LazySpec +return { +{ -- Autoformat + 'stevearc/conform.nvim', + event = { 'BufWritePre' }, + cmd = { 'ConformInfo' }, + keys = { + { + 'f', + function() require('conform').format { async = true } end, + mode = '', + desc = '[F]ormat buffer', + }, + }, + ---@module 'conform' + ---@type conform.setupOpts + 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, + typescript = true, + typescriptreact = true, + javascript = true, + javascriptreact = true, + python = true, + sql = true, + json = true, + } + if disable_filetypes[vim.bo[bufnr].filetype] then + return nil + else + return nil + end + end, + default_format_opts = { + lsp_format = 'fallback', -- Use external formatters if configured below, otherwise use LSP formatting. Set to `false` to disable LSP formatting entirely. + }, + -- You can also specify external formatters in here. + formatters_by_ft = { + lua = { 'stylua' }, + sql = { 'sql_formatter' }, + json = { 'prettier' }, + -- Conform can also run multiple formatters sequentially + -- python = { "isort", "black" }, + -- + -- You can use 'stop_after_first' to run the first available formatter from the list + -- javascript = { "prettierd", "prettier", stop_after_first = true }, + }, + formatters = { + ['sql_formatter'] = { + prepend_args = { '-l', 'postgresql', '-c', '{"useTabs": true}' }, + }, + }, + }, +}, +} diff --git a/lua/kickstart/plugins/debug.lua b/lua/plugins/kickstart/plugins/debug.lua similarity index 68% rename from lua/kickstart/plugins/debug.lua rename to lua/plugins/kickstart/plugins/debug.lua index 7e58905e830..403c87598b9 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/plugins/kickstart/plugins/debug.lua @@ -1,10 +1,17 @@ --- debug.lua --- --- Shows how to use the DAP plugin to debug your code. --- --- Primarily focused on configuring the debugger for Go, but can --- be extended to other languages as well. That's why it's called --- kickstart.nvim and not kitchen-sink.nvim ;) +--[[ + Path: lua/plugins/kickstart/plugins/debug.lua + Module: plugins.kickstart.plugins.debug + + Purpose + Lazy spec for nvim-dap + nvim-dap-ui + mason-nvim-dap + nvim-dap-go: debug + sessions, UI controls, breakpoint signs, and Go/Delve configurations. + + Rationale + Debugging is optional but heavy; isolating DAP keeps optional tooling out of + LSP startup. Extend `dap.configurations` for other languages as needed. + + See `:help dap.txt`, plugin READMEs. +]] ---@module 'lazy' ---@type LazySpec @@ -83,16 +90,16 @@ return { } -- Change breakpoint icons - -- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' }) - -- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' }) - -- local breakpoint_icons = vim.g.have_nerd_font - -- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' } - -- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' } - -- for type, icon in pairs(breakpoint_icons) do - -- local tp = 'Dap' .. type - -- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak' - -- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl }) - -- end + vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' }) + vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' }) + local breakpoint_icons = vim.g.have_nerd_font + and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' } + or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' } + for type, icon in pairs(breakpoint_icons) do + local tp = 'Dap' .. type + local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak' + vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl }) + end dap.listeners.after.event_initialized['dapui_config'] = dapui.open dap.listeners.before.event_terminated['dapui_config'] = dapui.close @@ -100,11 +107,25 @@ return { -- Install golang specific config require('dap-go').setup { + dap_configurations_from_gopls = false, delve = { -- On Windows delve must be run attached or it crashes. -- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring detached = vim.fn.has 'win32' == 0, }, } + dap.configurations.go = dap.configurations.go or {} + table.insert(dap.configurations.go, { + type = 'go', + name = 'Attach remote (localhost:2345)', + mode = 'remote', + request = 'attach', + -- Connect to the port, not PID + port = 2345, + host = '127.0.0.1', + substitutePath = { + { from = '${workspaceFolder}', to = vim.fn.getcwd() }, + }, + }) end, } diff --git a/lua/plugins/kickstart/plugins/gitsigns.lua b/lua/plugins/kickstart/plugins/gitsigns.lua new file mode 100644 index 00000000000..53b55e05019 --- /dev/null +++ b/lua/plugins/kickstart/plugins/gitsigns.lua @@ -0,0 +1,101 @@ +--[[ + Path: lua/plugins/kickstart/plugins/gitsigns.lua + Module: plugins.kickstart.plugins.gitsigns + + Purpose + Lazy spec for lewis6991/gitsigns.nvim: gutter hunks, stage/reset, blame, + diff against index / HEAD / default branch, and buffer-local keymaps. + + Rationale + Single source of truth for Git-in-editor UX; pairs with which-key groups + under `h` and avoids duplicating gitsigns setup in `init.lua`. + + See `:help gitsigns`. +]] + +---@type LazySpec +return { +{ -- Adds git related signs to the gutter, as well as utilities for managing changes + 'lewis6991/gitsigns.nvim', + ---@module 'gitsigns' + ---@type Gitsigns.Config + ---@diagnostic disable-next-line: missing-fields + opts = { + signs = { + add = { text = '+' }, ---@diagnostic disable-line: missing-fields + change = { text = '~' }, ---@diagnostic disable-line: missing-fields + delete = { text = '_' }, ---@diagnostic disable-line: missing-fields + topdelete = { text = '‾' }, ---@diagnostic disable-line: missing-fields + changedelete = { text = '~' }, ---@diagnostic disable-line: missing-fields + }, + on_attach = function(bufnr) + local gitsigns = require 'gitsigns' + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Detect branch once per buffer attach + local primary_branch = 'main' + local handle = io.popen 'git branch --list main master' + if handle then + local result = handle:read '*a' + handle:close() + if not string.find(result, 'main') and string.find(result, 'master') then + primary_branch = 'master' + end + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then + vim.cmd.normal { ']c', bang = true } + else + gitsigns.nav_hunk 'next' + end + end, { desc = 'Jump to next git [c]hange' }) + + map('n', '[c', function() + if vim.wo.diff then + vim.cmd.normal { '[c', bang = true } + else + gitsigns.nav_hunk 'prev' + end + end, { desc = 'Jump to previous git [c]hange' }) + + -- Actions + map('v', 'hs', function() + gitsigns.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'git [s]tage hunk' }) + map('v', 'hr', function() + gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'git [r]eset hunk' }) + + map('n', 'hs', gitsigns.stage_hunk, { desc = 'git [s]tage hunk' }) + map('n', 'hr', gitsigns.reset_hunk, { desc = 'git [r]eset hunk' }) + map('n', 'hS', gitsigns.stage_buffer, { desc = 'git [S]tage buffer' }) + map('n', 'hu', gitsigns.stage_hunk, { desc = 'git [u]ndo stage hunk' }) + map('n', 'hR', gitsigns.reset_buffer, { desc = 'git [R]eset buffer' }) + map('n', 'hp', gitsigns.preview_hunk, { desc = 'git [p]review hunk' }) + map('n', 'hb', gitsigns.blame_line, { desc = 'git [b]lame line' }) + map('n', 'hB', gitsigns.blame, { desc = 'git [B]lame toggle' }) + + -- Diff Mappings + map('n', 'hd', gitsigns.diffthis, { desc = 'git [d]iff against index' }) + map('n', 'hD', function() + gitsigns.diffthis '@' + end, { desc = 'git [D]iff against last commit' }) + + map('n', 'hm', function() + gitsigns.diffthis(primary_branch) + end, { desc = 'git diff against [m]ain/master' }) + + -- Toggles + map('n', 'ht', gitsigns.toggle_current_line_blame, { desc = '[t]oggle git show blame line' }) + map('n', 'hv', gitsigns.preview_hunk_inline, { desc = 'toggle git show deleted ([v]iew)' }) + end, + }, +}, +} diff --git a/lua/plugins/kickstart/plugins/guess_indent.lua b/lua/plugins/kickstart/plugins/guess_indent.lua new file mode 100644 index 00000000000..813febcb032 --- /dev/null +++ b/lua/plugins/kickstart/plugins/guess_indent.lua @@ -0,0 +1,19 @@ +--[[ + Path: lua/plugins/kickstart/plugins/guess_indent.lua + Module: plugins.kickstart.plugins.guess_indent + + Purpose + Lazy spec for guess-indent.nvim: detects indentation style per buffer so new + lines match tabs vs. spaces without manual `:set sw=`. + + Rationale + Lightweight, runs early in the spec list; no keymaps. Keeps indent behavior + consistent before Treesitter or LSP attach. + + See plugin README; `:help 'shiftwidth'`. +]] + +---@type LazySpec +return { + { 'NMAC427/guess-indent.nvim', opts = {} }, +} diff --git a/lua/plugins/kickstart/plugins/indent_line.lua b/lua/plugins/kickstart/plugins/indent_line.lua new file mode 100644 index 00000000000..38b170006a0 --- /dev/null +++ b/lua/plugins/kickstart/plugins/indent_line.lua @@ -0,0 +1,26 @@ +--[[ + Path: lua/plugins/kickstart/plugins/indent_line.lua + Module: plugins.kickstart.plugins.indent_line + + Purpose + Lazy spec for indent-blankline.nvim (`ibl`): optional vertical guides aligned + with indentation levels for readability in deeply nested code. + + Rationale + Purely visual; lazy-loads via `main = 'ibl'`. Defaults are minimal; extend + `opts` if you want scope rules or excluded filetypes. + + See `:help ibl.txt`. +]] + +---@module 'lazy' +---@type LazySpec +return { + 'lukas-reineke/indent-blankline.nvim', + -- Enable `lukas-reineke/indent-blankline.nvim` + -- See `:help ibl` + main = 'ibl', + ---@module 'ibl' + ---@type ibl.config + opts = {}, +} diff --git a/lua/kickstart/plugins/lint.lua b/lua/plugins/kickstart/plugins/lint.lua similarity index 82% rename from lua/kickstart/plugins/lint.lua rename to lua/plugins/kickstart/plugins/lint.lua index 556f3178811..4c5d5b04f6f 100644 --- a/lua/kickstart/plugins/lint.lua +++ b/lua/plugins/kickstart/plugins/lint.lua @@ -1,4 +1,17 @@ --- Linting +--[[ + Path: lua/plugins/kickstart/plugins/lint.lua + Module: plugins.kickstart.plugins.lint + + Purpose + Lazy spec for nvim-lint: asynchronous linters per filetype (here Markdown + via markdownlint) triggered on buffer enter / write / leaving Insert mode. + + Rationale + Complements LSP diagnostics where you want CLI linters or faster feedback. + Extend `linters_by_ft` as you add tools to Mason or the host system. + + See `:help nvim-lint.txt`. +]] ---@module 'lazy' ---@type LazySpec diff --git a/lua/plugins/kickstart/plugins/lsp.lua b/lua/plugins/kickstart/plugins/lsp.lua new file mode 100644 index 00000000000..94c9bd6808e --- /dev/null +++ b/lua/plugins/kickstart/plugins/lsp.lua @@ -0,0 +1,437 @@ +--[[ + Path: lua/plugins/kickstart/plugins/lsp.lua + Module: plugins.kickstart.plugins.lsp + + Purpose + Lazy spec for nvim-lspconfig + Mason + blink.cmp integration: LspAttach + keymaps, server table (clangd, gopls, pyright, rust, ts_ls, lua_ls, etc.), + Mason tool installer, and 0.11 `vim.lsp.config` / `vim.lsp.enable` wiring. + + Rationale + Concentrates all LSP lifecycle logic in one place. Blink is both a + dependency (capabilities) and a top-level plugin spec in `blink.lua`. + + See `:help lsp`, `:help mason.nvim`, `:help blink.cmp`. +]] + +---@type LazySpec +return { +{ + -- Main LSP Configuration + 'neovim/nvim-lspconfig', + dependencies = { + -- Load before this plugin's config runs so get_lsp_capabilities() exists even when + -- LSP startup happens before VimEnter (e.g. `nvim file.py`). + { 'saghen/blink.cmp', version = '1.*' }, + -- Automatically install LSPs and related tools to stdpath for Neovim + -- Mason must be loaded before its dependents so we need to set it up here. + -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})` + { + 'mason-org/mason.nvim', + ---@module 'mason.settings' + ---@type MasonSettings + ---@diagnostic disable-next-line: missing-fields + opts = {}, + }, + -- Maps LSP server names between nvim-lspconfig and Mason package names. + 'mason-org/mason-lspconfig.nvim', + 'WhoIsSethDaniel/mason-tool-installer.nvim', + + -- Useful status updates for LSP. + { 'j-hui/fidget.nvim', opts = {} }, + }, + config = function() + -- Brief aside: **What is LSP?** + -- + -- LSP is an initialism you've probably heard, but might not understand what it is. + -- + -- LSP stands for Language Server Protocol. It's a protocol that helps editors + -- and language tooling communicate in a standardized fashion. + -- + -- In general, you have a "server" which is some tool built to understand a particular + -- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc.). These Language Servers + -- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone + -- processes that communicate with some "client" - in this case, Neovim! + -- + -- LSP provides Neovim with features like: + -- - Go to definition + -- - Find references + -- - Autocompletion + -- - Symbol Search + -- - and more! + -- + -- Thus, Language Servers are external tools that must be installed separately from + -- Neovim. This is where `mason` and related plugins come into play. + -- + -- If you're wondering about lsp vs treesitter, you can check out the wonderfully + -- and elegantly composed help section, `:help lsp-vs-treesitter` + + -- This function gets run when an LSP attaches to a particular buffer. + -- That is to say, every time a new file is opened that is associated with + -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this + -- function will be executed to configure the current buffer + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), + callback = function(event) + -- NOTE: Remember that Lua is a real programming language, and as such it is possible + -- to define small helper and utility functions so you don't have to repeat yourself. + -- + -- In this case, we create a function that lets us more easily define mappings specific + -- for LSP related items. It sets the mode, buffer and description for us each time. + local map = function(keys, func, desc, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) + end + + -- Rename the variable under your cursor. + -- Most Language Servers support renaming across files, etc. + map('grn', vim.lsp.buf.rename, '[R]e[n]ame') + + -- Execute a code action, usually your cursor needs to be on top of an error + -- or a suggestion from your LSP for this to activate. + map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) + + -- WARN: This is not Goto Definition, this is Goto Declaration. + -- For example, in C this would take you to the header. + map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + + -- Defer requiring Telescope until keypress: on `nvim file.py`, LspAttach can run + -- before VimEnter, when lazy.nvim has not loaded telescope.nvim yet. + -- + -- Nvim 0.11+ sets *global* defaults grr/gri/grt/gO → vim.lsp.buf.* (quickfix / loclist). + -- Buffer-local maps override. Match kickstart.nvim: grr gri grd gO gW grt (see telescope + -- LspAttach in upstream). `grd` is not a core default — it was only in your fork/telescope. + map('grr', function() require('telescope.builtin').lsp_references() end, '[R]eferences') + map('gri', function() require('telescope.builtin').lsp_implementations() end, '[I]mplementation') + map('grd', function() require('telescope.builtin').lsp_definitions() end, '[G]oto [D]efinition') + map('gO', function() require('telescope.builtin').lsp_document_symbols() end, 'Open Document Symbols') + map('gW', function() require('telescope.builtin').lsp_dynamic_workspace_symbols() end, 'Open Workspace Symbols') + -- gopls may error on anonymous func types ("cannot find type name from type func(...)"): + -- put the cursor on a named identifier, or use grd on the symbol name — same LSP limit. + map('grt', function() require('telescope.builtin').lsp_type_definitions() end, '[G]oto [T]ype Definition') + + -- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10) + local function client_supports_method(client, method, bufnr) + if vim.fn.has 'nvim-0.11' == 1 then + return client:supports_method(method, bufnr) + else + return client.supports_method(method, { bufnr = bufnr }) + end + end + + local client = vim.lsp.get_client_by_id(event.data.client_id) + + -- ========================================================================= + -- NEW: The gopls Semantic Tokens Workaround + -- ========================================================================= + if client and client.name == 'gopls' and not client.server_capabilities.semanticTokensProvider then + local semantic = client.config.capabilities.textDocument.semanticTokens + if semantic then + client.server_capabilities.semanticTokensProvider = { + full = true, + legend = { + tokenTypes = semantic.tokenTypes, + tokenModifiers = semantic.tokenModifiers, + }, + range = true, + } + end + end + -- ========================================================================= + + -- The following two autocommands are used to highlight references of the + -- word under your cursor when your cursor rests there for a little while. + -- See `:help CursorHold` for information about when this is executed + -- + -- When you move your cursor, the highlights will be cleared (the second autocommand). + if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) 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 + + -- The following code creates a keymap to toggle inlay hints in your + -- code, if the language server you are using supports them + -- + -- This may be unwanted, since they displace some of your code + if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) 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, + }) + + + -- LSP servers and clients are able to communicate to each other what features they support. + -- By default, Neovim doesn't support everything that is in the LSP specification. + -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. + -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers. + local capabilities = require('blink.cmp').get_lsp_capabilities() + + -- Enable the following language servers + -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. + -- See `:help lsp-config` for information about keys and how to configure + ---@type table + local servers = { + clangd = {}, + + -- ========================================================================= + -- UPDATED: The unified "God Mode" gopls config + -- ========================================================================= + gopls = { + settings = { + gopls = { + buildFlags = { + '-tags', + 'functional,integration,small,medium,large', + }, + + -- Completion settings + completeUnimported = true, + usePlaceholders = true, + deepCompletion = true, + matcher = 'Fuzzy', + + -- Hover and signature help + hoverKind = 'FullDocumentation', + linkTarget = 'pkg.go.dev', + linksInHover = true, + + -- Does this actually help? + expandWorkspaceToModule = true, + + -- Static analysis and diagnostics + staticcheck = true, -- THIS automatically runs the officially supported staticcheck suite + + analyses = { + -- Only natively supported go vet / gopls checks go here + asmdecl = true, + assign = true, + atomic = true, + atomicalign = true, + bools = true, + buildtag = true, + cgocall = true, + composites = true, + copylock = true, + defers = true, + directive = true, + errorsas = true, + framepointer = true, + httpresponse = true, + ifaceassert = true, + loopclosure = true, + lostcancel = true, + nilfunc = true, + printf = true, + shift = true, + sigchanyzer = true, + slog = true, + stdmethods = true, + stringintconv = true, + structtag = true, + testinggoroutine = true, + tests = true, + timeformat = true, + unmarshal = true, + unreachable = true, + unsafeptr = true, + unusedresult = true, + deepequalerrors = true, + embed = true, + fillreturns = true, + infertypeargs = true, + nilness = true, + nonewvars = true, + noresultvalues = true, + shadow = true, + simplifycompositelit = true, + simplifyrange = true, + simplifyslice = true, + sortslice = true, + stubmethods = true, + undeclaredname = true, + unusedparams = true, + unusedvariable = true, + unusedwrite = true, + useany = true, + }, + + hints = { + assignVariableTypes = true, + compositeLiteralFields = true, + compositeLiteralTypes = true, + constantValues = true, + functionTypeParameters = true, + parameterNames = true, + rangeVariableTypes = true, + }, + + codelenses = { + gc_details = true, + generate = true, + regenerate_cgo = true, + test = true, + tidy = true, + upgrade_dependency = true, + vendor = true, + vulncheck = true, + }, + + gofumpt = true, + directoryFilters = { '-vendor' }, + }, + }, + + on_attach = function(client, bufnr) + if client.name == 'gopls' then + vim.api.nvim_create_autocmd('BufWritePre', { + buffer = bufnr, + callback = function() + vim.lsp.buf.code_action { + context = { diagnostics = {}, only = { 'source.organizeImports' } }, + apply = true, + } + end, + }) + end + end, + }, + -- ========================================================================= + + pyright = {}, + rust_analyzer = {}, + -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs + -- + -- Some languages (like typescript) have entire language plugins that can be useful: + -- https://github.com/pmizio/typescript-tools.nvim + -- + -- But for many setups, the LSP (`ts_ls`) will work just fine + ts_ls = { + settings = {}, + on_attach = function(client, bufnr) + client.server_capabilities.documentFormattingProvider = false + client.server_capabilities.documentRangeFormattingProvider = false + + -- Disable format on save for this buffer + vim.api.nvim_set_option_value('formatoptions', '', { buf = bufnr }) + vim.api.nvim_create_autocmd('BufWritePre', { + buffer = bufnr, + callback = function() + -- Do nothing, preventing format on save + end, + }) + end, + }, + + stylua = {}, -- Used to format Lua code + + -- Special Lua Config, as recommended by neovim help docs + lua_ls = { + on_init = function(client) + client.server_capabilities.documentFormattingProvider = false -- Disable formatting (formatting is done by stylua) + + if client.workspace_folders then + local path = client.workspace_folders[1].name + if path ~= vim.fn.stdpath 'config' and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc')) then return end + end + + client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { + runtime = { + version = 'LuaJIT', + path = { 'lua/?.lua', 'lua/?/init.lua' }, + }, + workspace = { + checkThirdParty = false, + -- NOTE: this is a lot slower and will cause issues when working on your own configuration. + -- See https://github.com/neovim/nvim-lspconfig/issues/3189 + library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), { + '${3rd}/luv/library', + '${3rd}/busted/library', + }), + }, + }) + end, + ---@type lspconfig.settings.lua_ls + settings = { + Lua = { + format = { enable = false }, -- Disable formatting (formatting is done by stylua) + }, + }, + }, + } + -- + -- -- + -- -- FORCE GOPLS SETUP + -- -- + -- local gopls_config = servers.gopls + -- gopls_config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, gopls_config.capabilities or {}) + -- require('lspconfig').gopls.setup(gopls_config) + -- + + -- Ensure the servers and tools above are installed + -- + -- To check the current status of installed tools and/or manually install + -- other tools, you can run + -- :Mason + -- + -- You can press `g?` for help in this menu. + local ensure_installed = vim.tbl_keys(servers or {}) + vim.list_extend(ensure_installed, { + 'stylua', -- Used to format Lua code + 'sql-formatter', + 'prettier', + 'staticcheck', + 'goimports', + 'gofumpt', + 'gomodifytags', + 'impl', + 'golangci-lint', + 'delve', + }) + + require('mason-tool-installer').setup { ensure_installed = ensure_installed } + + require('mason-lspconfig').setup { + ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) + automatic_installation = false, + -- We are removing the handlers block here to prevent Mason + -- from silently skipping unmanaged/globally-installed binaries. + } + + -- Ensure lspconfig is loaded so defaults are populated in Nvim 0.11 + require 'lspconfig' + + -- Explicitly set up all servers defined in the servers table. + for server_name, server in pairs(servers) do + server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + + if vim.fn.has 'nvim-0.11' == 1 then + -- Neovim 0.11+ native config API (prevents deprecation warning) + local def = vim.lsp.config[server_name] or {} + vim.lsp.config[server_name] = vim.tbl_deep_extend('force', def, server) + vim.lsp.enable(server_name) + else + -- Neovim 0.10 and earlier legacy API + require('lspconfig')[server_name].setup(server) + end + end + end, +}, +} diff --git a/lua/plugins/kickstart/plugins/mini.lua b/lua/plugins/kickstart/plugins/mini.lua new file mode 100644 index 00000000000..cdbf970b7e5 --- /dev/null +++ b/lua/plugins/kickstart/plugins/mini.lua @@ -0,0 +1,60 @@ +--[[ + Path: lua/plugins/kickstart/plugins/mini.lua + Module: plugins.kickstart.plugins.mini + + Purpose + Lazy spec for nvim-mini/mini.nvim: loads `mini.ai`, `mini.surround`, and + `mini.statusline` with nerd-font aware icons and a compact location section. + + Rationale + Bundles small quality-of-life modules under one plugin id to reduce Lazy + node count; adjust `mini.ai` mappings if they collide with Treesitter. + + See `:help mini.nvim`. +]] + +---@type LazySpec +return { +{ -- Collection of various small independent plugins/modules + 'nvim-mini/mini.nvim', + config = function() + -- Better Around/Inside textobjects + -- + -- Examples: + -- - va) - [V]isually select [A]round [)]paren + -- - yiiq - [Y]ank [I]nside [I]+1 [Q]uote + -- - ci' - [C]hange [I]nside [']quote + require('mini.ai').setup { + -- NOTE: Avoid conflicts with the built-in incremental selection mappings on Neovim>=0.12 (see `:help treesitter-incremental-selection`) + mappings = { + around_next = 'aa', + inside_next = 'ii', + }, + 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() + + -- Simple and easy statusline. + -- You could remove this setup call if you don't like it, + -- and try some other statusline plugin + local statusline = require 'mini.statusline' + -- set use_icons to true if you have a Nerd Font + statusline.setup { use_icons = vim.g.have_nerd_font } + + -- You can configure sections in the statusline by overriding their + -- default behavior. For example, here we set the section for + -- cursor location to LINE:COLUMN + ---@diagnostic disable-next-line: duplicate-set-field + statusline.section_location = function() return '%2l:%-2v' end + + -- ... and there is more! + -- Check out: https://github.com/nvim-mini/mini.nvim + end, +}, +} diff --git a/lua/plugins/kickstart/plugins/mini_icons.lua b/lua/plugins/kickstart/plugins/mini_icons.lua new file mode 100644 index 00000000000..c70cb3e1226 --- /dev/null +++ b/lua/plugins/kickstart/plugins/mini_icons.lua @@ -0,0 +1,29 @@ +--[[ + Path: lua/plugins/kickstart/plugins/mini_icons.lua + Module: plugins.kickstart.plugins.mini_icons + + Purpose + Lazy spec for mini.icons: consistent glyphs/highlights for special filenames + (e.g. `.go-version`) and filetypes like `gotmpl`. + + Rationale + Complements web-devicons and Treesitter; keeps icon tweaks in one small + table instead of scattering `nvim_set_hl` calls. + + See `:help mini.icons`. +]] + +---@type LazySpec +return { +{ + 'nvim-mini/mini.icons', + opts = { + file = { + ['.go-version'] = { glyph = '', hl = 'MiniIconsBlue' }, + }, + filetype = { + gotmpl = { glyph = '󰟓', hl = 'MiniIconsGrey' }, + }, + }, +}, +} diff --git a/lua/plugins/kickstart/plugins/neo-tree.lua b/lua/plugins/kickstart/plugins/neo-tree.lua new file mode 100644 index 00000000000..2b0ae0c0311 --- /dev/null +++ b/lua/plugins/kickstart/plugins/neo-tree.lua @@ -0,0 +1,47 @@ +--[[ + Path: lua/plugins/kickstart/plugins/neo-tree.lua + Module: plugins.kickstart.plugins.neo-tree + + Purpose + Lazy spec for nvim-neo-tree/neo-tree.nvim: filesystem sidebar, reveal/toggle + keymaps, and tuned `filesystem` options (hidden files, libuv watcher, root). + + Rationale + Centralizes file-tree UX; `x` / `z` maps live in keymaps.lua. + Kept separate from `custom.plugins` so “core” navigation stays discoverable. + + See https://github.com/nvim-neo-tree/neo-tree.nvim +]] + +---@module 'lazy' +---@type LazySpec +return { + { + 'nvim-neo-tree/neo-tree.nvim', + version = '*', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons', + 'MunifTanjim/nui.nvim', + }, + lazy = false, + keys = { + { '\\', ':Neotree reveal', desc = 'NeoTree reveal', silent = true }, + }, + ---@module 'neo-tree' + ---@type neotree.Config + opts = { + filesystem = { + visible = false, + window = { + use_libuv_file_watcher = true, + mappings = { + ['\\'] = 'close_window', + ['.'] = 'set_root', + ['H'] = 'toggle_hidden', + }, + }, + }, + }, + }, +} diff --git a/lua/plugins/kickstart/plugins/neotest_golang.lua b/lua/plugins/kickstart/plugins/neotest_golang.lua new file mode 100644 index 00000000000..23db821f2c2 --- /dev/null +++ b/lua/plugins/kickstart/plugins/neotest_golang.lua @@ -0,0 +1,21 @@ +--[[ + Path: lua/plugins/kickstart/plugins/neotest_golang.lua + Module: plugins.kickstart.plugins.neotest_golang + + Purpose + Lazy spec for neotest-golang: Neotest adapter for Go tests (table-driven, + subtests) when you wire Neotest core elsewhere. + + Rationale + Declared as a standalone plugin entry so enabling `nvim-neotest/neotest` + later only requires adding the core plugin + runners; this stays inert until then. + + See https://github.com/nvim-neotest/neotest and adapter README. +]] + +---@type LazySpec +return { +{ + 'fredrikaverpil/neotest-golang', +}, +} diff --git a/lua/plugins/kickstart/plugins/render_markdown.lua b/lua/plugins/kickstart/plugins/render_markdown.lua new file mode 100644 index 00000000000..352b5cf6871 --- /dev/null +++ b/lua/plugins/kickstart/plugins/render_markdown.lua @@ -0,0 +1,27 @@ +--[[ + Path: lua/plugins/kickstart/plugins/render_markdown.lua + Module: plugins.kickstart.plugins.render_markdown + + Purpose + Lazy spec for render-markdown.nvim: in-buffer Markdown preview (no external + server), with LaTeX disabled and LSP/blink completion hooks enabled. + + Rationale + Filetype-limited load keeps startup lean; pairs with Treesitter + mini.nvim + as declared dependencies. + + See plugin README; `:help render-markdown.nvim` if bundled. +]] + +---@type LazySpec +return { +{ + 'MeanderingProgrammer/render-markdown.nvim', + dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-mini/mini.nvim' }, + ft = { 'markdown', 'markdown.mdx' }, + opts = { + latex = { enabled = false }, + completions = { lsp = { enabled = true }, blink = { enabled = true } }, + }, +}, +} diff --git a/lua/plugins/kickstart/plugins/spec.lua b/lua/plugins/kickstart/plugins/spec.lua new file mode 100644 index 00000000000..810be8e7e89 --- /dev/null +++ b/lua/plugins/kickstart/plugins/spec.lua @@ -0,0 +1,59 @@ +--[[ + Path: lua/plugins/kickstart/plugins/spec.lua + Module: plugins.kickstart.plugins.spec + + Purpose + Builds the complete lazy.nvim plugin list: requires each per-plugin module, + normalizes return shapes (single spec vs. `{ spec }`), and returns one flat + `LazySpec` array for `lazy.setup()`. + + Rationale + Splitting each plugin into its own file keeps diffs small and matches how + lazy.nvim expects multiple tables to be merged at setup time. + + See `:help lazy.nvim-plugin-spec`, `:help LazySpec`. +]] + +---@param out table +---@param chunk LazySpec|LazySpec[] +local function append_specs(out, chunk) + if type(chunk[1]) == 'string' then + out[#out + 1] = chunk + return + end + for i = 1, #chunk do + out[#out + 1] = chunk[i] + end +end + +---@type LazySpec +local specs = {} +local mods = { + 'plugins.kickstart.plugins.guess_indent', + 'plugins.kickstart.plugins.gitsigns', + 'plugins.kickstart.plugins.which_key', + 'plugins.kickstart.plugins.render_markdown', + 'plugins.kickstart.plugins.telescope', + 'plugins.kickstart.plugins.lsp', + 'plugins.kickstart.plugins.conform', + 'plugins.kickstart.plugins.blink', + 'plugins.kickstart.plugins.tokyonight', + 'plugins.kickstart.plugins.todo_comments', + 'plugins.kickstart.plugins.mini', + 'plugins.kickstart.plugins.treesitter', + 'plugins.kickstart.plugins.vim_helm', + 'plugins.kickstart.plugins.neotest_golang', + 'plugins.kickstart.plugins.mini_icons', + 'plugins.kickstart.plugins.debug', + 'plugins.kickstart.plugins.indent_line', + 'plugins.kickstart.plugins.lint', + 'plugins.kickstart.plugins.autopairs', + 'plugins.kickstart.plugins.neo-tree', + 'custom.plugins', +} + +for _, mod in ipairs(mods) do + append_specs(specs, require(mod)) +end + +return specs diff --git a/lua/plugins/kickstart/plugins/telescope.lua b/lua/plugins/kickstart/plugins/telescope.lua new file mode 100644 index 00000000000..8bcc684bb5a --- /dev/null +++ b/lua/plugins/kickstart/plugins/telescope.lua @@ -0,0 +1,175 @@ +--[[ + Path: lua/plugins/kickstart/plugins/telescope.lua + Module: plugins.kickstart.plugins.telescope + + Purpose + Lazy spec for telescope.nvim: fuzzy finder for files, grep, diagnostics, + git, help, and LSP pickers; includes fzf-native and ui-select extensions. + + Rationale + Large `config` function registers `s*` maps and theme extensions. + Deferred `require('telescope.builtin')` from LSP attach remains valid. + + See `:help telescope`, `:help telescope.setup()`. +]] + +---@type LazySpec +return { +{ -- Fuzzy Finder (files, lsp, etc) + 'nvim-telescope/telescope.nvim', + -- By default, Telescope is included and acts as your picker for everything. + + -- If you would like to switch to a different picker (like snacks, or fzf-lua) + -- you can disable the Telescope plugin by setting enabled to false and enable + -- your replacement picker by requiring it explicitly (e.g. 'custom.plugins.snacks') + + -- Note: If you customize your config for yourself, + -- it’s best to remove the Telescope plugin config entirely + -- instead of just disabling it here, to keep your config clean. + enabled = true, + event = 'VimEnter', + dependencies = { + 'nvim-lua/plenary.nvim', + { -- If encountering errors, see telescope-fzf-native README for installation instructions + 'nvim-telescope/telescope-fzf-native.nvim', + + -- `build` is used to run some command when the plugin is installed/updated. + -- This is only run then, not every time Neovim starts up. + build = 'make', + + -- `cond` is a condition used to determine whether this plugin should be + -- installed and loaded. + cond = function() return vim.fn.executable 'make' == 1 end, + }, + { 'nvim-telescope/telescope-ui-select.nvim' }, + + -- Useful for getting pretty icons, but requires a Nerd Font. + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, + }, + config = function() + -- Telescope is a fuzzy finder that comes with a lot of different things that + -- it can fuzzy find! It's more than just a "file finder", it can search + -- many different aspects of Neovim, your workspace, LSP, and more! + -- + -- The easiest way to use Telescope, is to start by doing something like: + -- :Telescope help_tags + -- + -- After running this command, a window will open up and you're able to + -- type in the prompt window. You'll see a list of `help_tags` options and + -- a corresponding preview of the help. + -- + -- Two important keymaps to use while in Telescope are: + -- - Insert mode: + -- - Normal mode: ? + -- + -- This opens a window that shows you all of the keymaps for the current + -- Telescope picker. This is really useful to discover what Telescope can + -- do as well as how to actually do it! + + -- [[ Configure Telescope ]] + -- See `:help telescope` and `:help telescope.setup()` + require('telescope').setup { + -- You can put your default mappings / updates / etc. in here + -- All the info you're looking for is in `:help 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', 'v' }, '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', 'sD', function() + local current_dir = vim.fn.expand '%:p:h' -- Gets the absolute path to the current file's folder + require('telescope.builtin').diagnostics { + cwd = current_dir, + -- This ensures it searches within the directory, not just the file + root_dir = current_dir, + } + end, { desc = '[S]earch [D]iagnostics in current directory' }) + 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', 'sc', builtin.commands, { desc = '[S]earch [C]ommands' }) + vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + + -- vim.keymap.set('n', 'g', '', { desc = '[Git]' }) + -- vim.keymap.set('n', 'gl', builtin.git_bcommits, { desc = '[Git] Buffer Commits' }) + -- vim.keymap.set('n', 'gr', builtin.git_bcommits_range, { desc = '[Git] Buffer Commits Range' }) + -- vim.keymap.set('n', 'gb', builtin.git_branches, { desc = '[Git] Branches' }) + -- vim.keymap.set('n', 'gc', builtin.git_commits, { desc = '[Git] Commits' }) + -- vim.keymap.set('n', 'gf', builtin.git_files, { desc = '[Git] Files' }) + -- vim.keymap.set('n', 'gt', builtin.git_stash, { desc = '[Git] Stash' }) + -- vim.keymap.set('n', 'gs', builtin.git_status, { desc = '[Git] Status' }) + -- vim.keymap.set('n', 'gm', function() + -- builtin.git_commits { + -- git_command = { 'git', 'log', '--oneline', '--decorate', 'main..HEAD' }, + -- } + -- end, { desc = '[Git] Commits ahead of main' }) + + -- 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' }) + + -- 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' } + ) + + -- Shortcut for searching your Neovim configuration files + vim.keymap.set('n', 'sn', function() + builtin.find_files { cwd = vim.fn.stdpath 'config' } + end, { desc = '[S]earch [N]eovim files' }) + + vim.keymap.set('n', 'sag', function() + builtin.live_grep { + prompt_title = 'Live Grep (All Files)', + -- This function adds the flags to the underlying grep command + additional_args = function(args) + return { '--hidden', '--no-ignore', '--no-ignore-parent', '--glob=!**/.git/*' } + end, + } + end, { desc = '[S]earch [A]ll Files [G]rep)' }) + + vim.keymap.set('n', 'saf', function() + builtin.find_files { + prompt_title = 'Find All Files (Hidden + Ignored)', + hidden = true, -- Show hidden dotfiles + no_ignore = true, -- Ignore .gitignore rules + no_ignore_parent = true, -- Ignore .gitignore rules of all parents, too + file_ignore_patterns = { '.git/' }, -- <--- Explicitly remove the .git folder + } + end, { desc = '[S]earch [A]ll [F]iles' }) + end, +}, +} diff --git a/lua/plugins/kickstart/plugins/todo_comments.lua b/lua/plugins/kickstart/plugins/todo_comments.lua new file mode 100644 index 00000000000..9e75d49ac3b --- /dev/null +++ b/lua/plugins/kickstart/plugins/todo_comments.lua @@ -0,0 +1,27 @@ +--[[ + Path: lua/plugins/kickstart/plugins/todo_comments.lua + Module: plugins.kickstart.plugins.todo_comments + + Purpose + Lazy spec for todo-comments.nvim: highlights TODO/FIXME/HACK-style comment + tokens and can integrate with Telescope (optional). + + Rationale + Purely visual aid for scanning large codebases; `signs = false` avoids + gutter clutter if you prefer highlight-only. + + See https://github.com/folke/todo-comments.nvim +]] + +---@type LazySpec +return { +{ + 'folke/todo-comments.nvim', + event = 'VimEnter', + dependencies = { 'nvim-lua/plenary.nvim' }, + ---@module 'todo-comments' + ---@type TodoOptions + ---@diagnostic disable-next-line: missing-fields + opts = { signs = false }, +}, +} diff --git a/lua/plugins/kickstart/plugins/tokyonight.lua b/lua/plugins/kickstart/plugins/tokyonight.lua new file mode 100644 index 00000000000..c63e7642392 --- /dev/null +++ b/lua/plugins/kickstart/plugins/tokyonight.lua @@ -0,0 +1,39 @@ +--[[ + Path: lua/plugins/kickstart/plugins/tokyonight.lua + Module: plugins.kickstart.plugins.tokyonight + + Purpose + Lazy spec for tokyonight.nvim: colorscheme plugin with high priority so it + loads before most UI; disables italic comments then sets `colorscheme`. + + Rationale + Centralizes theme choice. Swap plugin name + `vim.cmd.colorscheme` here if + you change distributions. + + See `:help colorscheme`, plugin README. +]] + +---@type LazySpec +return { +{ -- You can easily change to a different colorscheme. + -- Change the name of the colorscheme plugin below, and then + -- change the command in the config to whatever the name of that colorscheme is. + -- + -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. + 'folke/tokyonight.nvim', + priority = 1000, -- Make sure to load this before all the other start plugins. + config = function() + ---@diagnostic disable-next-line: missing-fields + require('tokyonight').setup { + styles = { + comments = { italic = false }, -- Disable italics in comments + }, + } + + -- Load the colorscheme here. + -- Like many other themes, this one has different styles, and you could load + -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. + vim.cmd.colorscheme 'tokyonight-night' + end, +}, +} diff --git a/lua/plugins/kickstart/plugins/treesitter.lua b/lua/plugins/kickstart/plugins/treesitter.lua new file mode 100644 index 00000000000..fecd25065f8 --- /dev/null +++ b/lua/plugins/kickstart/plugins/treesitter.lua @@ -0,0 +1,72 @@ +--[[ + Path: lua/plugins/kickstart/plugins/treesitter.lua + Module: plugins.kickstart.plugins.treesitter + + Purpose + Lazy spec for nvim-treesitter: parser install list, `TSUpdate` build step, + highlight/indent toggles, and `lazy = false` so buffers get treesitter early. + + Rationale + Syntax/folds/indent for supported languages; `auto_install` pulls missing + parsers on demand. Ruby keeps vim regex highlighting per upstream note. + + See `:help nvim-treesitter`. +]] + +---@type LazySpec +return { +{ -- Highlight, edit, and navigate code + 'nvim-treesitter/nvim-treesitter', + lazy = false, + build = ':TSUpdate', + main = 'nvim-treesitter.configs', -- Sets main module to use for opts + -- [[ Configure Treesitter ]] See `:help nvim-treesitter` + opts = { + ensure_installed = { + 'bash', + 'c', + 'diff', + 'html', + 'lua', + 'luadoc', + 'markdown', + 'markdown_inline', + 'query', + 'vim', + 'vimdoc', + 'go', + 'gomod', + 'gowork', + 'gosum', + 'rust', + 'python', + 'json', + 'toml', + 'css', + 'helm', + 'dockerfile', + 'bash', + 'yaml', + 'sql', + 'hcl', + 'terraform', + }, + -- Autoinstall languages that are not installed + auto_install = true, + highlight = { + enable = true, + -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. + -- If you are experiencing weird indenting issues, add the language to + -- the list of additional_vim_regex_highlighting and disabled languages for indent. + additional_vim_regex_highlighting = { 'ruby' }, + }, + indent = { enable = true, disable = { 'ruby' } }, + }, + -- There are additional nvim-treesitter modules that you can use to interact + -- with nvim-treesitter. You should go explore a few and see what interests you: + -- + -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` + -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context + -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects +}, +} diff --git a/lua/plugins/kickstart/plugins/vim_helm.lua b/lua/plugins/kickstart/plugins/vim_helm.lua new file mode 100644 index 00000000000..ed8f5402326 --- /dev/null +++ b/lua/plugins/kickstart/plugins/vim_helm.lua @@ -0,0 +1,25 @@ +--[[ + Path: lua/plugins/kickstart/plugins/vim_helm.lua + Module: plugins.kickstart.plugins.vim_helm + + Purpose + Lazy spec for towolf/vim-helm: sets `filetype=helm` on Helm templates so + Treesitter/YAML tooling attach to the correct grammar instead of plain YAML. + + Rationale + Small filetype shim; loaded on `BufReadPre` before heavy YAML LSP hooks run. + + See Helm tooling docs; plugin README. +]] + +---@type LazySpec +return { +{ + 'towolf/vim-helm', + event = 'BufReadPre', + config = function() + -- This plugin automatically detects helm files (including .tpl) + -- and sets the filetype to "helm" instead of "yaml" + end, +}, +} diff --git a/lua/plugins/kickstart/plugins/which_key.lua b/lua/plugins/kickstart/plugins/which_key.lua new file mode 100644 index 00000000000..38c4364004c --- /dev/null +++ b/lua/plugins/kickstart/plugins/which_key.lua @@ -0,0 +1,38 @@ +--[[ + Path: lua/plugins/kickstart/plugins/which_key.lua + Module: plugins.kickstart.plugins.which_key + + Purpose + Lazy spec for which-key.nvim: discoverable pop-up of pending key sequences + and group labels for `` chains (search, toggle, git hunks, LSP). + + Rationale + Loaded on `VimEnter` so it does not delay first screen paint. `spec` entries + document chains used elsewhere (Telescope, gitsigns, LSP maps). + + See `:help which-key.nvim.txt`. +]] + +---@type LazySpec +return { +{ -- Useful plugin to show you pending keybinds. + 'folke/which-key.nvim', + event = 'VimEnter', + ---@module 'which-key' + ---@type wk.Opts + ---@diagnostic disable-next-line: missing-fields + opts = { + -- delay between pressing a key and opening which-key (milliseconds) + delay = 0, + icons = { mappings = vim.g.have_nerd_font }, + + -- Document existing key chains + spec = { + { 's', group = '[S]earch', mode = { 'n', 'v' } }, + { 't', group = '[T]oggle' }, + { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, -- Enable gitsigns recommended keymaps first + { 'gr', group = 'LSP Actions', mode = { 'n' } }, + }, + }, +}, +}