Advertisement
Guest User

Untitled

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