@@ -111,9 +111,12 @@ vim.opt.mouse = 'a'
111111vim .opt .showmode = false
112112
113113-- Sync clipboard between OS and Neovim.
114+ -- Schedule the setting after `UiEnter` because it can increase startup-time.
114115-- Remove this option if you want your OS clipboard to remain independent.
115116-- See `:help 'clipboard'`
116- vim .opt .clipboard = ' unnamedplus'
117+ vim .schedule (function ()
118+ vim .opt .clipboard = ' unnamedplus'
119+ end )
117120
118121-- Enable break indent
119122vim .opt .breakindent = true
@@ -157,14 +160,11 @@ vim.opt.scrolloff = 10
157160-- [[ Basic Keymaps ]]
158161-- See `:help vim.keymap.set()`
159162
160- -- Set highlight on search, but clear on pressing <Esc> in normal mode
161- vim . opt . hlsearch = true
163+ -- Clear highlights on search when pressing <Esc> in normal mode
164+ -- See `:help hlsearch`
162165vim .keymap .set (' n' , ' <Esc>' , ' <cmd>nohlsearch<CR>' )
163166
164167-- Diagnostic keymaps
165- vim .keymap .set (' n' , ' [d' , vim .diagnostic .goto_prev , { desc = ' Go to previous [D]iagnostic message' })
166- vim .keymap .set (' n' , ' ]d' , vim .diagnostic .goto_next , { desc = ' Go to next [D]iagnostic message' })
167- vim .keymap .set (' n' , ' <leader>e' , vim .diagnostic .open_float , { desc = ' Show diagnostic [E]rror messages' })
168168vim .keymap .set (' n' , ' <leader>q' , vim .diagnostic .setloclist , { desc = ' Open diagnostic [Q]uickfix list' })
169169
170170-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
@@ -207,9 +207,12 @@ vim.api.nvim_create_autocmd('TextYankPost', {
207207-- [[ Install `lazy.nvim` plugin manager ]]
208208-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
209209local lazypath = vim .fn .stdpath ' data' .. ' /lazy/lazy.nvim'
210- if not vim .loop .fs_stat (lazypath ) then
210+ if not ( vim .uv or vim . loop ) .fs_stat (lazypath ) then
211211 local lazyrepo = ' https://github.com/folke/lazy.nvim.git'
212- vim .fn .system { ' git' , ' clone' , ' --filter=blob:none' , ' --branch=stable' , lazyrepo , lazypath }
212+ local out = vim .fn .system { ' git' , ' clone' , ' --filter=blob:none' , ' --branch=stable' , lazyrepo , lazypath }
213+ if vim .v .shell_error ~= 0 then
214+ error (' Error cloning lazy.nvim:\n ' .. out )
215+ end
213216end --- @diagnostic disable-next-line : undefined-field
214217vim .opt .rtp :prepend (lazypath )
215218
@@ -234,11 +237,6 @@ require('lazy').setup({
234237 --
235238 -- Use `opts = {}` to force a plugin to be loaded.
236239 --
237- -- This is equivalent to:
238- -- require('Comment').setup({})
239-
240- -- "gc" to comment visual regions/lines
241- { ' numToStr/Comment.nvim' , opts = {} },
242240
243241 -- Here is a more advanced example where we pass configuration
244242 -- options to `gitsigns.nvim`. This is equivalent to the following Lua:
@@ -276,24 +274,55 @@ require('lazy').setup({
276274 { -- Useful plugin to show you pending keybinds.
277275 ' folke/which-key.nvim' ,
278276 event = ' VimEnter' , -- Sets the loading event to 'VimEnter'
279- config = function () -- This is the function that runs, AFTER loading
280- require (' which-key' ).setup ()
277+ opts = {
278+ icons = {
279+ -- set icon mappings to true if you have a Nerd Font
280+ mappings = vim .g .have_nerd_font ,
281+ -- If you are using a Nerd Font: set icons.keys to an empty table which will use the
282+ -- default whick-key.nvim defined Nerd Font icons, otherwise define a string table
283+ keys = vim .g .have_nerd_font and {} or {
284+ Up = ' <Up> ' ,
285+ Down = ' <Down> ' ,
286+ Left = ' <Left> ' ,
287+ Right = ' <Right> ' ,
288+ C = ' <C-…> ' ,
289+ M = ' <M-…> ' ,
290+ D = ' <D-…> ' ,
291+ S = ' <S-…> ' ,
292+ CR = ' <CR> ' ,
293+ Esc = ' <Esc> ' ,
294+ ScrollWheelDown = ' <ScrollWheelDown> ' ,
295+ ScrollWheelUp = ' <ScrollWheelUp> ' ,
296+ NL = ' <NL> ' ,
297+ BS = ' <BS> ' ,
298+ Space = ' <Space> ' ,
299+ Tab = ' <Tab> ' ,
300+ F1 = ' <F1>' ,
301+ F2 = ' <F2>' ,
302+ F3 = ' <F3>' ,
303+ F4 = ' <F4>' ,
304+ F5 = ' <F5>' ,
305+ F6 = ' <F6>' ,
306+ F7 = ' <F7>' ,
307+ F8 = ' <F8>' ,
308+ F9 = ' <F9>' ,
309+ F10 = ' <F10>' ,
310+ F11 = ' <F11>' ,
311+ F12 = ' <F12>' ,
312+ },
313+ },
281314
282315 -- Document existing key chains
283- require (' which-key' ).register {
284- [' <leader>c' ] = { name = ' [C]ode' , _ = ' which_key_ignore' },
285- [' <leader>d' ] = { name = ' [D]ocument' , _ = ' which_key_ignore' },
286- [' <leader>r' ] = { name = ' [R]ename' , _ = ' which_key_ignore' },
287- [' <leader>s' ] = { name = ' [S]earch' , _ = ' which_key_ignore' },
288- [' <leader>w' ] = { name = ' [W]orkspace' , _ = ' which_key_ignore' },
289- [' <leader>t' ] = { name = ' [T]oggle' , _ = ' which_key_ignore' },
290- [' <leader>h' ] = { name = ' Git [H]unk' , _ = ' which_key_ignore' },
291- }
292- -- visual mode
293- require (' which-key' ).register ({
294- [' <leader>h' ] = { ' Git [H]unk' },
295- }, { mode = ' v' })
296- end ,
316+ spec = {
317+ { ' <leader>c' , group = ' [C]ode' , mode = { ' n' , ' x' } },
318+ { ' <leader>d' , group = ' [D]ocument' },
319+ { ' <leader>r' , group = ' [R]ename' },
320+ { ' <leader>s' , group = ' [S]earch' },
321+ { ' <leader>w' , group = ' [W]orkspace' },
322+ { ' <leader>t' , group = ' [T]oggle' },
323+ { ' <leader>h' , group = ' Git [H]unk' , mode = { ' n' , ' v' } },
324+ },
325+ },
297326 },
298327
299328 -- NOTE: Plugins can specify dependencies.
@@ -408,7 +437,22 @@ require('lazy').setup({
408437 end ,
409438 },
410439
411- { -- LSP Configuration & Plugins
440+ -- LSP Plugins
441+ {
442+ -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
443+ -- used for completion, annotations and signatures of Neovim apis
444+ ' folke/lazydev.nvim' ,
445+ ft = ' lua' ,
446+ opts = {
447+ library = {
448+ -- Load luvit types when the `vim.uv` word is found
449+ { path = ' luvit-meta/library' , words = { ' vim%.uv' } },
450+ },
451+ },
452+ },
453+ { ' Bilal2453/luvit-meta' , lazy = true },
454+ {
455+ -- Main LSP Configuration
412456 ' neovim/nvim-lspconfig' ,
413457 dependencies = {
414458 -- Automatically install LSPs and related tools to stdpath for Neovim
@@ -420,9 +464,8 @@ require('lazy').setup({
420464 -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
421465 { ' j-hui/fidget.nvim' , opts = {} },
422466
423- -- `neodev` configures Lua LSP for your Neovim config, runtime and plugins
424- -- used for completion, annotations and signatures of Neovim apis
425- { ' folke/neodev.nvim' , opts = {} },
467+ -- Allows extra capabilities provided by nvim-cmp
468+ ' hrsh7th/cmp-nvim-lsp' ,
426469 },
427470 config = function ()
428471 -- Brief aside: **What is LSP?**
@@ -462,8 +505,9 @@ require('lazy').setup({
462505 --
463506 -- In this case, we create a function that lets us more easily define mappings specific
464507 -- for LSP related items. It sets the mode, buffer and description for us each time.
465- local map = function (keys , func , desc )
466- vim .keymap .set (' n' , keys , func , { buffer = event .buf , desc = ' LSP: ' .. desc })
508+ local map = function (keys , func , desc , mode )
509+ mode = mode or ' n'
510+ vim .keymap .set (mode , keys , func , { buffer = event .buf , desc = ' LSP: ' .. desc })
467511 end
468512
469513 -- Jump to the definition of the word under your cursor.
@@ -497,11 +541,7 @@ require('lazy').setup({
497541
498542 -- Execute a code action, usually your cursor needs to be on top of an error
499543 -- or a suggestion from your LSP for this to activate.
500- map (' <leader>ca' , vim .lsp .buf .code_action , ' [C]ode [A]ction' )
501-
502- -- Opens a popup that displays documentation about the word under your cursor
503- -- See `:help K` for why this keymap.
504- map (' K' , vim .lsp .buf .hover , ' Hover Documentation' )
544+ map (' <leader>ca' , vim .lsp .buf .code_action , ' [C]ode [A]ction' , { ' n' , ' x' })
505545
506546 -- WARN: This is not Goto Definition, this is Goto Declaration.
507547 -- For example, in C this would take you to the header.
@@ -513,7 +553,7 @@ require('lazy').setup({
513553 --
514554 -- When you move your cursor, the highlights will be cleared (the second autocommand).
515555 local client = vim .lsp .get_client_by_id (event .data .client_id )
516- if client and client .server_capabilities . documentHighlightProvider then
556+ if client and client .supports_method ( vim . lsp . protocol . Methods . textDocument_documentHighlight ) then
517557 local highlight_augroup = vim .api .nvim_create_augroup (' kickstart-lsp-highlight' , { clear = false })
518558 vim .api .nvim_create_autocmd ({ ' CursorHold' , ' CursorHoldI' }, {
519559 buffer = event .buf ,
@@ -536,13 +576,13 @@ require('lazy').setup({
536576 })
537577 end
538578
539- -- The following autocommand is used to enable inlay hints in your
579+ -- The following code creates a keymap to toggle inlay hints in your
540580 -- code, if the language server you are using supports them
541581 --
542582 -- This may be unwanted, since they displace some of your code
543- if client and client .server_capabilities . inlayHintProvider and vim .lsp .inlay_hint then
583+ if client and client .supports_method ( vim .lsp .protocol . Methods . textDocument_inlayHint ) then
544584 map (' <leader>th' , function ()
545- vim .lsp .inlay_hint .enable (not vim .lsp .inlay_hint .is_enabled () )
585+ vim .lsp .inlay_hint .enable (not vim .lsp .inlay_hint .is_enabled { bufnr = event . buf } )
546586 end , ' [T]oggle Inlay [H]ints' )
547587 end
548588 end ,
@@ -627,12 +667,13 @@ require('lazy').setup({
627667
628668 { -- Autoformat
629669 ' stevearc/conform.nvim' ,
630- lazy = false ,
670+ event = { ' BufWritePre' },
671+ cmd = { ' ConformInfo' },
631672 keys = {
632673 {
633674 ' <leader>f' ,
634675 function ()
635- require (' conform' ).format { async = true , lsp_fallback = true }
676+ require (' conform' ).format { async = true , lsp_format = ' fallback ' }
636677 end ,
637678 mode = ' ' ,
638679 desc = ' [F]ormat buffer' ,
@@ -645,19 +686,24 @@ require('lazy').setup({
645686 -- have a well standardized coding style. You can add additional
646687 -- languages here or re-enable it for the disabled ones.
647688 local disable_filetypes = { c = true , cpp = true }
689+ local lsp_format_opt
690+ if disable_filetypes [vim .bo [bufnr ].filetype ] then
691+ lsp_format_opt = ' never'
692+ else
693+ lsp_format_opt = ' fallback'
694+ end
648695 return {
649696 timeout_ms = 500 ,
650- lsp_fallback = not disable_filetypes [ vim . bo [ bufnr ]. filetype ] ,
697+ lsp_format = lsp_format_opt ,
651698 }
652699 end ,
653700 formatters_by_ft = {
654701 lua = { ' stylua' },
655702 -- Conform can also run multiple formatters sequentially
656703 -- python = { "isort", "black" },
657704 --
658- -- You can use a sub-list to tell conform to run *until* a formatter
659- -- is found.
660- -- javascript = { { "prettierd", "prettier" } },
705+ -- You can use 'stop_after_first' to run the first available formatter from the list
706+ -- javascript = { "prettierd", "prettier", stop_after_first = true },
661707 },
662708 },
663709 },
@@ -765,6 +811,11 @@ require('lazy').setup({
765811 -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
766812 },
767813 sources = {
814+ {
815+ name = ' lazydev' ,
816+ -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it
817+ group_index = 0 ,
818+ },
768819 { name = ' nvim_lsp' },
769820 { name = ' luasnip' },
770821 { name = ' path' },
@@ -801,7 +852,7 @@ require('lazy').setup({
801852 --
802853 -- Examples:
803854 -- - va) - [V]isually select [A]round [)]paren
804- -- - yinq - [Y]ank [I]nside [N]ext [']quote
855+ -- - yinq - [Y]ank [I]nside [N]ext [Q]uote
805856 -- - ci' - [C]hange [I]nside [']quote
806857 require (' mini.ai' ).setup { n_lines = 500 }
807858
@@ -834,8 +885,10 @@ require('lazy').setup({
834885 { -- Highlight, edit, and navigate code
835886 ' nvim-treesitter/nvim-treesitter' ,
836887 build = ' :TSUpdate' ,
888+ main = ' nvim-treesitter.configs' , -- Sets main module to use for opts
889+ -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
837890 opts = {
838- ensure_installed = { ' bash' , ' c' , ' diff' , ' html' , ' lua' , ' luadoc' , ' markdown' , ' vim' , ' vimdoc' },
891+ ensure_installed = { ' bash' , ' c' , ' diff' , ' html' , ' lua' , ' luadoc' , ' markdown' , ' markdown_inline ' , ' query ' , ' vim' , ' vimdoc' },
839892 -- Autoinstall languages that are not installed
840893 auto_install = true ,
841894 highlight = {
@@ -847,21 +900,12 @@ require('lazy').setup({
847900 },
848901 indent = { enable = true , disable = { ' ruby' } },
849902 },
850- config = function (_ , opts )
851- -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
852-
853- -- Prefer git instead of curl in order to improve connectivity in some environments
854- require (' nvim-treesitter.install' ).prefer_git = true
855- --- @diagnostic disable-next-line : missing-fields
856- require (' nvim-treesitter.configs' ).setup (opts )
857-
858- -- There are additional nvim-treesitter modules that you can use to interact
859- -- with nvim-treesitter. You should go explore a few and see what interests you:
860- --
861- -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
862- -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
863- -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
864- end ,
903+ -- There are additional nvim-treesitter modules that you can use to interact
904+ -- with nvim-treesitter. You should go explore a few and see what interests you:
905+ --
906+ -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
907+ -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
908+ -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
865909 },
866910
867911 -- The following two comments only work if you have downloaded the kickstart repo, not just copy pasted the
0 commit comments