init.lua 40 KB

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