Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2025
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.77 KB | None | 0 0
  1. { "L3MON4D3/LuaSnip", -- {{{
  2.     -- follow latest release.
  3.     version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
  4.  
  5.     -- install jsregexp (optional!).
  6.     -- doesn't work on Windows
  7.     -- build = "make install_jsregexp",
  8.  
  9.     opts = {},
  10.  
  11.     dependencies = {
  12.         -- VSCode-style snippets that should work with any snippet engine, including
  13.         -- LuaSnip
  14.         "rafamadriz/friendly-snippets",
  15.     },
  16.  
  17.     setup = function(_, opts)
  18.         local ls = require("luasnip")
  19.         ls.setup(opts)
  20.  
  21.         vim.keymap.set({"i"}, "<c-j>", function() ls.expand_or_jump() end, {silent = true})
  22.         -- vim.keymap.set({"i", "s"}, "<c-j>", function() ls.jump(1) end, {silent = true})
  23.         vim.keymap.set({"i", "s"}, "<c-k>", function() ls.jump(-1) end, {silent = true})
  24.  
  25.         vim.keymap.set({"i", "s"}, "<c-e>", function()
  26.             if ls.choice_active() then
  27.                 ls.change_choice(1)
  28.             end
  29.         end, {silent = true})
  30.  
  31.         local s = ls.snippet
  32.         local t = ls.text_node
  33.         local i = ls.insert_node
  34.  
  35.         ls.add_snippets("all", {
  36.             s("ternary", {
  37.                 -- equivalent to "${1:cond} ? ${2:then} : ${3:else}"
  38.                 i(1, "cond"), t(" ? "), i(2, "then"), t(" : "), i(3, "else")
  39.             })
  40.         })
  41.  
  42.         -- apparently this is needed for luasnip to recognize friendly-snippets.
  43.         -- source:
  44.         -- https://github.com/rafamadriz/friendly-snippets/tree/main
  45.         require("luasnip.loaders.from_vscode").lazy_load()
  46.     end,
  47. }, -- }}}
  48.  
  49. { "hrsh7th/nvim-cmp", -- {{{
  50.     dependencies = {
  51.         "neovim/nvim-lspconfig",
  52.         "williamboman/mason.nvim",
  53.         "williamboman/mason-lspconfig.nvim",
  54.  
  55.         -- these are little plugins for nvim-cmp that provide different kinds of
  56.         -- completion
  57.         --
  58.         -- note that cmp-nvim-lsp needs additional completion inside of
  59.         -- `ide_stuff.lua` in order to work (search for `cmp_nvim_lsp` in there to
  60.         -- find it)
  61.         {"hrsh7th/cmp-nvim-lsp"}, -- LSP completions
  62.         {"hrsh7th/cmp-buffer"},   -- buffer name completions
  63.         {"hrsh7th/cmp-path"},     -- filesystem path completions (don't use backslashes on Windows or it breaks :/)
  64.         {"hrsh7th/cmp-cmdline"},  -- completions for `/` search and `:` ex commands
  65.  
  66.         { "saadparwaiz1/cmp_luasnip", -- {{{
  67.  
  68.             dependencies = {
  69.                 "L3MON4D3/LuaSnip",
  70.                 "hrsh7th/nvim-cmp",
  71.             },
  72.         }, -- }}}
  73.  
  74.         -- "hrsh7th/vim-vsnip",
  75.  
  76.         "L3MON4D3/LuaSnip",
  77.     },
  78.  
  79.     config = function()
  80.         local cmp = require('cmp')
  81.  
  82.         cmp.setup({
  83.             snippet = {
  84.                 -- REQUIRED - you must specify a snippet engine
  85.                 expand = function(args)
  86.                     -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
  87.                     require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
  88.                     -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
  89.                     -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
  90.                     vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
  91.  
  92.                     -- For `mini.snippets` users:
  93.                     -- local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert
  94.                     -- insert({ body = args.body }) -- Insert at cursor
  95.                     -- cmp.resubscribe({ "TextChangedI", "TextChangedP" })
  96.                     -- require("cmp.config").set_onetime({ sources = {} })
  97.                 end,
  98.             },
  99.             window = {
  100.                 -- completion = cmp.config.window.bordered(),
  101.                 -- documentation = cmp.config.window.bordered(),
  102.             },
  103.             mapping = cmp.mapping.preset.insert({
  104.                 ['<C-b>'] = cmp.mapping.scroll_docs(-4),
  105.                 ['<C-f>'] = cmp.mapping.scroll_docs(4),
  106.                 ['<C-Space>'] = cmp.mapping.complete(),
  107.                 ['<C-e>'] = cmp.mapping.abort(),
  108.                 ['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
  109.             }),
  110.             sources = cmp.config.sources({
  111.                 { name = 'nvim_lsp' },
  112.                 -- { name = 'vsnip' }, -- For vsnip users.
  113.                 -- { name = 'ultisnips' }, -- For ultisnips users.
  114.                 -- { name = 'snippy' }, -- For snippy users.
  115.                 { name = 'luasnip' }, -- For luasnip users.
  116.             }, {
  117.                 { name = 'buffer' },
  118.             }),
  119.         })
  120.  
  121.         -- Set configuration for specific filetype.
  122.         cmp.setup.filetype('gitcommit', {
  123.             sources = cmp.config.sources({
  124.                 { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
  125.             }, {
  126.                 { name = 'buffer' },
  127.             })
  128.         })
  129.  
  130.         -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
  131.         cmp.setup.cmdline({ '/', '?' }, {
  132.             mapping = cmp.mapping.preset.cmdline(),
  133.             sources = {
  134.                 { name = 'buffer' }
  135.             }
  136.         })
  137.  
  138.         -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
  139.         cmp.setup.cmdline(':', {
  140.             mapping = cmp.mapping.preset.cmdline(),
  141.             sources = cmp.config.sources({
  142.                 { name = 'path' }
  143.             }, {
  144.                 { name = 'cmdline' }
  145.             }),
  146.             matching = { disallow_symbol_nonprefix_matching = false }
  147.         })
  148.     end,
  149. }, -- }}}
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement