init.lua 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. --[[
  2. =====================================================================
  3. ==================== READ THIS BEFORE CONTINUING ====================
  4. =====================================================================
  5. ======== .-----. ========
  6. ======== .----------------------. | === | ========
  7. ======== |.-""""""""""""""""""-.| |-----| ========
  8. ======== || || | === | ========
  9. ======== || KICKSTART.NVIM || |-----| ========
  10. ======== || || | === | ========
  11. ======== || || |-----| ========
  12. ======== ||:Tutor || |:::::| ========
  13. ======== |'-..................-'| |____o| ========
  14. ======== `"")----------------(""` ___________ ========
  15. ======== /::::::::::| |::::::::::\ \ no mouse \ ========
  16. ======== /:::========| |==hjkl==:::\ \ required \ ========
  17. ======== '""""""""""""' '""""""""""""' '""""""""""' ========
  18. ======== ========
  19. =====================================================================
  20. =====================================================================
  21. What is Kickstart?
  22. Kickstart.nvim is *not* a distribution.
  23. Kickstart.nvim is a starting point for your own configuration.
  24. The goal is that you can read every line of code, top-to-bottom, understand
  25. what your configuration is doing, and modify it to suit your needs.
  26. Once you've done that, you can start exploring, configuring and tinkering to
  27. make Neovim your own! That might mean leaving kickstart just the way it is for a while
  28. or immediately breaking it into modular pieces. It's up to you!
  29. If you don't know anything about Lua, I recommend taking some time to read through
  30. a guide. One possible example which will only take 10-15 minutes:
  31. - https://learnxinyminutes.com/docs/lua/
  32. After understanding a bit more about Lua, you can use `:help lua-guide` as a
  33. reference for how Neovim integrates Lua.
  34. - :help lua-guide
  35. - (or HTML version): https://neovim.io/doc/user/lua-guide.html
  36. Kickstart Guide:
  37. TODO: The very first thing you should do is to run the command `:Tutor` in Neovim.
  38. If you don't know what this means, type the following:
  39. - <escape key>
  40. - :
  41. - Tutor
  42. - <enter key>
  43. (If you already know how the Neovim basics, you can skip this step)
  44. Once you've completed that, you can continue working through **AND READING** the rest
  45. of the kickstart init.lua
  46. Next, run AND READ `:help`.
  47. This will open up a help window with some basic information
  48. about reading, navigating and searching the builtin help documentation.
  49. This should be the first place you go to look when you're stuck or confused
  50. with something. It's one of my favorite neovim features.
  51. MOST IMPORTANTLY, we provide a keymap "<space>sh" to [s]earch the [h]elp documentation,
  52. which is very useful when you're not sure exactly what you're looking for.
  53. I have left several `:help X` comments throughout the init.lua
  54. These are hints about where to find more information about the relevant settings,
  55. plugins or neovim features used in kickstart.
  56. NOTE: Look for lines like this
  57. Throughout the file. These are for you, the reader, to help understand what is happening.
  58. Feel free to delete them once you know what you're doing, but they should serve as a guide
  59. for when you are first encountering a few different constructs in your nvim config.
  60. If you experience any errors while trying to install kickstart, run `:checkhealth` for more info
  61. I hope you enjoy your Neovim journey,
  62. - TJ
  63. P.S. You can delete this when you're done too. It's your config now! :)
  64. --]]
  65. -- Set <space> as the leader key
  66. -- See `:help mapleader`
  67. -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
  68. vim.g.mapleader = ' '
  69. vim.g.maplocalleader = ' '
  70. -- [[ Setting options ]]
  71. -- See `:help vim.opt`
  72. -- NOTE: You can change these options as you wish!
  73. -- For more options, you can see `:help option-list`
  74. -- Make line numbers default
  75. vim.opt.number = true
  76. -- You can also add relative line numbers, for help with jumping.
  77. -- Experiment for yourself to see if you like it!
  78. -- vim.opt.relativenumber = true
  79. -- Enable mouse mode, can be useful for resizing splits for example!
  80. vim.opt.mouse = 'a'
  81. -- Don't show the mode, since it's already in status line
  82. vim.opt.showmode = false
  83. -- Sync clipboard between OS and Neovim.
  84. -- Remove this option if you want your OS clipboard to remain independent.
  85. -- See `:help 'clipboard'`
  86. vim.opt.clipboard = 'unnamedplus'
  87. -- Enable break indent
  88. vim.opt.breakindent = true
  89. -- Save undo history
  90. vim.opt.undofile = true
  91. -- Case-insensitive searching UNLESS \C or capital in search
  92. vim.opt.ignorecase = true
  93. vim.opt.smartcase = true
  94. -- Keep signcolumn on by default
  95. vim.opt.signcolumn = 'yes'
  96. -- Decrease update time
  97. vim.opt.updatetime = 250
  98. vim.opt.timeoutlen = 300
  99. -- Configure how new splits should be opened
  100. vim.opt.splitright = true
  101. vim.opt.splitbelow = true
  102. -- Sets how neovim will display certain whitespace in the editor.
  103. -- See `:help 'list'`
  104. -- and `:help 'listchars'`
  105. vim.opt.list = true
  106. vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' }
  107. -- Preview substitutions live, as you type!
  108. vim.opt.inccommand = 'split'
  109. -- Show which line your cursor is on
  110. vim.opt.cursorline = true
  111. -- Minimal number of screen lines to keep above and below the cursor.
  112. vim.opt.scrolloff = 10
  113. -- [[ Basic Keymaps ]]
  114. -- See `:help vim.keymap.set()`
  115. -- Set highlight on search, but clear on pressing <Esc> in normal mode
  116. vim.opt.hlsearch = true
  117. vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
  118. -- Diagnostic keymaps
  119. vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' })
  120. vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
  121. vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' })
  122. vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
  123. -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
  124. -- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
  125. -- is not what someone will guess without a bit more experience.
  126. --
  127. -- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
  128. -- or just use <C-\><C-n> to exit terminal mode
  129. vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
  130. -- TIP: Disable arrow keys in normal mode
  131. -- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
  132. -- vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
  133. -- vim.keymap.set('n', '<up>', '<cmd>echo "Use k to move!!"<CR>')
  134. -- vim.keymap.set('n', '<down>', '<cmd>echo "Use j to move!!"<CR>')
  135. -- Keybinds to make split navigation easier.
  136. -- Use CTRL+<hjkl> to switch between windows
  137. --
  138. -- See `:help wincmd` for a list of all window commands
  139. vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
  140. vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
  141. vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
  142. vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
  143. -- [[ Basic Autocommands ]]
  144. -- See `:help lua-guide-autocommands`
  145. -- Highlight when yanking (copying) text
  146. -- Try it with `yap` in normal mode
  147. -- See `:help vim.highlight.on_yank()`
  148. vim.api.nvim_create_autocmd('TextYankPost', {
  149. desc = 'Highlight when yanking (copying) text',
  150. group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
  151. callback = function()
  152. vim.highlight.on_yank()
  153. end,
  154. })
  155. -- [[ Install `lazy.nvim` plugin manager ]]
  156. -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
  157. local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
  158. if not vim.loop.fs_stat(lazypath) then
  159. local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
  160. vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }
  161. end ---@diagnostic disable-next-line: undefined-field
  162. vim.opt.rtp:prepend(lazypath)
  163. -- [[ Configure and install plugins ]]
  164. --
  165. -- To check the current status of your plugins, run
  166. -- :Lazy
  167. --
  168. -- You can press `?` in this menu for help. Use `:q` to close the window
  169. --
  170. -- To update plugins, you can run
  171. -- :Lazy update
  172. --
  173. -- NOTE: Here is where you install your plugins.
  174. require('lazy').setup {
  175. -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
  176. 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically
  177. -- NOTE: Plugins can also be added by using a table,
  178. -- with the first argument being the link and the following
  179. -- keys can be used to configure plugin behavior/loading/etc.
  180. --
  181. -- Use `opts = {}` to force a plugin to be loaded.
  182. --
  183. -- This is equivalent to:
  184. -- require('Comment').setup({})
  185. -- "gc" to comment visual regions/lines
  186. { 'numToStr/Comment.nvim', opts = {} },
  187. -- Here is a more advanced example where we pass configuration
  188. -- options to `gitsigns.nvim`. This is equivalent to the following lua:
  189. -- require('gitsigns').setup({ ... })
  190. --
  191. -- See `:help gitsigns` to understand what the configuration keys do
  192. { -- Adds git related signs to the gutter, as well as utilities for managing changes
  193. 'lewis6991/gitsigns.nvim',
  194. opts = {
  195. signs = {
  196. add = { text = '+' },
  197. change = { text = '~' },
  198. delete = { text = '_' },
  199. topdelete = { text = '‾' },
  200. changedelete = { text = '~' },
  201. },
  202. },
  203. },
  204. -- NOTE: Plugins can also be configured to run lua code when they are loaded.
  205. --
  206. -- This is often very useful to both group configuration, as well as handle
  207. -- lazy loading plugins that don't need to be loaded immediately at startup.
  208. --
  209. -- For example, in the following configuration, we use:
  210. -- event = 'VimEnter'
  211. --
  212. -- which loads which-key before all the UI elements are loaded. Events can be
  213. -- normal autocommands events (`:help autocmd-events`).
  214. --
  215. -- Then, because we use the `config` key, the configuration only runs
  216. -- after the plugin has been loaded:
  217. -- config = function() ... end
  218. { -- Useful plugin to show you pending keybinds.
  219. 'folke/which-key.nvim',
  220. event = 'VimEnter', -- Sets the loading event to 'VimEnter'
  221. config = function() -- This is the function that runs, AFTER loading
  222. require('which-key').setup()
  223. -- Document existing key chains
  224. require('which-key').register {
  225. ['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
  226. ['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
  227. ['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
  228. ['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
  229. ['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
  230. }
  231. end,
  232. },
  233. -- NOTE: Plugins can specify dependencies.
  234. --
  235. -- The dependencies are proper plugin specifications as well - anything
  236. -- you do for a plugin at the top level, you can do for a dependency.
  237. --
  238. -- Use the `dependencies` key to specify the dependencies of a particular plugin
  239. { -- Fuzzy Finder (files, lsp, etc)
  240. 'nvim-telescope/telescope.nvim',
  241. event = 'VimEnter',
  242. branch = '0.1.x',
  243. dependencies = {
  244. 'nvim-lua/plenary.nvim',
  245. { -- If encountering errors, see telescope-fzf-native README for install instructions
  246. 'nvim-telescope/telescope-fzf-native.nvim',
  247. -- `build` is used to run some command when the plugin is installed/updated.
  248. -- This is only run then, not every time Neovim starts up.
  249. build = 'make',
  250. -- `cond` is a condition used to determine whether this plugin should be
  251. -- installed and loaded.
  252. cond = function()
  253. return vim.fn.executable 'make' == 1
  254. end,
  255. },
  256. { 'nvim-telescope/telescope-ui-select.nvim' },
  257. -- Useful for getting pretty icons, but requires special font.
  258. -- If you already have a Nerd Font, or terminal set up with fallback fonts
  259. -- you can enable this
  260. -- { 'nvim-tree/nvim-web-devicons' }
  261. },
  262. config = function()
  263. -- Telescope is a fuzzy finder that comes with a lot of different things that
  264. -- it can fuzzy find! It's more than just a "file finder", it can search
  265. -- many different aspects of Neovim, your workspace, LSP, and more!
  266. --
  267. -- The easiest way to use telescope, is to start by doing something like:
  268. -- :Telescope help_tags
  269. --
  270. -- After running this command, a window will open up and you're able to
  271. -- type in the prompt window. You'll see a list of help_tags options and
  272. -- a corresponding preview of the help.
  273. --
  274. -- Two important keymaps to use while in telescope are:
  275. -- - Insert mode: <c-/>
  276. -- - Normal mode: ?
  277. --
  278. -- This opens a window that shows you all of the keymaps for the current
  279. -- telescope picker. This is really useful to discover what Telescope can
  280. -- do as well as how to actually do it!
  281. -- [[ Configure Telescope ]]
  282. -- See `:help telescope` and `:help telescope.setup()`
  283. require('telescope').setup {
  284. -- You can put your default mappings / updates / etc. in here
  285. -- All the info you're looking for is in `:help telescope.setup()`
  286. --
  287. -- defaults = {
  288. -- mappings = {
  289. -- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
  290. -- },
  291. -- },
  292. -- pickers = {}
  293. extensions = {
  294. ['ui-select'] = {
  295. require('telescope.themes').get_dropdown(),
  296. },
  297. },
  298. }
  299. -- Enable telescope extensions, if they are installed
  300. pcall(require('telescope').load_extension, 'fzf')
  301. pcall(require('telescope').load_extension, 'ui-select')
  302. -- See `:help telescope.builtin`
  303. local builtin = require 'telescope.builtin'
  304. vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
  305. vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' })
  306. vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' })
  307. vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' })
  308. vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
  309. vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
  310. vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
  311. vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
  312. vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
  313. vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
  314. -- Slightly advanced example of overriding default behavior and theme
  315. vim.keymap.set('n', '<leader>/', function()
  316. -- You can pass additional configuration to telescope to change theme, layout, etc.
  317. builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
  318. winblend = 10,
  319. previewer = false,
  320. })
  321. end, { desc = '[/] Fuzzily search in current buffer' })
  322. -- Also possible to pass additional configuration options.
  323. -- See `:help telescope.builtin.live_grep()` for information about particular keys
  324. vim.keymap.set('n', '<leader>s/', function()
  325. builtin.live_grep {
  326. grep_open_files = true,
  327. prompt_title = 'Live Grep in Open Files',
  328. }
  329. end, { desc = '[S]earch [/] in Open Files' })
  330. -- Shortcut for searching your neovim configuration files
  331. vim.keymap.set('n', '<leader>sn', function()
  332. builtin.find_files { cwd = vim.fn.stdpath 'config' }
  333. end, { desc = '[S]earch [N]eovim files' })
  334. end,
  335. },
  336. { -- LSP Configuration & Plugins
  337. 'neovim/nvim-lspconfig',
  338. dependencies = {
  339. -- Automatically install LSPs and related tools to stdpath for neovim
  340. 'williamboman/mason.nvim',
  341. 'williamboman/mason-lspconfig.nvim',
  342. 'WhoIsSethDaniel/mason-tool-installer.nvim',
  343. -- Useful status updates for LSP.
  344. -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
  345. { 'j-hui/fidget.nvim', opts = {} },
  346. },
  347. config = function()
  348. -- Brief Aside: **What is LSP?**
  349. --
  350. -- LSP is an acronym you've probably heard, but might not understand what it is.
  351. --
  352. -- LSP stands for Language Server Protocol. It's a protocol that helps editors
  353. -- and language tooling communicate in a standardized fashion.
  354. --
  355. -- In general, you have a "server" which is some tool built to understand a particular
  356. -- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc). These Language Servers
  357. -- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone
  358. -- processes that communicate with some "client" - in this case, Neovim!
  359. --
  360. -- LSP provides Neovim with features like:
  361. -- - Go to definition
  362. -- - Find references
  363. -- - Autocompletion
  364. -- - Symbol Search
  365. -- - and more!
  366. --
  367. -- Thus, Language Servers are external tools that must be installed separately from
  368. -- Neovim. This is where `mason` and related plugins come into play.
  369. --
  370. -- If you're wondering about lsp vs treesitter, you can check out the wonderfully
  371. -- and elegantly composed help section, `:help lsp-vs-treesitter`
  372. -- This function gets run when an LSP attaches to a particular buffer.
  373. -- That is to say, every time a new file is opened that is associated with
  374. -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
  375. -- function will be executed to configure the current buffer
  376. vim.api.nvim_create_autocmd('LspAttach', {
  377. group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
  378. callback = function(event)
  379. -- NOTE: Remember that lua is a real programming language, and as such it is possible
  380. -- to define small helper and utility functions so you don't have to repeat yourself
  381. -- many times.
  382. --
  383. -- In this case, we create a function that lets us more easily define mappings specific
  384. -- for LSP related items. It sets the mode, buffer and description for us each time.
  385. local map = function(keys, func, desc)
  386. vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
  387. end
  388. -- Jump to the definition of the word under your cursor.
  389. -- This is where a variable was first declared, or where a function is defined, etc.
  390. -- To jump back, press <C-T>.
  391. map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
  392. -- Find references for the word under your cursor.
  393. map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
  394. -- Jump to the implementation of the word under your cursor.
  395. -- Useful when your language has ways of declaring types without an actual implementation.
  396. map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
  397. -- Jump to the type of the word under your cursor.
  398. -- Useful when you're not sure what type a variable is and you want to see
  399. -- the definition of its *type*, not where it was *defined*.
  400. map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
  401. -- Fuzzy find all the symbols in your current document.
  402. -- Symbols are things like variables, functions, types, etc.
  403. map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
  404. -- Fuzzy find all the symbols in your current workspace
  405. -- Similar to document symbols, except searches over your whole project.
  406. map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
  407. -- Rename the variable under your cursor
  408. -- Most Language Servers support renaming across files, etc.
  409. map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
  410. -- Execute a code action, usually your cursor needs to be on top of an error
  411. -- or a suggestion from your LSP for this to activate.
  412. map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
  413. -- Opens a popup that displays documentation about the word under your cursor
  414. -- See `:help K` for why this keymap
  415. map('K', vim.lsp.buf.hover, 'Hover Documentation')
  416. -- WARN: This is not Goto Definition, this is Goto Declaration.
  417. -- For example, in C this would take you to the header
  418. map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
  419. -- The following two autocommands are used to highlight references of the
  420. -- word under your cursor when your cursor rests there for a little while.
  421. -- See `:help CursorHold` for information about when this is executed
  422. --
  423. -- When you move your cursor, the highlights will be cleared (the second autocommand).
  424. local client = vim.lsp.get_client_by_id(event.data.client_id)
  425. if client and client.server_capabilities.documentHighlightProvider then
  426. vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
  427. buffer = event.buf,
  428. callback = vim.lsp.buf.document_highlight,
  429. })
  430. vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
  431. buffer = event.buf,
  432. callback = vim.lsp.buf.clear_references,
  433. })
  434. end
  435. end,
  436. })
  437. -- LSP servers and clients are able to communicate to each other what features they support.
  438. -- By default, Neovim doesn't support everything that is in the LSP Specification.
  439. -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
  440. -- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
  441. local capabilities = vim.lsp.protocol.make_client_capabilities()
  442. capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
  443. -- Enable the following language servers
  444. -- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
  445. --
  446. -- Add any additional override configuration in the following tables. Available keys are:
  447. -- - cmd (table): Override the default command used to start the server
  448. -- - filetypes (table): Override the default list of associated filetypes for the server
  449. -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
  450. -- - settings (table): Override the default settings passed when initializing the server.
  451. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
  452. local servers = {
  453. -- clangd = {},
  454. -- gopls = {},
  455. -- pyright = {},
  456. -- rust_analyzer = {},
  457. -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
  458. --
  459. -- Some languages (like typescript) have entire language plugins that can be useful:
  460. -- https://github.com/pmizio/typescript-tools.nvim
  461. --
  462. -- But for many setups, the LSP (`tsserver`) will work just fine
  463. -- tsserver = {},
  464. --
  465. lua_ls = {
  466. -- cmd = {...},
  467. -- filetypes { ...},
  468. -- capabilities = {},
  469. settings = {
  470. Lua = {
  471. runtime = { version = 'LuaJIT' },
  472. workspace = {
  473. checkThirdParty = false,
  474. -- Tells lua_ls where to find all the Lua files that you have loaded
  475. -- for your neovim configuration.
  476. library = {
  477. '${3rd}/luv/library',
  478. unpack(vim.api.nvim_get_runtime_file('', true)),
  479. },
  480. -- If lua_ls is really slow on your computer, you can try this instead:
  481. -- library = { vim.env.VIMRUNTIME },
  482. },
  483. completion = {
  484. callSnippet = 'Replace',
  485. },
  486. -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
  487. -- diagnostics = { disable = { 'missing-fields' } },
  488. },
  489. },
  490. },
  491. }
  492. -- Ensure the servers and tools above are installed
  493. -- To check the current status of installed tools and/or manually install
  494. -- other tools, you can run
  495. -- :Mason
  496. --
  497. -- You can press `g?` for help in this menu
  498. require('mason').setup()
  499. -- You can add other tools here that you want Mason to install
  500. -- for you, so that they are available from within Neovim.
  501. local ensure_installed = vim.tbl_keys(servers or {})
  502. vim.list_extend(ensure_installed, {
  503. 'stylua', -- Used to format lua code
  504. })
  505. require('mason-tool-installer').setup { ensure_installed = ensure_installed }
  506. require('mason-lspconfig').setup {
  507. handlers = {
  508. function(server_name)
  509. local server = servers[server_name] or {}
  510. -- This handles overriding only values explicitly passed
  511. -- by the server configuration above. Useful when disabling
  512. -- certain features of an LSP (for example, turning off formatting for tsserver)
  513. server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
  514. require('lspconfig')[server_name].setup(server)
  515. end,
  516. },
  517. }
  518. end,
  519. },
  520. { -- Autoformat
  521. 'stevearc/conform.nvim',
  522. opts = {
  523. notify_on_error = false,
  524. format_on_save = {
  525. timeout_ms = 500,
  526. lsp_fallback = true,
  527. },
  528. formatters_by_ft = {
  529. lua = { 'stylua' },
  530. -- Conform can also run multiple formatters sequentially
  531. -- python = { "isort", "black" },
  532. --
  533. -- You can use a sub-list to tell conform to run *until* a formatter
  534. -- is found.
  535. -- javascript = { { "prettierd", "prettier" } },
  536. },
  537. },
  538. },
  539. { -- Autocompletion
  540. 'hrsh7th/nvim-cmp',
  541. event = 'InsertEnter',
  542. dependencies = {
  543. -- Snippet Engine & its associated nvim-cmp source
  544. {
  545. 'L3MON4D3/LuaSnip',
  546. build = (function()
  547. -- Build Step is needed for regex support in snippets
  548. -- This step is not supported in many windows environments
  549. -- Remove the below condition to re-enable on windows
  550. if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
  551. return
  552. end
  553. return 'make install_jsregexp'
  554. end)(),
  555. },
  556. 'saadparwaiz1/cmp_luasnip',
  557. -- Adds other completion capabilities.
  558. -- nvim-cmp does not ship with all sources by default. They are split
  559. -- into multiple repos for maintenance purposes.
  560. 'hrsh7th/cmp-nvim-lsp',
  561. 'hrsh7th/cmp-path',
  562. -- If you want to add a bunch of pre-configured snippets,
  563. -- you can use this plugin to help you. It even has snippets
  564. -- for various frameworks/libraries/etc. but you will have to
  565. -- set up the ones that are useful for you.
  566. -- 'rafamadriz/friendly-snippets',
  567. },
  568. config = function()
  569. -- See `:help cmp`
  570. local cmp = require 'cmp'
  571. local luasnip = require 'luasnip'
  572. luasnip.config.setup {}
  573. cmp.setup {
  574. snippet = {
  575. expand = function(args)
  576. luasnip.lsp_expand(args.body)
  577. end,
  578. },
  579. completion = { completeopt = 'menu,menuone,noinsert' },
  580. -- For an understanding of why these mappings were
  581. -- chosen, you will need to read `:help ins-completion`
  582. --
  583. -- No, but seriously. Please read `:help ins-completion`, it is really good!
  584. mapping = cmp.mapping.preset.insert {
  585. -- Select the [n]ext item
  586. ['<C-n>'] = cmp.mapping.select_next_item(),
  587. -- Select the [p]revious item
  588. ['<C-p>'] = cmp.mapping.select_prev_item(),
  589. -- Accept ([y]es) the completion.
  590. -- This will auto-import if your LSP supports it.
  591. -- This will expand snippets if the LSP sent a snippet.
  592. ['<C-y>'] = cmp.mapping.confirm { select = true },
  593. -- Manually trigger a completion from nvim-cmp.
  594. -- Generally you don't need this, because nvim-cmp will display
  595. -- completions whenever it has completion options available.
  596. ['<C-Space>'] = cmp.mapping.complete {},
  597. -- Think of <c-l> as moving to the right of your snippet expansion.
  598. -- So if you have a snippet that's like:
  599. -- function $name($args)
  600. -- $body
  601. -- end
  602. --
  603. -- <c-l> will move you to the right of each of the expansion locations.
  604. -- <c-h> is similar, except moving you backwards.
  605. ['<C-l>'] = cmp.mapping(function()
  606. if luasnip.expand_or_locally_jumpable() then
  607. luasnip.expand_or_jump()
  608. end
  609. end, { 'i', 's' }),
  610. ['<C-h>'] = cmp.mapping(function()
  611. if luasnip.locally_jumpable(-1) then
  612. luasnip.jump(-1)
  613. end
  614. end, { 'i', 's' }),
  615. },
  616. sources = {
  617. { name = 'nvim_lsp' },
  618. { name = 'luasnip' },
  619. { name = 'path' },
  620. },
  621. }
  622. end,
  623. },
  624. { -- You can easily change to a different colorscheme.
  625. -- Change the name of the colorscheme plugin below, and then
  626. -- change the command in the config to whatever the name of that colorscheme is
  627. --
  628. -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`
  629. 'folke/tokyonight.nvim',
  630. lazy = false, -- make sure we load this during startup if it is your main colorscheme
  631. priority = 1000, -- make sure to load this before all the other start plugins
  632. config = function()
  633. -- Load the colorscheme here
  634. vim.cmd.colorscheme 'tokyonight-night'
  635. -- You can configure highlights by doing something like
  636. vim.cmd.hi 'Comment gui=none'
  637. end,
  638. },
  639. -- Highlight todo, notes, etc in comments
  640. { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } },
  641. { -- Collection of various small independent plugins/modules
  642. 'echasnovski/mini.nvim',
  643. config = function()
  644. -- Better Around/Inside textobjects
  645. --
  646. -- Examples:
  647. -- - va) - [V]isually select [A]round [)]paren
  648. -- - yinq - [Y]ank [I]nside [N]ext [']quote
  649. -- - ci' - [C]hange [I]nside [']quote
  650. require('mini.ai').setup { n_lines = 500 }
  651. -- Add/delete/replace surroundings (brackets, quotes, etc.)
  652. --
  653. -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren
  654. -- - sd' - [S]urround [D]elete [']quotes
  655. -- - sr)' - [S]urround [R]eplace [)] [']
  656. require('mini.surround').setup()
  657. -- Simple and easy statusline.
  658. -- You could remove this setup call if you don't like it,
  659. -- and try some other statusline plugin
  660. local statusline = require 'mini.statusline'
  661. statusline.setup()
  662. -- You can configure sections in the statusline by overriding their
  663. -- default behavior. For example, here we disable the section for
  664. -- cursor information because line numbers are already enabled
  665. ---@diagnostic disable-next-line: duplicate-set-field
  666. statusline.section_location = function()
  667. return ''
  668. end
  669. -- ... and there is more!
  670. -- Check out: https://github.com/echasnovski/mini.nvim
  671. end,
  672. },
  673. { -- Highlight, edit, and navigate code
  674. 'nvim-treesitter/nvim-treesitter',
  675. build = ':TSUpdate',
  676. config = function()
  677. -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
  678. ---@diagnostic disable-next-line: missing-fields
  679. require('nvim-treesitter.configs').setup {
  680. ensure_installed = { 'bash', 'c', 'html', 'lua', 'markdown', 'vim', 'vimdoc' },
  681. -- Autoinstall languages that are not installed
  682. auto_install = true,
  683. highlight = { enable = true },
  684. indent = { enable = true },
  685. }
  686. -- There are additional nvim-treesitter modules that you can use to interact
  687. -- with nvim-treesitter. You should go explore a few and see what interests you:
  688. --
  689. -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
  690. -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
  691. -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
  692. end,
  693. },
  694. -- The following two comments only work if you have downloaded the kickstart repo, not just copy pasted the
  695. -- init.lua. If you want these files, they are in the repository, so you can just download them and
  696. -- put them in the right spots if you want.
  697. -- NOTE: Next step on your Neovim journey: Add/Configure additional plugins for kickstart
  698. --
  699. -- Here are some example plugins that I've included in the kickstart repository.
  700. -- Uncomment any of the lines below to enable them (you will need to restart nvim).
  701. --
  702. -- require 'kickstart.plugins.debug',
  703. -- require 'kickstart.plugins.indent_line',
  704. -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
  705. -- This is the easiest way to modularize your config.
  706. --
  707. -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
  708. -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins`
  709. -- { import = 'custom.plugins' },
  710. }
  711. -- The line beneath this is called `modeline`. See `:help modeline`
  712. -- vim: ts=2 sts=2 sw=2 et