init.lua 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. -- Set <space> as the leader key
  2. -- See `:help mapleader`
  3. -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
  4. vim.g.mapleader = ' '
  5. vim.g.maplocalleader = '\\'
  6. -- Set to true if you have a Nerd Font installed and selected in the terminal
  7. vim.g.have_nerd_font = true
  8. -- [[ Setting options ]]
  9. -- See `:help vim.o`
  10. -- NOTE: You can change these options as you wish!
  11. -- For more options, you can see `:help option-list`
  12. -- Set shiftwidth and tabstop
  13. vim.o.tabstop = 4
  14. vim.o.shiftwidth = 4
  15. vim.o.expandtab = true
  16. -- Make line numbers default
  17. vim.o.number = true
  18. -- You can also add relative line numbers, to help with jumping.
  19. -- Experiment for yourself to see if you like it!
  20. vim.o.relativenumber = true
  21. -- Enable mouse mode, can be useful for resizing splits for example!
  22. vim.o.mouse = 'a'
  23. -- Don't show the mode, since it's already in the status line
  24. vim.o.showmode = false
  25. -- Sync clipboard between OS and Neovim.
  26. -- Schedule the setting after `UiEnter` because it can increase startup-time.
  27. -- Remove this option if you want your OS clipboard to remain independent.
  28. -- See `:help 'clipboard'`
  29. vim.schedule(function()
  30. vim.o.clipboard = 'unnamedplus'
  31. end)
  32. -- Enable break indent
  33. vim.o.breakindent = true
  34. -- Save undo history
  35. vim.o.undofile = true
  36. -- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
  37. vim.o.ignorecase = true
  38. vim.o.smartcase = true
  39. -- Keep signcolumn on by default
  40. vim.o.signcolumn = 'yes'
  41. -- Decrease update time
  42. vim.o.updatetime = 250
  43. -- Decrease mapped sequence wait time
  44. vim.o.timeoutlen = 300
  45. -- Configure how new splits should be opened
  46. vim.o.splitright = true
  47. vim.o.splitbelow = true
  48. -- Wrap lines longer than 80 chars
  49. vim.o.textwidth = 80
  50. -- Sets how neovim will display certain whitespace characters in the editor.
  51. -- See `:help 'list'`
  52. -- and `:help 'listchars'`
  53. --
  54. -- Notice listchars is set using `vim.opt` instead of `vim.o`.
  55. -- It is very similar to `vim.o` but offers an interface for conveniently interacting with tables.
  56. -- See `:help lua-options`
  57. -- and `:help lua-options-guide`
  58. vim.o.list = true
  59. vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' }
  60. -- Preview substitutions live, as you type!
  61. vim.o.inccommand = 'split'
  62. -- Show which line your cursor is on
  63. vim.o.cursorline = true
  64. -- Minimal number of screen lines to keep above and below the cursor.
  65. vim.o.scrolloff = 10
  66. -- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`),
  67. -- instead raise a dialog asking if you wish to save the current file(s)
  68. -- See `:help 'confirm'`
  69. vim.o.confirm = true
  70. vim.o.cc = "80"
  71. -- [[ Basic Keymaps ]]
  72. -- See `:help vim.keymap.set()`
  73. -- Clear highlights on search when pressing <Esc> in normal mode
  74. -- See `:help hlsearch`
  75. vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
  76. -- Diagnostic keymaps
  77. vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
  78. -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
  79. -- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
  80. -- is not what someone will guess without a bit more experience.
  81. --
  82. -- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
  83. -- or just use <C-\><C-n> to exit terminal mode
  84. vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
  85. -- TIP: Disable arrow keys in normal mode
  86. -- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
  87. -- vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
  88. -- vim.keymap.set('n', '<up>', '<cmd>echo "Use k to move!!"<CR>')
  89. -- vim.keymap.set('n', '<down>', '<cmd>echo "Use j to move!!"<CR>')
  90. -- Keybinds to make split navigation easier.
  91. -- Use CTRL+<hjkl> to switch between windows
  92. --
  93. -- See `:help wincmd` for a list of all window commands
  94. vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
  95. vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
  96. vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
  97. vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
  98. -- NOTE: Some terminals have colliding keymaps or are not able to send distinct keycodes
  99. -- vim.keymap.set("n", "<C-S-h>", "<C-w>H", { desc = "Move window to the left" })
  100. -- vim.keymap.set("n", "<C-S-l>", "<C-w>L", { desc = "Move window to the right" })
  101. -- vim.keymap.set("n", "<C-S-j>", "<C-w>J", { desc = "Move window to the lower" })
  102. -- vim.keymap.set("n", "<C-S-k>", "<C-w>K", { desc = "Move window to the upper" })
  103. -- Use j and k to go up and down within the same line
  104. vim.keymap.set({ 'n', 'v' }, 'j', 'gj')
  105. vim.keymap.set({ 'n', 'v' }, 'k', 'gk')
  106. -- [[ Basic Autocommands ]]
  107. -- See `:help lua-guide-autocommands`
  108. -- Highlight when yanking (copying) text
  109. -- Try it with `yap` in normal mode
  110. -- See `:help vim.hl.on_yank()`
  111. vim.api.nvim_create_autocmd('TextYankPost', {
  112. desc = 'Highlight when yanking (copying) text',
  113. group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
  114. callback = function()
  115. vim.hl.on_yank()
  116. end,
  117. })
  118. -- [[ Install `lazy.nvim` plugin manager ]]
  119. -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
  120. local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
  121. if not (vim.uv or vim.loop).fs_stat(lazypath) then
  122. local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
  123. local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }
  124. if vim.v.shell_error ~= 0 then
  125. error('Error cloning lazy.nvim:\n' .. out)
  126. end
  127. end
  128. ---@type vim.Option
  129. local rtp = vim.opt.rtp
  130. rtp:prepend(lazypath)
  131. -- [[ Configure and install plugins ]]
  132. --
  133. -- To check the current status of your plugins, run
  134. -- :Lazy
  135. --
  136. -- You can press `?` in this menu for help. Use `:q` to close the window
  137. --
  138. -- To update plugins you can run
  139. -- :Lazy update
  140. --
  141. -- NOTE: Here is where you install your plugins.
  142. require('lazy').setup({
  143. -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
  144. 'NMAC427/guess-indent.nvim', -- Detect tabstop and shiftwidth automatically
  145. -- NOTE: Plugins can also be added by using a table,
  146. -- with the first argument being the link and the following
  147. -- keys can be used to configure plugin behavior/loading/etc.
  148. --
  149. -- Use `opts = {}` to automatically pass options to a plugin's `setup()` function, forcing the plugin to be loaded.
  150. --
  151. -- Alternatively, use `config = function() ... end` for full control over the configuration.
  152. -- If you prefer to call `setup` explicitly, use:
  153. -- {
  154. -- 'lewis6991/gitsigns.nvim',
  155. -- config = function()
  156. -- require('gitsigns').setup({
  157. -- -- Your gitsigns configuration here
  158. -- })
  159. -- end,
  160. -- }
  161. --
  162. -- Here is a more advanced example where we pass configuration
  163. -- options to `gitsigns.nvim`.
  164. --
  165. -- See `:help gitsigns` to understand what the configuration keys do
  166. { -- Adds git related signs to the gutter, as well as utilities for managing changes
  167. 'lewis6991/gitsigns.nvim',
  168. opts = {
  169. signs = {
  170. add = { text = '+' },
  171. change = { text = '~' },
  172. delete = { text = '_' },
  173. topdelete = { text = '‾' },
  174. changedelete = { text = '~' },
  175. },
  176. },
  177. },
  178. -- NOTE: Plugins can also be configured to run Lua code when they are loaded.
  179. --
  180. -- This is often very useful to both group configuration, as well as handle
  181. -- lazy loading plugins that don't need to be loaded immediately at startup.
  182. --
  183. -- For example, in the following configuration, we use:
  184. -- event = 'VimEnter'
  185. --
  186. -- which loads which-key before all the UI elements are loaded. Events can be
  187. -- normal autocommands events (`:help autocmd-events`).
  188. --
  189. -- Then, because we use the `opts` key (recommended), the configuration runs
  190. -- after the plugin has been loaded as `require(MODULE).setup(opts)`.
  191. { -- Useful plugin to show you pending keybinds.
  192. 'folke/which-key.nvim',
  193. event = 'VimEnter', -- Sets the loading event to 'VimEnter'
  194. opts = {
  195. -- delay between pressing a key and opening which-key (milliseconds)
  196. -- this setting is independent of vim.o.timeoutlen
  197. delay = 0,
  198. icons = {
  199. -- set icon mappings to true if you have a Nerd Font
  200. mappings = vim.g.have_nerd_font,
  201. -- If you are using a Nerd Font: set icons.keys to an empty table which will use the
  202. -- default which-key.nvim defined Nerd Font icons, otherwise define a string table
  203. keys = vim.g.have_nerd_font and {} or {
  204. Up = '<Up> ',
  205. Down = '<Down> ',
  206. Left = '<Left> ',
  207. Right = '<Right> ',
  208. C = '<C-…> ',
  209. M = '<M-…> ',
  210. D = '<D-…> ',
  211. S = '<S-…> ',
  212. CR = '<CR> ',
  213. Esc = '<Esc> ',
  214. ScrollWheelDown = '<ScrollWheelDown> ',
  215. ScrollWheelUp = '<ScrollWheelUp> ',
  216. NL = '<NL> ',
  217. BS = '<BS> ',
  218. Space = '<Space> ',
  219. Tab = '<Tab> ',
  220. F1 = '<F1>',
  221. F2 = '<F2>',
  222. F3 = '<F3>',
  223. F4 = '<F4>',
  224. F5 = '<F5>',
  225. F6 = '<F6>',
  226. F7 = '<F7>',
  227. F8 = '<F8>',
  228. F9 = '<F9>',
  229. F10 = '<F10>',
  230. F11 = '<F11>',
  231. F12 = '<F12>',
  232. },
  233. },
  234. -- Document existing key chains
  235. spec = {
  236. { '<leader>s', group = '[S]earch' },
  237. { '<leader>t', group = '[T]oggle' },
  238. { '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
  239. },
  240. },
  241. },
  242. -- NOTE: Plugins can specify dependencies.
  243. --
  244. -- The dependencies are proper plugin specifications as well - anything
  245. -- you do for a plugin at the top level, you can do for a dependency.
  246. --
  247. -- Use the `dependencies` key to specify the dependencies of a particular plugin
  248. { -- Fuzzy Finder (files, lsp, etc)
  249. 'nvim-telescope/telescope.nvim',
  250. event = 'VimEnter',
  251. dependencies = {
  252. 'nvim-lua/plenary.nvim',
  253. { -- If encountering errors, see telescope-fzf-native README for installation instructions
  254. 'nvim-telescope/telescope-fzf-native.nvim',
  255. -- `build` is used to run some command when the plugin is installed/updated.
  256. -- This is only run then, not every time Neovim starts up.
  257. build = 'make',
  258. -- `cond` is a condition used to determine whether this plugin should be
  259. -- installed and loaded.
  260. cond = function()
  261. return vim.fn.executable 'make' == 1
  262. end,
  263. },
  264. { 'nvim-telescope/telescope-ui-select.nvim' },
  265. -- Useful for getting pretty icons, but requires a Nerd Font.
  266. { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
  267. },
  268. config = function()
  269. -- Telescope is a fuzzy finder that comes with a lot of different things that
  270. -- it can fuzzy find! It's more than just a "file finder", it can search
  271. -- many different aspects of Neovim, your workspace, LSP, and more!
  272. --
  273. -- The easiest way to use Telescope, is to start by doing something like:
  274. -- :Telescope help_tags
  275. --
  276. -- After running this command, a window will open up and you're able to
  277. -- type in the prompt window. You'll see a list of `help_tags` options and
  278. -- a corresponding preview of the help.
  279. --
  280. -- Two important keymaps to use while in Telescope are:
  281. -- - Insert mode: <c-/>
  282. -- - Normal mode: ?
  283. --
  284. -- This opens a window that shows you all of the keymaps for the current
  285. -- Telescope picker. This is really useful to discover what Telescope can
  286. -- do as well as how to actually do it!
  287. -- [[ Configure Telescope ]]
  288. -- See `:help telescope` and `:help telescope.setup()`
  289. require('telescope').setup {
  290. -- You can put your default mappings / updates / etc. in here
  291. -- All the info you're looking for is in `:help telescope.setup()`
  292. --
  293. -- defaults = {
  294. -- mappings = {
  295. -- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
  296. -- },
  297. -- },
  298. -- pickers = {}
  299. extensions = {
  300. ['ui-select'] = {
  301. require('telescope.themes').get_dropdown(),
  302. },
  303. },
  304. }
  305. -- Enable Telescope extensions if they are installed
  306. pcall(require('telescope').load_extension, 'fzf')
  307. pcall(require('telescope').load_extension, 'ui-select')
  308. -- See `:help telescope.builtin`
  309. local builtin = require 'telescope.builtin'
  310. vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
  311. vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' })
  312. vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' })
  313. vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' })
  314. vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
  315. vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
  316. vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
  317. vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
  318. vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
  319. vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
  320. -- Slightly advanced example of overriding default behavior and theme
  321. vim.keymap.set('n', '<leader>/', function()
  322. -- You can pass additional configuration to Telescope to change the theme, layout, etc.
  323. builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
  324. winblend = 10,
  325. previewer = false,
  326. })
  327. end, { desc = '[/] Fuzzily search in current buffer' })
  328. -- It's also possible to pass additional configuration options.
  329. -- See `:help telescope.builtin.live_grep()` for information about particular keys
  330. vim.keymap.set('n', '<leader>s/', function()
  331. builtin.live_grep {
  332. grep_open_files = true,
  333. prompt_title = 'Live Grep in Open Files',
  334. }
  335. end, { desc = '[S]earch [/] in Open Files' })
  336. -- Shortcut for searching your Neovim configuration files
  337. vim.keymap.set('n', '<leader>sn', function()
  338. builtin.find_files { cwd = vim.fn.stdpath 'config' }
  339. end, { desc = '[S]earch [N]eovim files' })
  340. end,
  341. },
  342. -- LSP Plugins
  343. {
  344. -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
  345. -- used for completion, annotations and signatures of Neovim apis
  346. 'folke/lazydev.nvim',
  347. ft = 'lua',
  348. opts = {
  349. library = {
  350. -- Load luvit types when the `vim.uv` word is found
  351. { path = '${3rd}/luv/library', words = { 'vim%.uv' } },
  352. },
  353. },
  354. },
  355. {
  356. -- Main LSP Configuration
  357. 'neovim/nvim-lspconfig',
  358. dependencies = {
  359. -- Automatically install LSPs and related tools to stdpath for Neovim
  360. -- Mason must be loaded before its dependents so we need to set it up here.
  361. -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})`
  362. { 'mason-org/mason.nvim', opts = {} },
  363. 'mason-org/mason-lspconfig.nvim',
  364. 'WhoIsSethDaniel/mason-tool-installer.nvim',
  365. -- Useful status updates for LSP.
  366. { 'j-hui/fidget.nvim', opts = {} },
  367. -- Allows extra capabilities provided by blink.cmp
  368. 'saghen/blink.cmp',
  369. },
  370. config = function()
  371. -- Brief aside: **What is LSP?**
  372. --
  373. -- LSP is an initialism you've probably heard, but might not understand what it is.
  374. --
  375. -- LSP stands for Language Server Protocol. It's a protocol that helps editors
  376. -- and language tooling communicate in a standardized fashion.
  377. --
  378. -- In general, you have a "server" which is some tool built to understand a particular
  379. -- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc.). These Language Servers
  380. -- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone
  381. -- processes that communicate with some "client" - in this case, Neovim!
  382. --
  383. -- LSP provides Neovim with features like:
  384. -- - Go to definition
  385. -- - Find references
  386. -- - Autocompletion
  387. -- - Symbol Search
  388. -- - and more!
  389. --
  390. -- Thus, Language Servers are external tools that must be installed separately from
  391. -- Neovim. This is where `mason` and related plugins come into play.
  392. --
  393. -- If you're wondering about lsp vs treesitter, you can check out the wonderfully
  394. -- and elegantly composed help section, `:help lsp-vs-treesitter`
  395. -- This function gets run when an LSP attaches to a particular buffer.
  396. -- That is to say, every time a new file is opened that is associated with
  397. -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
  398. -- function will be executed to configure the current buffer
  399. vim.api.nvim_create_autocmd('LspAttach', {
  400. group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
  401. callback = function(event)
  402. -- NOTE: Remember that Lua is a real programming language, and as such it is possible
  403. -- to define small helper and utility functions so you don't have to repeat yourself.
  404. --
  405. -- In this case, we create a function that lets us more easily define mappings specific
  406. -- for LSP related items. It sets the mode, buffer and description for us each time.
  407. local map = function(keys, func, desc, mode)
  408. mode = mode or 'n'
  409. vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
  410. end
  411. -- Rename the variable under your cursor.
  412. -- Most Language Servers support renaming across files, etc.
  413. map('grn', vim.lsp.buf.rename, '[R]e[n]ame')
  414. -- Execute a code action, usually your cursor needs to be on top of an error
  415. -- or a suggestion from your LSP for this to activate.
  416. map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' })
  417. -- Find references for the word under your cursor.
  418. map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
  419. -- Jump to the implementation of the word under your cursor.
  420. -- Useful when your language has ways of declaring types without an actual implementation.
  421. map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
  422. -- Jump to the definition of the word under your cursor.
  423. -- This is where a variable was first declared, or where a function is defined, etc.
  424. -- To jump back, press <C-t>.
  425. map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
  426. -- WARN: This is not Goto Definition, this is Goto Declaration.
  427. -- For example, in C this would take you to the header.
  428. map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
  429. -- Fuzzy find all the symbols in your current document.
  430. -- Symbols are things like variables, functions, types, etc.
  431. map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols')
  432. -- Fuzzy find all the symbols in your current workspace.
  433. -- Similar to document symbols, except searches over your entire project.
  434. map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols')
  435. -- Jump to the type of the word under your cursor.
  436. -- Useful when you're not sure what type a variable is and you want to see
  437. -- the definition of its *type*, not where it was *defined*.
  438. map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition')
  439. -- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10)
  440. ---@param client vim.lsp.Client
  441. ---@param method vim.lsp.protocol.Method
  442. ---@param bufnr? integer some lsp support methods only in specific files
  443. ---@return boolean
  444. local function client_supports_method(client, method, bufnr)
  445. if vim.fn.has 'nvim-0.11' == 1 then
  446. return client:supports_method(method, bufnr)
  447. else
  448. return client.supports_method(method, { bufnr = bufnr })
  449. end
  450. end
  451. -- The following two autocommands are used to highlight references of the
  452. -- word under your cursor when your cursor rests there for a little while.
  453. -- See `:help CursorHold` for information about when this is executed
  454. --
  455. -- When you move your cursor, the highlights will be cleared (the second autocommand).
  456. local client = vim.lsp.get_client_by_id(event.data.client_id)
  457. if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then
  458. local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
  459. vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
  460. buffer = event.buf,
  461. group = highlight_augroup,
  462. callback = vim.lsp.buf.document_highlight,
  463. })
  464. vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
  465. buffer = event.buf,
  466. group = highlight_augroup,
  467. callback = vim.lsp.buf.clear_references,
  468. })
  469. vim.api.nvim_create_autocmd('LspDetach', {
  470. group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }),
  471. callback = function(event2)
  472. vim.lsp.buf.clear_references()
  473. vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf }
  474. end,
  475. })
  476. end
  477. -- The following code creates a keymap to toggle inlay hints in your
  478. -- code, if the language server you are using supports them
  479. --
  480. -- This may be unwanted, since they displace some of your code
  481. if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
  482. map('<leader>th', function()
  483. vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
  484. end, '[T]oggle Inlay [H]ints')
  485. end
  486. end,
  487. })
  488. -- Diagnostic Config
  489. -- See :help vim.diagnostic.Opts
  490. vim.diagnostic.config {
  491. severity_sort = true,
  492. float = { border = 'rounded', source = 'if_many' },
  493. underline = { severity = vim.diagnostic.severity.ERROR },
  494. signs = vim.g.have_nerd_font and {
  495. text = {
  496. [vim.diagnostic.severity.ERROR] = '󰅚 ',
  497. [vim.diagnostic.severity.WARN] = '󰀪 ',
  498. [vim.diagnostic.severity.INFO] = '󰋽 ',
  499. [vim.diagnostic.severity.HINT] = '󰌶 ',
  500. },
  501. } or {},
  502. virtual_text = {
  503. source = 'if_many',
  504. spacing = 2,
  505. format = function(diagnostic)
  506. local diagnostic_message = {
  507. [vim.diagnostic.severity.ERROR] = diagnostic.message,
  508. [vim.diagnostic.severity.WARN] = diagnostic.message,
  509. [vim.diagnostic.severity.INFO] = diagnostic.message,
  510. [vim.diagnostic.severity.HINT] = diagnostic.message,
  511. }
  512. return diagnostic_message[diagnostic.severity]
  513. end,
  514. },
  515. }
  516. -- LSP servers and clients are able to communicate to each other what features they support.
  517. -- By default, Neovim doesn't support everything that is in the LSP specification.
  518. -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
  519. -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
  520. local capabilities = require('blink.cmp').get_lsp_capabilities()
  521. -- Enable the following language servers
  522. -- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
  523. --
  524. -- Add any additional override configuration in the following tables. Available keys are:
  525. -- - cmd (table): Override the default command used to start the server
  526. -- - filetypes (table): Override the default list of associated filetypes for the server
  527. -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
  528. -- - settings (table): Override the default settings passed when initializing the server.
  529. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
  530. local servers = {
  531. -- clangd = {},
  532. -- gopls = {},
  533. -- pyright = {},
  534. -- rust_analyzer = {},
  535. -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
  536. --
  537. -- Some languages (like typescript) have entire language plugins that can be useful:
  538. -- https://github.com/pmizio/typescript-tools.nvim
  539. --
  540. -- But for many setups, the LSP (`ts_ls`) will work just fine
  541. -- ts_ls = {},
  542. --
  543. lua_ls = {
  544. -- cmd = { ... },
  545. -- filetypes = { ... },
  546. -- capabilities = {},
  547. settings = {
  548. Lua = {
  549. completion = {
  550. callSnippet = 'Replace',
  551. },
  552. -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
  553. -- diagnostics = { disable = { 'missing-fields' } },
  554. },
  555. },
  556. },
  557. }
  558. -- Ensure the servers and tools above are installed
  559. --
  560. -- To check the current status of installed tools and/or manually install
  561. -- other tools, you can run
  562. -- :Mason
  563. --
  564. -- You can press `g?` for help in this menu.
  565. --
  566. -- `mason` had to be setup earlier: to configure its options see the
  567. -- `dependencies` table for `nvim-lspconfig` above.
  568. --
  569. -- You can add other tools here that you want Mason to install
  570. -- for you, so that they are available from within Neovim.
  571. local ensure_installed = vim.tbl_keys(servers or {})
  572. vim.list_extend(ensure_installed, {
  573. 'stylua', -- Used to format Lua code
  574. })
  575. require('mason-tool-installer').setup { ensure_installed = ensure_installed }
  576. require('mason-lspconfig').setup {
  577. ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
  578. automatic_installation = false,
  579. handlers = {
  580. function(server_name)
  581. local server = servers[server_name] or {}
  582. -- This handles overriding only values explicitly passed
  583. -- by the server configuration above. Useful when disabling
  584. -- certain features of an LSP (for example, turning off formatting for ts_ls)
  585. server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
  586. require('lspconfig')[server_name].setup(server)
  587. end,
  588. },
  589. }
  590. end,
  591. },
  592. { -- Autoformat
  593. 'stevearc/conform.nvim',
  594. event = { 'BufWritePre' },
  595. cmd = { 'ConformInfo' },
  596. keys = {
  597. {
  598. '<leader>f',
  599. function()
  600. require('conform').format { async = true, lsp_format = 'fallback' }
  601. end,
  602. mode = '',
  603. desc = '[F]ormat buffer',
  604. },
  605. },
  606. opts = {
  607. notify_on_error = false,
  608. format_on_save = function(bufnr)
  609. -- Disable "format_on_save lsp_fallback" for languages that don't
  610. -- have a well standardized coding style. You can add additional
  611. -- languages here or re-enable it for the disabled ones.
  612. local disable_filetypes = { c = true, cpp = true }
  613. if disable_filetypes[vim.bo[bufnr].filetype] then
  614. return nil
  615. else
  616. return {
  617. timeout_ms = 500,
  618. lsp_format = 'fallback',
  619. }
  620. end
  621. end,
  622. formatters_by_ft = {
  623. lua = { 'stylua' },
  624. -- Conform can also run multiple formatters sequentially
  625. -- python = { "isort", "black" },
  626. --
  627. -- You can use 'stop_after_first' to run the first available formatter from the list
  628. -- javascript = { "prettierd", "prettier", stop_after_first = true },
  629. },
  630. },
  631. },
  632. { -- Autocompletion
  633. 'saghen/blink.cmp',
  634. event = 'VimEnter',
  635. version = '1.*',
  636. dependencies = {
  637. -- Snippet Engine
  638. {
  639. 'L3MON4D3/LuaSnip',
  640. version = '2.*',
  641. build = (function()
  642. -- Build Step is needed for regex support in snippets.
  643. -- This step is not supported in many windows environments.
  644. -- Remove the below condition to re-enable on windows.
  645. if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
  646. return
  647. end
  648. return 'make install_jsregexp'
  649. end)(),
  650. dependencies = {
  651. -- `friendly-snippets` contains a variety of premade snippets.
  652. -- See the README about individual language/framework/plugin snippets:
  653. -- https://github.com/rafamadriz/friendly-snippets
  654. -- {
  655. -- 'rafamadriz/friendly-snippets',
  656. -- config = function()
  657. -- require('luasnip.loaders.from_vscode').lazy_load()
  658. -- end,
  659. -- },
  660. },
  661. opts = {},
  662. },
  663. 'folke/lazydev.nvim',
  664. },
  665. --- @module 'blink.cmp'
  666. --- @type blink.cmp.Config
  667. opts = {
  668. keymap = {
  669. -- 'default' (recommended) for mappings similar to built-in completions
  670. -- <c-y> to accept ([y]es) the completion.
  671. -- This will auto-import if your LSP supports it.
  672. -- This will expand snippets if the LSP sent a snippet.
  673. -- 'super-tab' for tab to accept
  674. -- 'enter' for enter to accept
  675. -- 'none' for no mappings
  676. --
  677. -- For an understanding of why the 'default' preset is recommended,
  678. -- you will need to read `:help ins-completion`
  679. --
  680. -- No, but seriously. Please read `:help ins-completion`, it is really good!
  681. --
  682. -- All presets have the following mappings:
  683. -- <tab>/<s-tab>: move to right/left of your snippet expansion
  684. -- <c-space>: Open menu or open docs if already open
  685. -- <c-n>/<c-p> or <up>/<down>: Select next/previous item
  686. -- <c-e>: Hide menu
  687. -- <c-k>: Toggle signature help
  688. --
  689. -- See :h blink-cmp-config-keymap for defining your own keymap
  690. preset = 'default',
  691. -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
  692. -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
  693. },
  694. appearance = {
  695. -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
  696. -- Adjusts spacing to ensure icons are aligned
  697. nerd_font_variant = 'mono',
  698. },
  699. completion = {
  700. -- By default, you may press `<c-space>` to show the documentation.
  701. -- Optionally, set `auto_show = true` to show the documentation after a delay.
  702. documentation = { auto_show = false, auto_show_delay_ms = 500 },
  703. },
  704. sources = {
  705. default = { 'lsp', 'path', 'snippets', 'lazydev' },
  706. providers = {
  707. lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 },
  708. },
  709. },
  710. snippets = { preset = 'luasnip' },
  711. -- Blink.cmp includes an optional, recommended rust fuzzy matcher,
  712. -- which automatically downloads a prebuilt binary when enabled.
  713. --
  714. -- By default, we use the Lua implementation instead, but you may enable
  715. -- the rust implementation via `'prefer_rust_with_warning'`
  716. --
  717. -- See :h blink-cmp-config-fuzzy for more information
  718. fuzzy = { implementation = 'lua' },
  719. -- Shows a signature help window while you type arguments for a function
  720. signature = { enabled = true },
  721. },
  722. },
  723. { -- You can easily change to a different colorscheme.
  724. -- Change the name of the colorscheme plugin below, and then
  725. -- change the command in the config to whatever the name of that colorscheme is.
  726. --
  727. -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`.
  728. 'folke/tokyonight.nvim',
  729. priority = 1000, -- Make sure to load this before all the other start plugins.
  730. config = function()
  731. ---@diagnostic disable-next-line: missing-fields
  732. require('tokyonight').setup {
  733. styles = {
  734. -- comments = { italic = false }, -- Disable italics in comments
  735. },
  736. }
  737. -- Load the colorscheme here.
  738. -- Like many other themes, this one has different styles, and you could load
  739. -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'.
  740. vim.cmd.colorscheme 'tokyonight-night'
  741. end,
  742. },
  743. -- Highlight todo, notes, etc in comments
  744. { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } },
  745. { -- Collection of various small independent plugins/modules
  746. 'echasnovski/mini.nvim',
  747. config = function()
  748. -- Better Around/Inside textobjects
  749. --
  750. -- Examples:
  751. -- - va) - [V]isually select [A]round [)]paren
  752. -- - yinq - [Y]ank [I]nside [N]ext [Q]uote
  753. -- - ci' - [C]hange [I]nside [']quote
  754. require('mini.ai').setup { n_lines = 500 }
  755. -- Add/delete/replace surroundings (brackets, quotes, etc.)
  756. --
  757. -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren
  758. -- - sd' - [S]urround [D]elete [']quotes
  759. -- - sr)' - [S]urround [R]eplace [)] [']
  760. require('mini.surround').setup()
  761. -- Simple and easy statusline.
  762. -- You could remove this setup call if you don't like it,
  763. -- and try some other statusline plugin
  764. local statusline = require 'mini.statusline'
  765. -- set use_icons to true if you have a Nerd Font
  766. statusline.setup { use_icons = vim.g.have_nerd_font }
  767. -- You can configure sections in the statusline by overriding their
  768. -- default behavior. For example, here we set the section for
  769. -- cursor location to LINE:COLUMN
  770. ---@diagnostic disable-next-line: duplicate-set-field
  771. statusline.section_location = function()
  772. return '%2l:%-2v'
  773. end
  774. -- File browser
  775. -- require('mini.files').setup()
  776. end,
  777. },
  778. { -- Highlight, edit, and navigate code
  779. 'nvim-treesitter/nvim-treesitter',
  780. build = ':TSUpdate',
  781. main = 'nvim-treesitter.configs', -- Sets main module to use for opts
  782. -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
  783. opts = {
  784. ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' },
  785. -- Autoinstall languages that are not installed
  786. auto_install = true,
  787. highlight = {
  788. enable = true,
  789. -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
  790. -- If you are experiencing weird indenting issues, add the language to
  791. -- the list of additional_vim_regex_highlighting and disabled languages for indent.
  792. additional_vim_regex_highlighting = { 'ruby' },
  793. },
  794. indent = { enable = true, disable = { 'ruby' } },
  795. },
  796. -- There are additional nvim-treesitter modules that you can use to interact
  797. -- with nvim-treesitter. You should go explore a few and see what interests you:
  798. --
  799. -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
  800. -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
  801. -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
  802. },
  803. -- The following comments only work if you have downloaded the kickstart repo, not just copy pasted the
  804. -- init.lua. If you want these files, they are in the repository, so you can just download them and
  805. -- place them in the correct locations.
  806. -- NOTE: Next step on your Neovim journey: Add/Configure additional plugins for Kickstart
  807. --
  808. -- Here are some example plugins that I've included in the Kickstart repository.
  809. -- Uncomment any of the lines below to enable them (you will need to restart nvim).
  810. --
  811. -- require 'kickstart.plugins.debug',
  812. -- require 'kickstart.plugins.indent_line',
  813. -- require 'kickstart.plugins.lint',
  814. -- require 'kickstart.plugins.autopairs',
  815. -- require 'kickstart.plugins.neo-tree',
  816. -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps
  817. -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
  818. -- This is the easiest way to modularize your config.
  819. --
  820. -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
  821. { import = 'custom.plugins' },
  822. --
  823. -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec`
  824. -- Or use telescope!
  825. -- In normal mode type `<space>sh` then write `lazy.nvim-plugin`
  826. -- you can continue same window with `<space>sr` which resumes last telescope search
  827. }, {
  828. ui = {
  829. -- If you are using a Nerd Font: set icons to an empty table which will use the
  830. -- default lazy.nvim defined Nerd Font icons, otherwise define a unicode icons table
  831. icons = vim.g.have_nerd_font and {} or {
  832. cmd = '⌘',
  833. config = '🛠',
  834. event = '📅',
  835. ft = '📂',
  836. init = '⚙',
  837. keys = '🗝',
  838. plugin = '🔌',
  839. runtime = '💻',
  840. require = '🌙',
  841. source = '📄',
  842. start = '🚀',
  843. task = '📌',
  844. lazy = '💤 ',
  845. },
  846. },
  847. })
  848. -- The line beneath this is called `modeline`. See `:help modeline`
  849. -- vim: ts=2 sts=2 sw=2 et