@@ -25,9 +25,12 @@ vim.opt.mouse = 'a'
2525vim .opt .showmode = false
2626
2727-- Sync clipboard between OS and Neovim.
28+ -- Schedule the setting after `UiEnter` because it can increase startup-time.
2829-- Remove this option if you want your OS clipboard to remain independent.
2930-- See `:help 'clipboard'`
30- -- vim.opt.clipboard = 'unnamedplus'
31+ vim .schedule (function ()
32+ -- vim.opt.clipboard = 'unnamedplus'
33+ end )
3134
3235-- Enable break indent
3336vim .opt .breakindent = true
@@ -71,8 +74,8 @@ vim.opt.scrolloff = 10
7174-- [[ Basic Keymaps ]]
7275-- See `:help vim.keymap.set()`
7376
74- -- Set highlight on search, but clear on pressing <Esc> in normal mode
75- vim . opt . hlsearch = true
77+ -- Clear highlights on search when pressing <Esc> in normal mode
78+ -- See `:help hlsearch`
7679vim .keymap .set (' n' , ' <Esc>' , ' <cmd>nohlsearch<CR>' )
7780
7881-- Diagnostic keymaps
@@ -121,7 +124,7 @@ vim.api.nvim_create_autocmd('TextYankPost', {
121124-- [[ Install `lazy.nvim` plugin manager ]]
122125-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
123126local lazypath = vim .fn .stdpath ' data' .. ' /lazy/lazy.nvim'
124- if not vim .uv .fs_stat (lazypath ) then
127+ if not ( vim .uv or vim . loop ) .fs_stat (lazypath ) then
125128 local lazyrepo = ' https://github.com/folke/lazy.nvim.git'
126129 local out = vim .fn .system { ' git' , ' clone' , ' --filter=blob:none' , ' --branch=stable' , lazyrepo , lazypath }
127130 if vim .v .shell_error ~= 0 then
@@ -275,20 +278,55 @@ require('lazy').setup({
275278 { -- Useful plugin to show you pending keybinds.
276279 ' folke/which-key.nvim' ,
277280 event = ' VimEnter' , -- Sets the loading event to 'VimEnter'
278- config = function () -- This is the function that runs, AFTER loading
279- require (' which-key' ).setup ()
281+ opts = {
282+ icons = {
283+ -- set icon mappings to true if you have a Nerd Font
284+ mappings = vim .g .have_nerd_font ,
285+ -- If you are using a Nerd Font: set icons.keys to an empty table which will use the
286+ -- default whick-key.nvim defined Nerd Font icons, otherwise define a string table
287+ keys = vim .g .have_nerd_font and {} or {
288+ Up = ' <Up> ' ,
289+ Down = ' <Down> ' ,
290+ Left = ' <Left> ' ,
291+ Right = ' <Right> ' ,
292+ C = ' <C-…> ' ,
293+ M = ' <M-…> ' ,
294+ D = ' <D-…> ' ,
295+ S = ' <S-…> ' ,
296+ CR = ' <CR> ' ,
297+ Esc = ' <Esc> ' ,
298+ ScrollWheelDown = ' <ScrollWheelDown> ' ,
299+ ScrollWheelUp = ' <ScrollWheelUp> ' ,
300+ NL = ' <NL> ' ,
301+ BS = ' <BS> ' ,
302+ Space = ' <Space> ' ,
303+ Tab = ' <Tab> ' ,
304+ F1 = ' <F1>' ,
305+ F2 = ' <F2>' ,
306+ F3 = ' <F3>' ,
307+ F4 = ' <F4>' ,
308+ F5 = ' <F5>' ,
309+ F6 = ' <F6>' ,
310+ F7 = ' <F7>' ,
311+ F8 = ' <F8>' ,
312+ F9 = ' <F9>' ,
313+ F10 = ' <F10>' ,
314+ F11 = ' <F11>' ,
315+ F12 = ' <F12>' ,
316+ },
317+ },
280318
281319 -- Document existing key chains
282- require ( ' which-key ' ). add {
283- { ' <leader>c' , group = ' [C]ode' },
320+ spec = {
321+ { ' <leader>c' , group = ' [C]ode' , mode = { ' n ' , ' x ' } },
284322 { ' <leader>d' , group = ' [D]ocument' },
285323 { ' <leader>r' , group = ' [R]ename' },
286324 { ' <leader>s' , group = ' [S]earch' },
287325 { ' <leader>w' , group = ' [W]orkspace' },
288326 { ' <leader>t' , group = ' [T]oggle' },
289327 { ' <leader>h' , group = ' Git [H]unk' , mode = { ' n' , ' v' } },
290- }
291- end ,
328+ },
329+ } ,
292330 },
293331
294332 -- NOTE: Plugins can specify dependencies.
@@ -403,7 +441,22 @@ require('lazy').setup({
403441 end ,
404442 },
405443
406- { -- LSP Configuration & Plugins
444+ -- LSP Plugins
445+ {
446+ -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
447+ -- used for completion, annotations and signatures of Neovim apis
448+ ' folke/lazydev.nvim' ,
449+ ft = ' lua' ,
450+ opts = {
451+ library = {
452+ -- Load luvit types when the `vim.uv` word is found
453+ { path = ' luvit-meta/library' , words = { ' vim%.uv' } },
454+ },
455+ },
456+ },
457+ { ' Bilal2453/luvit-meta' , lazy = true },
458+ {
459+ -- Main LSP Configuration
407460 ' neovim/nvim-lspconfig' ,
408461 dependencies = {
409462 -- Automatically install LSPs and related tools to stdpath for Neovim
@@ -415,19 +468,8 @@ require('lazy').setup({
415468 -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
416469 { ' j-hui/fidget.nvim' , opts = {} },
417470
418- -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
419- -- used for completion, annotations and signatures of Neovim apis
420- {
421- ' folke/lazydev.nvim' ,
422- ft = ' lua' ,
423- opts = {
424- library = {
425- -- Load luvit types when the `vim.uv` word is found
426- { path = ' luvit-meta/library' , words = { ' vim%.uv' } },
427- },
428- },
429- },
430- { ' Bilal2453/luvit-meta' , lazy = true },
471+ -- Allows extra capabilities provided by nvim-cmp
472+ ' hrsh7th/cmp-nvim-lsp' ,
431473 },
432474 config = function ()
433475 -- Brief aside: **What is LSP?**
@@ -467,8 +509,9 @@ require('lazy').setup({
467509 --
468510 -- In this case, we create a function that lets us more easily define mappings specific
469511 -- for LSP related items. It sets the mode, buffer and description for us each time.
470- local map = function (keys , func , desc )
471- vim .keymap .set (' n' , keys , func , { buffer = event .buf , desc = ' LSP: ' .. desc })
512+ local map = function (keys , func , desc , mode )
513+ mode = mode or ' n'
514+ vim .keymap .set (mode , keys , func , { buffer = event .buf , desc = ' LSP: ' .. desc })
472515 end
473516
474517 -- Jump to the definition of the word under your cursor.
@@ -502,7 +545,7 @@ require('lazy').setup({
502545
503546 -- Execute a code action, usually your cursor needs to be on top of an error
504547 -- or a suggestion from your LSP for this to activate.
505- map (' <leader>ca' , vim .lsp .buf .code_action , ' [C]ode [A]ction' )
548+ map (' <leader>ca' , vim .lsp .buf .code_action , ' [C]ode [A]ction' , { ' n ' , ' x ' } )
506549
507550 -- WARN: This is not Goto Definition, this is Goto Declaration.
508551 -- For example, in C this would take you to the header.
@@ -584,8 +627,8 @@ require('lazy').setup({
584627 -- Some languages (like typescript) have entire language plugins that can be useful:
585628 -- https://github.com/pmizio/typescript-tools.nvim
586629 --
587- -- But for many setups, the LSP (`tsserver `) will work just fine
588- -- tsserver = {},
630+ -- But for many setups, the LSP (`ts_ls `) will work just fine
631+ -- ts_ls = {},
589632 --
590633
591634 lua_ls = {
@@ -629,7 +672,7 @@ require('lazy').setup({
629672 local server = servers [server_name ] or {}
630673 -- This handles overriding only values explicitly passed
631674 -- by the server configuration above. Useful when disabling
632- -- certain features of an LSP (for example, turning off formatting for tsserver )
675+ -- certain features of an LSP (for example, turning off formatting for ts_ls )
633676 server .capabilities = vim .tbl_deep_extend (' force' , {}, capabilities , server .capabilities or {})
634677 require (' lspconfig' )[server_name ].setup (server )
635678 end ,
@@ -646,7 +689,7 @@ require('lazy').setup({
646689 {
647690 ' <leader>f' ,
648691 function ()
649- require (' conform' ).format { async = true , lsp_fallback = true }
692+ require (' conform' ).format { async = true , lsp_format = ' fallback ' }
650693 end ,
651694 mode = ' ' ,
652695 desc = ' [F]ormat buffer' ,
@@ -659,19 +702,24 @@ require('lazy').setup({
659702 -- have a well standardized coding style. You can add additional
660703 -- languages here or re-enable it for the disabled ones.
661704 local disable_filetypes = { c = true , cpp = true }
705+ local lsp_format_opt
706+ if disable_filetypes [vim .bo [bufnr ].filetype ] then
707+ lsp_format_opt = ' never'
708+ else
709+ lsp_format_opt = ' fallback'
710+ end
662711 return {
663712 timeout_ms = 500 ,
664- lsp_fallback = not disable_filetypes [ vim . bo [ bufnr ]. filetype ] ,
713+ lsp_format = lsp_format_opt ,
665714 }
666715 end ,
667716 formatters_by_ft = {
668717 lua = { ' stylua' },
669718 -- Conform can also run multiple formatters sequentially
670719 -- python = { "isort", "black" },
671720 --
672- -- You can use a sub-list to tell conform to run *until* a formatter
673- -- is found.
674- -- javascript = { { "prettierd", "prettier" } },
721+ -- You can use 'stop_after_first' to run the first available formatter from the list
722+ -- javascript = { "prettierd", "prettier", stop_after_first = true },
675723 },
676724 },
677725 },
@@ -853,6 +901,8 @@ require('lazy').setup({
853901 { -- Highlight, edit, and navigate code
854902 ' nvim-treesitter/nvim-treesitter' ,
855903 build = ' :TSUpdate' ,
904+ main = ' nvim-treesitter.configs' , -- Sets main module to use for opts
905+ -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
856906 opts = {
857907 ensure_installed = { ' bash' , ' c' , ' diff' , ' html' , ' lua' , ' luadoc' , ' markdown' , ' markdown_inline' , ' query' , ' vim' , ' vimdoc' },
858908 -- Autoinstall languages that are not installed
@@ -866,21 +916,12 @@ require('lazy').setup({
866916 },
867917 indent = { enable = true , disable = { ' ruby' } },
868918 },
869- config = function (_ , opts )
870- -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
871-
872- -- Prefer git instead of curl in order to improve connectivity in some environments
873- require (' nvim-treesitter.install' ).prefer_git = true
874- --- @diagnostic disable-next-line : missing-fields
875- require (' nvim-treesitter.configs' ).setup (opts )
876-
877- -- There are additional nvim-treesitter modules that you can use to interact
878- -- with nvim-treesitter. You should go explore a few and see what interests you:
879- --
880- -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
881- -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
882- -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
883- end ,
919+ -- There are additional nvim-treesitter modules that you can use to interact
920+ -- with nvim-treesitter. You should go explore a few and see what interests you:
921+ --
922+ -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
923+ -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
924+ -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
884925 },
885926 -- {
886927 -- 'sourcegraph/sg.nvim',
0 commit comments