Advertisement
Guest User

Untitled

a guest
Nov 13th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.51 KB | None | 0 0
  1. --[[
  2.  
  3. =====================================================================
  4. ==================== READ THIS BEFORE CONTINUING ====================
  5. =====================================================================
  6. ======== .-----. ========
  7. ======== .----------------------. | === | ========
  8. ======== |.-""""""""""""""""""-.| |-----| ========
  9. ======== || || | === | ========
  10. ======== || KICKSTART.NVIM || |-----| ========
  11. ======== || || | === | ========
  12. ======== || || |-----| ========
  13. ======== ||:Tutor || |:::::| ========
  14. ======== |'-..................-'| |____o| ========
  15. ======== `"")----------------(""` ___________ ========
  16. ======== /::::::::::| |::::::::::\ \ no mouse \ ========
  17. ======== /:::========| |==hjkl==:::\ \ required \ ========
  18. ======== '""""""""""""' '""""""""""""' '""""""""""' ========
  19. ======== ========
  20. =====================================================================
  21. =====================================================================
  22.  
  23. What is Kickstart?
  24.  
  25. Kickstart.nvim is *not* a distribution.
  26.  
  27. Kickstart.nvim is a starting point for your own configuration.
  28. The goal is that you can read every line of code, top-to-bottom, understand
  29. what your configuration is doing, and modify it to suit your needs.
  30.  
  31. Once you've done that, you can start exploring, configuring and tinkering to
  32. make Neovim your own! That might mean leaving Kickstart just the way it is for a while
  33. or immediately breaking it into modular pieces. It's up to you!
  34.  
  35. If you don't know anything about Lua, I recommend taking some time to read through
  36. a guide. One possible example which will only take 10-15 minutes:
  37. - https://learnxinyminutes.com/docs/lua/
  38.  
  39. After understanding a bit more about Lua, you can use `:help lua-guide` as a
  40. reference for how Neovim integrates Lua.
  41. - :help lua-guide
  42. - (or HTML version): https://neovim.io/doc/user/lua-guide.html
  43.  
  44. Kickstart Guide:
  45.  
  46. TODO: The very first thing you should do is to run the command `:Tutor` in Neovim.
  47.  
  48. If you don't know what this means, type the following:
  49. - <escape key>
  50. - :
  51. - Tutor
  52. - <enter key>
  53.  
  54. (If you already know the Neovim basics, you can skip this step.)
  55.  
  56. Once you've completed that, you can continue working through **AND READING** the rest
  57. of the kickstart init.lua.
  58.  
  59. Next, run AND READ `:help`.
  60. This will open up a help window with some basic information
  61. about reading, navigating and searching the builtin help documentation.
  62.  
  63. This should be the first place you go to look when you're stuck or confused
  64. with something. It's one of my favorite Neovim features.
  65.  
  66. MOST IMPORTANTLY, we provide a keymap "<space>sh" to [s]earch the [h]elp documentation,
  67. which is very useful when you're not exactly sure of what you're looking for.
  68.  
  69. I have left several `:help X` comments throughout the init.lua
  70. These are hints about where to find more information about the relevant settings,
  71. plugins or Neovim features used in Kickstart.
  72.  
  73. NOTE: Look for lines like this
  74.  
  75. Throughout the file. These are for you, the reader, to help you understand what is happening.
  76. Feel free to delete them once you know what you're doing, but they should serve as a guide
  77. for when you are first encountering a few different constructs in your Neovim config.
  78.  
  79. If you experience any errors while trying to install kickstart, run `:checkhealth` for more info.
  80.  
  81. I hope you enjoy your Neovim journey,
  82. - TJ
  83.  
  84. P.S. You can delete this when you're done too. It's your config now! :)
  85. --]]
  86.  
  87. -- Set <space> as the leader key
  88. -- See `:help mapleader`
  89. -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
  90. vim.g.mapleader = ' '
  91. vim.g.maplocalleader = ' '
  92.  
  93. -- Set to true if you have a Nerd Font installed and selected in the terminal
  94. vim.g.have_nerd_font = true
  95.  
  96. -- [[ Setting options ]]
  97. -- See `:help vim.opt`
  98. -- NOTE: You can change these options as you wish!
  99. -- For more options, you can see `:help option-list`
  100.  
  101. -- Make line numbers default
  102. vim.opt.number = true
  103. -- Relative numbers
  104. vim.opt.relativenumber = true
  105. -- Highlight on search
  106. vim.opt.hlsearch = false
  107. -- Enable mouse mode, can be useful for resizing splits for example!
  108. vim.opt.mouse = 'a'
  109.  
  110. -- Don't show the mode, since it's already in the status line
  111. vim.opt.showmode = false
  112.  
  113. -- Show filename at the top
  114. vim.opt.winbar = '%f'
  115.  
  116. -- Sync clipboard between OS and Neovim.
  117. -- Schedule the setting after `UiEnter` because it can increase startup-time.
  118. -- Remove this option if you want your OS clipboard to remain independent.
  119. -- See `:help 'clipboard'`
  120. vim.schedule(function()
  121. vim.opt.clipboard = 'unnamedplus'
  122. end)
  123.  
  124. -- Enable break indent
  125. vim.opt.breakindent = true
  126.  
  127. -- Save undo history
  128. vim.opt.undofile = true
  129.  
  130. -- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
  131. vim.opt.ignorecase = true
  132. vim.opt.smartcase = true
  133.  
  134. -- Keep signcolumn on by default
  135. vim.opt.signcolumn = 'yes'
  136.  
  137. -- Decrease update time
  138. vim.opt.updatetime = 250
  139.  
  140. -- Decrease mapped sequence wait time
  141. -- Displays which-key popup sooner
  142. vim.opt.timeoutlen = 300
  143.  
  144. -- Configure how new splits should be opened
  145. vim.opt.splitright = true
  146. vim.opt.splitbelow = true
  147.  
  148. -- Sets how neovim will display certain whitespace characters in the editor.
  149. -- See `:help 'list'`
  150. -- and `:help 'listchars'`
  151. vim.opt.list = true
  152. vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' }
  153.  
  154. -- Preview substitutions live, as you type!
  155. vim.opt.inccommand = 'split'
  156.  
  157. -- Show which line your cursor is on
  158. vim.opt.cursorline = true
  159.  
  160. -- Minimal number of screen lines to keep above and below the cursor.
  161. vim.opt.scrolloff = 10
  162.  
  163. -- [[ Basic Keymaps ]]
  164. -- See `:help vim.keymap.set()`
  165.  
  166. -- Clear highlights on search when pressing <Esc> in normal mode
  167. -- See `:help hlsearch`
  168. vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
  169.  
  170. -- Diagnostic keymaps
  171. vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
  172.  
  173. -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
  174. -- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
  175. -- is not what someone will guess without a bit more experience.
  176. --
  177. -- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
  178. -- or just use <C-\><C-n> to exit terminal mode
  179. vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
  180.  
  181. -- TIP: Disable arrow keys in normal mode
  182. -- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
  183. -- vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
  184. -- vim.keymap.set('n', '<up>', '<cmd>echo "Use k to move!!"<CR>')
  185. -- vim.keymap.set('n', '<down>', '<cmd>echo "Use j to move!!"<CR>')
  186.  
  187. -- Keybinds to make split navigation easier.
  188. -- Use CTRL+<hjkl> to switch between windows
  189. --
  190. -- See `:help wincmd` for a list of all window commands
  191. vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
  192. vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
  193. vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
  194. vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
  195.  
  196. vim.keymap.set('n', '<leader>n<Tab>', function()
  197. vim.cmd ':tabnew'
  198. end, { desc = '[Tab] New tab' })
  199. vim.keymap.set('n', '<leader>c<Tab>', function()
  200. vim.cmd ':tabclose'
  201. end, { desc = '[Tab] Close tab' })
  202. vim.keymap.set('n', '<leader><Tab>', function()
  203. vim.cmd ':tabnext'
  204. end, { desc = '[Tab] Next tab' })
  205.  
  206. vim.keymap.set('n', '<leader>dl', 'iUnityEngine.Debug.Log($"");<Esc>hhi', { desc = '[D]ebug [L]og' })
  207. vim.keymap.set('i', '<leader>dl', 'UnityEngine.Debug.Log($"");<Esc>hhi', { desc = '[D]ebug [L]og' })
  208.  
  209. -- [[ Basic Autocommands ]]
  210. -- See `:help lua-guide-autocommands`
  211.  
  212. -- Highlight when yanking (copying) text
  213. -- Try it with `yap` in normal mode
  214. -- See `:help vim.highlight.on_yank()`
  215. vim.api.nvim_create_autocmd('TextYankPost', {
  216. desc = 'Highlight when yanking (copying) text',
  217. group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
  218. callback = function()
  219. vim.highlight.on_yank()
  220. end,
  221. })
  222.  
  223. -- [[ Install `lazy.nvim` plugin manager ]]
  224. -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
  225. local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
  226. if not vim.uv.fs_stat(lazypath) then
  227. local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
  228. local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }
  229. if vim.v.shell_error ~= 0 then
  230. error('Error cloning lazy.nvim:\n' .. out)
  231. end
  232. end ---@diagnostic disable-next-line: undefined-field
  233. vim.opt.rtp:prepend(lazypath)
  234.  
  235. -- [[ Configure and install plugins ]]
  236. --
  237. -- To check the current status of your plugins, run
  238. -- :Lazy
  239. --
  240. -- You can press `?` in this menu for help. Use `:q` to close the window
  241. --
  242. -- To update plugins you can run
  243. -- :Lazy update
  244. --
  245. -- NOTE: Here is where you install your plugins.
  246. require('lazy').setup({
  247. -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
  248. 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically
  249.  
  250. -- NOTE: Plugins can also be added by using a table,
  251. -- with the first argument being the link and the following
  252. -- keys can be used to configure plugin behavior/loading/etc.
  253. --
  254. -- Use `opts = {}` to force a plugin to be loaded.
  255. --
  256.  
  257. -- Here is a more advanced example where we pass configuration
  258. -- options to `gitsigns.nvim`. This is equivalent to the following Lua:
  259. -- require('gitsigns').setup({ ... })
  260. --
  261. -- See `:help gitsigns` to understand what the configuration keys do
  262. { -- Adds git related signs to the gutter, as well as utilities for managing changes
  263. 'lewis6991/gitsigns.nvim',
  264. opts = {
  265. signs = {
  266. add = { text = '+' },
  267. change = { text = '~' },
  268. delete = { text = '_' },
  269. topdelete = { text = '‾' },
  270. changedelete = { text = '~' },
  271. },
  272. },
  273. },
  274.  
  275. -- Transparent background
  276. {
  277. 'xiyaowong/transparent.nvim',
  278. },
  279.  
  280. -- Complete brackets
  281. {
  282. 'jiangmiao/auto-pairs',
  283. },
  284.  
  285. -- neoCodeium
  286. {
  287. 'monkoose/neocodeium',
  288. event = 'VeryLazy',
  289. config = function()
  290. local neocodeium = require 'neocodeium'
  291. neocodeium.setup()
  292. vim.keymap.set('i', '<Tab>', neocodeium.accept)
  293. vim.keymap.set('i', '<A-j>', neocodeium.cycle_or_complete)
  294. vim.keymap.set('i', '<A-k>', function()
  295. neocodeium.cycle_or_complete(-1)
  296. end)
  297. end,
  298. },
  299.  
  300. -- Show method signatures
  301. {
  302. 'ray-x/lsp_signature.nvim',
  303. init = function()
  304. require('lsp_signature').setup {
  305. hint_enable = false,
  306. }
  307. end,
  308. },
  309.  
  310. -- Git blame
  311. {
  312. 'f-person/git-blame.nvim',
  313. init = function()
  314. vim.g.gitblame_display_virtual_text = 0
  315. end,
  316. },
  317.  
  318. -- Status line
  319. {
  320. 'nvim-lualine/lualine.nvim',
  321. init = function()
  322. local git_blame = require 'gitblame'
  323. require('lualine').setup {
  324. options = {
  325. icons_enabled = true,
  326. theme = 'everforest',
  327. section_separators = { left = '', right = '' },
  328. component_separators = '',
  329. },
  330. -- Show git blame info in the status line
  331. sections = {
  332. lualine_c = { { git_blame.get_current_blame_text, cond = git_blame.is_blame_text_available } },
  333. },
  334. }
  335. end,
  336. },
  337.  
  338. -- NOTE: Plugins can also be configured to run Lua code when they are loaded.
  339. --
  340. -- This is often very useful to both group configuration, as well as handle
  341. -- lazy loading plugins that don't need to be loaded immediately at startup.
  342. --
  343. -- For example, in the following configuration, we use:
  344. -- event = 'VimEnter'
  345. --
  346. -- which loads which-key before all the UI elements are loaded. Events can be
  347. -- normal autocommands events (`:help autocmd-events`).
  348. --
  349. -- Then, because we use the `config` key, the configuration only runs
  350. -- after the plugin has been loaded:
  351. -- config = function() ... end
  352.  
  353. { -- Useful plugin to show you pending keybinds.
  354. 'folke/which-key.nvim',
  355. event = 'VimEnter', -- Sets the loading event to 'VimEnter'
  356. config = function() -- This is the function that runs, AFTER loading
  357. require('which-key').setup()
  358.  
  359. -- Document existing key chains
  360. require('which-key').add {
  361. { '<leader>c', group = '[C]ode' },
  362. { '<leader>d', group = '[D]ocument' },
  363. { '<leader>r', group = '[R]ename' },
  364. { '<leader>s', group = '[S]earch' },
  365. { '<leader>w', group = '[W]orkspace' },
  366. { '<leader>t', group = '[T]oggle' },
  367. { '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
  368. }
  369. end,
  370. },
  371.  
  372. -- NOTE: Plugins can specify dependencies.
  373. --
  374. -- The dependencies are proper plugin specifications as well - anything
  375. -- you do for a plugin at the top level, you can do for a dependency.
  376. --
  377. -- Use the `dependencies` key to specify the dependencies of a particular plugin
  378.  
  379. { -- Fuzzy Finder (files, lsp, etc)
  380. 'nvim-telescope/telescope.nvim',
  381. event = 'VimEnter',
  382. branch = '0.1.x',
  383. dependencies = {
  384. 'nvim-lua/plenary.nvim',
  385. { -- If encountering errors, see telescope-fzf-native README for installation instructions
  386. 'nvim-telescope/telescope-fzf-native.nvim',
  387.  
  388. -- `build` is used to run some command when the plugin is installed/updated.
  389. -- This is only run then, not every time Neovim starts up.
  390. build = 'make',
  391.  
  392. -- `cond` is a condition used to determine whether this plugin should be
  393. -- installed and loaded.
  394. cond = function()
  395. return vim.fn.executable 'make' == 1
  396. end,
  397. },
  398. { 'nvim-telescope/telescope-ui-select.nvim' },
  399.  
  400. -- Useful for getting pretty icons, but requires a Nerd Font.
  401. { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
  402. },
  403. config = function()
  404. -- [[ Configure Telescope ]]
  405. -- See `:help telescope` and `:help telescope.setup()`
  406. require('telescope').setup {
  407. -- You can put your default mappings / updates / etc. in here
  408. -- All the info you're looking for is in `:help telescope.setup()`
  409. --
  410. defaults = {
  411. path_display = function(_, path)
  412. local tail = require('telescope.utils').path_tail(path)
  413. return string.format('%s (%s)', tail, path)
  414. end,
  415. },
  416. -- pickers = {}
  417. extensions = {
  418. ['ui-select'] = {
  419. require('telescope.themes').get_dropdown(),
  420. },
  421. },
  422. }
  423.  
  424. -- Enable Telescope extensions if they are installed
  425. pcall(require('telescope').load_extension, 'fzf')
  426. pcall(require('telescope').load_extension, 'ui-select')
  427.  
  428. -- See `:help telescope.builtin`
  429. local builtin = require 'telescope.builtin'
  430. vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
  431. vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' })
  432. vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
  433. vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
  434. vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
  435. vim.keymap.set('n', '<leader>?', builtin.oldfiles, { desc = '[?]Find Recent Files' })
  436. vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
  437.  
  438. -- Slightly advanced example of overriding default behavior and theme
  439. vim.keymap.set('n', '<leader>/', function()
  440. -- You can pass additional configuration to Telescope to change the theme, layout, etc.
  441. builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
  442. winblend = 10,
  443. previewer = false,
  444. })
  445. end, { desc = '[/] Fuzzily search in current buffer' })
  446.  
  447. -- It's also possible to pass additional configuration options.
  448. -- See `:help telescope.builtin.live_grep()` for information about particular keys
  449. vim.keymap.set('n', '<leader>s/', function()
  450. builtin.live_grep {
  451. grep_open_files = true,
  452. prompt_title = 'Live Grep in Open Files',
  453. }
  454. end, { desc = '[S]earch [/] in Open Files' })
  455.  
  456. -- Shortcut for searching your Neovim configuration files
  457. vim.keymap.set('n', '<leader>sn', function()
  458. builtin.find_files { cwd = vim.fn.stdpath 'config' }
  459. end, { desc = '[S]earch [N]eovim files' })
  460. end,
  461. },
  462.  
  463. -- LSP Plugins
  464. {
  465. -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
  466. -- used for completion, annotations and signatures of Neovim apis
  467. 'folke/lazydev.nvim',
  468. ft = 'lua',
  469. opts = {
  470. library = {
  471. -- Load luvit types when the `vim.uv` word is found
  472. { path = 'luvit-meta/library', words = { 'vim%.uv' } },
  473. },
  474. },
  475. },
  476. { 'Bilal2453/luvit-meta', lazy = true },
  477. {
  478. -- Main LSP Configuration
  479. 'neovim/nvim-lspconfig',
  480. dependencies = {
  481. -- Automatically install LSPs and related tools to stdpath for Neovim
  482. { 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
  483. 'williamboman/mason-lspconfig.nvim',
  484. 'WhoIsSethDaniel/mason-tool-installer.nvim',
  485.  
  486. -- Useful status updates for LSP.
  487. -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
  488. { 'j-hui/fidget.nvim', opts = {} },
  489.  
  490. -- Allows extra capabilities provided by nvim-cmp
  491. 'hrsh7th/cmp-nvim-lsp',
  492. },
  493. config = function()
  494. -- This function gets run when an LSP attaches to a particular buffer.
  495. -- That is to say, every time a new file is opened that is associated with
  496. -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
  497. -- function will be executed to configure the current buffer
  498. vim.api.nvim_create_autocmd('LspAttach', {
  499. group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
  500. callback = function(event)
  501. -- NOTE: Remember that Lua is a real programming language, and as such it is possible
  502. -- to define small helper and utility functions so you don't have to repeat yourself.
  503. --
  504. -- In this case, we create a function that lets us more easily define mappings specific
  505. -- for LSP related items. It sets the mode, buffer and description for us each time.
  506. local map = function(keys, func, desc)
  507. vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
  508. end
  509.  
  510. -- Jump to the definition of the word under your cursor.
  511. -- This is where a variable was first declared, or where a function is defined, etc.
  512. -- To jump back, press <C-t>.
  513. map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
  514.  
  515. -- Find references for the word under your cursor.
  516. map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
  517.  
  518. -- Jump to the implementation of the word under your cursor.
  519. -- Useful when your language has ways of declaring types without an actual implementation.
  520. map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
  521.  
  522. -- Jump to the type of the word under your cursor.
  523. -- Useful when you're not sure what type a variable is and you want to see
  524. -- the definition of its *type*, not where it was *defined*.
  525. map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
  526.  
  527. -- Fuzzy find all the symbols in your current document.
  528. -- Symbols are things like variables, functions, types, etc.
  529. map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
  530.  
  531. -- Fuzzy find all the symbols in your current workspace.
  532. -- Similar to document symbols, except searches over your entire project.
  533. map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
  534.  
  535. -- Rename the variable under your cursor.
  536. -- Most Language Servers support renaming across files, etc.
  537. map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
  538.  
  539. -- Execute a code action, usually your cursor needs to be on top of an error
  540. -- or a suggestion from your LSP for this to activate.
  541. map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
  542.  
  543. -- WARN: This is not Goto Definition, this is Goto Declaration.
  544. -- For example, in C this would take you to the header.
  545. map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
  546.  
  547. map('K', vim.lsp.buf.hover, 'Hover Documentation')
  548. map('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
  549.  
  550. -- The following two autocommands are used to highlight references of the
  551. -- word under your cursor when your cursor rests there for a little while.
  552. -- See `:help CursorHold` for information about when this is executed
  553. --
  554. -- When you move your cursor, the highlights will be cleared (the second autocommand).
  555. local client = vim.lsp.get_client_by_id(event.data.client_id)
  556. if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then
  557. local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
  558. vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
  559. buffer = event.buf,
  560. group = highlight_augroup,
  561. callback = vim.lsp.buf.document_highlight,
  562. })
  563.  
  564. vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
  565. buffer = event.buf,
  566. group = highlight_augroup,
  567. callback = vim.lsp.buf.clear_references,
  568. })
  569.  
  570. vim.api.nvim_create_autocmd('LspDetach', {
  571. group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }),
  572. callback = function(event2)
  573. vim.lsp.buf.clear_references()
  574. vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf }
  575. end,
  576. })
  577. end
  578.  
  579. -- The following code creates a keymap to toggle inlay hints in your
  580. -- code, if the language server you are using supports them
  581. --
  582. -- This may be unwanted, since they displace some of your code
  583. if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
  584. map('<leader>th', function()
  585. vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
  586. end, '[T]oggle Inlay [H]ints')
  587. end
  588. end,
  589. })
  590.  
  591. -- LSP servers and clients are able to communicate to each other what features they support.
  592. -- By default, Neovim doesn't support everything that is in the LSP specification.
  593. -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
  594. -- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
  595. local capabilities = vim.lsp.protocol.make_client_capabilities()
  596. capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
  597.  
  598. -- Enable the following language servers
  599. -- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
  600. --
  601. -- Add any additional override configuration in the following tables. Available keys are:
  602. -- - cmd (table): Override the default command used to start the server
  603. -- - filetypes (table): Override the default list of associated filetypes for the server
  604. -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
  605. -- - settings (table): Override the default settings passed when initializing the server.
  606. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
  607. local servers = {
  608. -- clangd = {},
  609. -- gopls = {},
  610. -- pyright = {},
  611. -- rust_analyzer = {},
  612. -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
  613. --
  614. -- Some languages (like typescript) have entire language plugins that can be useful:
  615. -- https://github.com/pmizio/typescript-tools.nvim
  616. --
  617. -- But for many setups, the LSP (`tsserver`) will work just fine
  618. -- tsserver = {},
  619. --
  620.  
  621. csharp_ls = {},
  622. lua_ls = {
  623. -- cmd = {...},
  624. -- filetypes = { ...},
  625. -- capabilities = {},
  626. settings = {
  627. Lua = {
  628. completion = {
  629. callSnippet = 'Replace',
  630. },
  631. -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
  632. -- diagnostics = { disable = { 'missing-fields' } },
  633. },
  634. },
  635. },
  636. }
  637.  
  638. -- Ensure the servers and tools above are installed
  639. -- To check the current status of installed tools and/or manually install
  640. -- other tools, you can run
  641. -- :Mason
  642. --
  643. -- You can press `g?` for help in this menu.
  644. require('mason').setup()
  645.  
  646. -- You can add other tools here that you want Mason to install
  647. -- for you, so that they are available from within Neovim.
  648. local ensure_installed = vim.tbl_keys(servers or {})
  649. vim.list_extend(ensure_installed, {
  650. 'stylua', -- Used to format Lua code
  651. })
  652. require('mason-tool-installer').setup { ensure_installed = ensure_installed }
  653.  
  654. require('mason-lspconfig').setup {
  655. handlers = {
  656. function(server_name)
  657. local server = servers[server_name] or {}
  658. -- This handles overriding only values explicitly passed
  659. -- by the server configuration above. Useful when disabling
  660. -- certain features of an LSP (for example, turning off formatting for tsserver)
  661. server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
  662. require('lspconfig')[server_name].setup(server)
  663. end,
  664. },
  665. }
  666. end,
  667. },
  668.  
  669. { -- Autoformat
  670. 'stevearc/conform.nvim',
  671. event = { 'BufWritePre' },
  672. cmd = { 'ConformInfo' },
  673. keys = {
  674. {
  675. '<leader>f',
  676. function()
  677. require('conform').format { async = true, lsp_fallback = true }
  678. end,
  679. mode = '',
  680. desc = '[F]ormat buffer',
  681. },
  682. },
  683. opts = {
  684. notify_on_error = false,
  685. format_on_save = function(bufnr)
  686. -- Disable "format_on_save lsp_fallback" for languages that don't
  687. -- have a well standardized coding style. You can add additional
  688. -- languages here or re-enable it for the disabled ones.
  689. local disable_filetypes = { c = true, cpp = true }
  690. return {
  691. timeout_ms = 500,
  692. lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype],
  693. }
  694. end,
  695. formatters_by_ft = {
  696. lua = { 'stylua' },
  697. -- Conform can also run multiple formatters sequentially
  698. -- python = { "isort", "black" },
  699. --
  700. -- You can use 'stop_after_first' to run the first available formatter from the list
  701. -- javascript = { "prettierd", "prettier", stop_after_first = true },
  702. },
  703. },
  704. },
  705.  
  706. { -- Autocompletion
  707. 'hrsh7th/nvim-cmp',
  708. event = 'InsertEnter',
  709. dependencies = {
  710. -- Snippet Engine & its associated nvim-cmp source
  711. {
  712. 'L3MON4D3/LuaSnip',
  713. build = (function()
  714. -- Build Step is needed for regex support in snippets.
  715. -- This step is not supported in many windows environments.
  716. -- Remove the below condition to re-enable on windows.
  717. if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
  718. return
  719. end
  720. return 'make install_jsregexp'
  721. end)(),
  722. dependencies = {
  723. -- `friendly-snippets` contains a variety of premade snippets.
  724. -- See the README about individual language/framework/plugin snippets:
  725. -- https://github.com/rafamadriz/friendly-snippets
  726. -- {
  727. -- 'rafamadriz/friendly-snippets',
  728. -- config = function()
  729. -- require('luasnip.loaders.from_vscode').lazy_load()
  730. -- end,
  731. -- },
  732. },
  733. },
  734. 'saadparwaiz1/cmp_luasnip',
  735.  
  736. -- Adds other completion capabilities.
  737. -- nvim-cmp does not ship with all sources by default. They are split
  738. -- into multiple repos for maintenance purposes.
  739. 'hrsh7th/cmp-nvim-lsp',
  740. 'hrsh7th/cmp-path',
  741. },
  742. config = function()
  743. -- See `:help cmp`
  744. local cmp = require 'cmp'
  745. local luasnip = require 'luasnip'
  746. luasnip.config.setup {}
  747.  
  748. cmp.setup {
  749. snippet = {
  750. expand = function(args)
  751. luasnip.lsp_expand(args.body)
  752. end,
  753. },
  754. completion = { completeopt = 'menu,menuone,noinsert' },
  755.  
  756. -- For an understanding of why these mappings were
  757. -- chosen, you will need to read `:help ins-completion`
  758. --
  759. -- No, but seriously. Please read `:help ins-completion`, it is really good!
  760. mapping = cmp.mapping.preset.insert {
  761. -- Select the [n]ext item
  762. ['<C-j>'] = cmp.mapping.select_next_item(),
  763. -- Select the [p]revious item
  764. ['<C-k>'] = cmp.mapping.select_prev_item(),
  765.  
  766. -- Scroll the documentation window [b]ack / [f]orward
  767. ['<C-b>'] = cmp.mapping.scroll_docs(-4),
  768. ['<C-f>'] = cmp.mapping.scroll_docs(4),
  769.  
  770. -- Accept ([y]es) the completion.
  771. -- This will auto-import if your LSP supports it.
  772. -- This will expand snippets if the LSP sent a snippet.
  773. ['<CR>'] = cmp.mapping.confirm { select = true },
  774.  
  775. -- If you prefer more traditional completion keymaps,
  776. -- you can uncomment the following lines
  777. --['<CR>'] = cmp.mapping.confirm { select = true },
  778. --['<Tab>'] = cmp.mapping.select_next_item(),
  779. --['<S-Tab>'] = cmp.mapping.select_prev_item(),
  780.  
  781. -- Manually trigger a completion from nvim-cmp.
  782. -- Generally you don't need this, because nvim-cmp will display
  783. -- completions whenever it has completion options available.
  784. ['<C-Space>'] = cmp.mapping.complete {},
  785.  
  786. -- Think of <c-l> as moving to the right of your snippet expansion.
  787. -- So if you have a snippet that's like:
  788. -- function $name($args)
  789. -- $body
  790. -- end
  791. --
  792. -- <c-l> will move you to the right of each of the expansion locations.
  793. -- <c-h> is similar, except moving you backwards.
  794. ['<C-l>'] = cmp.mapping(function()
  795. if luasnip.expand_or_locally_jumpable() then
  796. luasnip.expand_or_jump()
  797. end
  798. end, { 'i', 's' }),
  799. ['<C-h>'] = cmp.mapping(function()
  800. if luasnip.locally_jumpable(-1) then
  801. luasnip.jump(-1)
  802. end
  803. end, { 'i', 's' }),
  804.  
  805. -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
  806. -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
  807. },
  808. sources = {
  809. {
  810. name = 'lazydev',
  811. -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it
  812. group_index = 0,
  813. },
  814. { name = 'nvim_lsp' },
  815. { name = 'luasnip' },
  816. { name = 'path' },
  817. },
  818. }
  819. end,
  820. },
  821.  
  822. { -- You can easily change to a different colorscheme.
  823. -- Change the name of the colorscheme plugin below, and then
  824. -- change the command in the config to whatever the name of that colorscheme is.
  825. --
  826. -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`.
  827. 'sainnhe/everforest',
  828. priority = 1000, -- Make sure to load this before all the other start plugins.
  829. init = function()
  830. vim.cmd.colorscheme 'everforest'
  831. vim.g.everforest_enable_italic = true
  832. vim.g.everforest_background = 'hard'
  833. vim.cmd.hi 'Comment gui=none'
  834. end,
  835. },
  836.  
  837. -- Highlight todo, notes, etc in comments
  838. { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = true } },
  839.  
  840. { -- Highlight, edit, and navigate code
  841. 'nvim-treesitter/nvim-treesitter',
  842. build = ':TSUpdate',
  843. opts = {
  844. ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc', 'c_sharp', 'rust', 'python' },
  845. -- Autoinstall languages that are not installed
  846. auto_install = true,
  847. highlight = {
  848. enable = true,
  849. -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
  850. -- If you are experiencing weird indenting issues, add the language to
  851. -- the list of additional_vim_regex_highlighting and disabled languages for indent.
  852. additional_vim_regex_highlighting = { 'ruby' },
  853. },
  854. indent = { enable = true, disable = { 'ruby' } },
  855. },
  856. config = function(_, opts)
  857. -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
  858.  
  859. ---@diagnostic disable-next-line: missing-fields
  860. require('nvim-treesitter.configs').setup(opts)
  861.  
  862. -- There are additional nvim-treesitter modules that you can use to interact
  863. -- with nvim-treesitter. You should go explore a few and see what interests you:
  864. --
  865. -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
  866. -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
  867. -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
  868. end,
  869. },
  870.  
  871. {
  872. 'm-demare/hlargs.nvim',
  873. init = function()
  874. require('hlargs').setup {
  875. color = '#e69875',
  876. }
  877. end,
  878. },
  879.  
  880. {
  881. 'toppair/peek.nvim',
  882. event = { 'VeryLazy' },
  883. build = 'deno task --quiet build:fast',
  884. config = function()
  885. require('peek').setup {
  886. app = 'browser',
  887. }
  888. vim.api.nvim_create_user_command('PeekOpen', require('peek').open, {})
  889. vim.api.nvim_create_user_command('PeekClose', require('peek').close, {})
  890. end,
  891. },
  892.  
  893. {
  894. 'MeanderingProgrammer/render-markdown.nvim',
  895. dependencies = { 'nvim-treesitter/nvim-treesitter', 'echasnovski/mini.icons' }, -- if you use standalone mini plugins
  896. ---@module 'render-markdown'
  897. ---@type render.md.UserConfig
  898. opts = {},
  899. },
  900. --
  901. -- The following two comments only work if you have downloaded the kickstart repo, not just copy pasted the
  902. -- init.lua. If you want these files, they are in the repository, so you can just download them and
  903. -- place them in the correct locations.
  904.  
  905. -- NOTE: Next step on your Neovim journey: Add/Configure additional plugins for Kickstart
  906. --
  907. -- Here are some example plugins that I've included in the Kickstart repository.
  908. -- Uncomment any of the lines below to enable them (you will need to restart nvim).
  909. --
  910. -- require 'kickstart.plugins.debug',
  911. -- require 'kickstart.plugins.indent_line',
  912. -- require 'kickstart.plugins.lint',
  913. -- require 'kickstart.plugins.autopairs',
  914. -- require 'kickstart.plugins.neo-tree',
  915. -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps
  916.  
  917. -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
  918. -- This is the easiest way to modularize your config.
  919. --
  920. -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
  921. -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins`
  922. -- { import = 'custom.plugins' },
  923. }, {
  924. ui = {
  925. -- If you are using a Nerd Font: set icons to an empty table which will use the
  926. -- default lazy.nvim defined Nerd Font icons, otherwise define a unicode icons table
  927. icons = vim.g.have_nerd_font and {} or {
  928. cmd = '⌘',
  929. config = '🛠',
  930. event = '📅',
  931. ft = '📂',
  932. init = '⚙',
  933. keys = '🗝',
  934. plugin = '🔌',
  935. runtime = '💻',
  936. require = '🌙',
  937. source = '📄',
  938. start = '🚀',
  939. task = '📌',
  940. lazy = '💤 ',
  941. },
  942. },
  943. })
  944.  
  945. -- The line beneath this is called `modeline`. See `:help modeline`
  946. -- vim: ts=2 sts=2 sw=2 et
  947.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement