2022-12-30 17:30:52 +01:00
return {
-- auto completion
{
" hrsh7th/nvim-cmp " ,
2023-01-16 20:39:12 +01:00
version = false , -- last release is way too old
2022-12-30 17:30:52 +01:00
event = " InsertEnter " ,
dependencies = {
" hrsh7th/cmp-nvim-lsp " ,
" hrsh7th/cmp-buffer " ,
" hrsh7th/cmp-path " ,
} ,
2024-03-28 21:32:09 +01:00
-- Not all LSP servers add brackets when completing a function.
-- To better deal with this, LazyVim adds a custom option to cmp,
-- that you can configure. For example:
--
-- ```lua
-- opts = {
-- auto_brackets = { "python" }
-- }
-- ```
2023-01-08 15:05:34 +01:00
opts = function ( )
2023-06-16 14:51:19 +02:00
vim.api . nvim_set_hl ( 0 , " CmpGhostText " , { link = " Comment " , default = true } )
2022-12-30 17:30:52 +01:00
local cmp = require ( " cmp " )
2023-06-28 11:24:54 +02:00
local defaults = require ( " cmp.config.default " ) ( )
2023-01-08 15:05:34 +01:00
return {
2024-03-28 21:32:09 +01:00
auto_brackets = { } , -- configure any filetype to auto add brackets
2023-01-04 08:21:44 +01:00
completion = {
completeopt = " menu,menuone,noinsert " ,
} ,
2022-12-30 17:30:52 +01:00
mapping = cmp.mapping . preset.insert ( {
2023-02-11 13:29:27 +01:00
[ " <C-n> " ] = cmp.mapping . select_next_item ( { behavior = cmp.SelectBehavior . Insert } ) ,
[ " <C-p> " ] = cmp.mapping . select_prev_item ( { behavior = cmp.SelectBehavior . Insert } ) ,
2022-12-30 17:30:52 +01:00
[ " <C-b> " ] = cmp.mapping . scroll_docs ( - 4 ) ,
[ " <C-f> " ] = cmp.mapping . scroll_docs ( 4 ) ,
[ " <C-Space> " ] = cmp.mapping . complete ( ) ,
[ " <C-e> " ] = cmp.mapping . abort ( ) ,
2024-05-19 22:46:09 +02:00
[ " <CR> " ] = LazyVim.cmp . confirm ( ) ,
[ " <S-CR> " ] = LazyVim.cmp . confirm ( { behavior = cmp.ConfirmBehavior . Replace } ) , -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
2023-10-09 09:51:53 +02:00
[ " <C-CR> " ] = function ( fallback )
cmp.abort ( )
fallback ( )
end ,
2022-12-30 17:30:52 +01:00
} ) ,
2023-10-09 10:05:57 +02:00
sources = cmp.config . sources ( {
{ name = " nvim_lsp " } ,
{ name = " path " } ,
} , {
{ name = " buffer " } ,
} ) ,
2022-12-31 17:03:39 +01:00
formatting = {
format = function ( _ , item )
2023-01-10 10:07:19 +01:00
local icons = require ( " lazyvim.config " ) . icons.kinds
2022-12-31 17:03:39 +01:00
if icons [ item.kind ] then
item.kind = icons [ item.kind ] .. item.kind
end
return item
end ,
} ,
2023-01-02 09:49:22 +01:00
experimental = {
ghost_text = {
2023-06-16 14:51:19 +02:00
hl_group = " CmpGhostText " ,
2023-01-02 09:49:22 +01:00
} ,
} ,
2023-06-28 11:24:54 +02:00
sorting = defaults.sorting ,
2023-01-08 15:05:34 +01:00
}
2022-12-30 17:30:52 +01:00
end ,
2024-03-28 21:32:09 +01:00
---@param opts cmp.ConfigSchema | {auto_brackets?: string[]}
2023-10-09 10:05:57 +02:00
config = function ( _ , opts )
for _ , source in ipairs ( opts.sources ) do
source.group_index = source.group_index or 1
end
2024-05-21 19:51:13 +02:00
local parse = require ( " cmp.utils.snippet " ) . parse
require ( " cmp.utils.snippet " ) . parse = function ( input )
local ok , ret = pcall ( parse , input )
if ok then
return ret
end
return LazyVim.cmp . snippet_preview ( input )
end
2024-03-28 21:32:09 +01:00
local cmp = require ( " cmp " )
cmp.setup ( opts )
cmp.event : on ( " confirm_done " , function ( event )
2024-05-19 21:46:54 +02:00
if vim.tbl_contains ( opts.auto_brackets or { } , vim.bo . filetype ) then
LazyVim.cmp . auto_brackets ( event.entry )
2024-03-28 21:32:09 +01:00
end
end )
2024-05-19 21:47:42 +02:00
cmp.event : on ( " menu_opened " , function ( event )
LazyVim.cmp . add_missing_snippet_docs ( event.window )
end )
2023-10-09 10:05:57 +02:00
end ,
2022-12-30 17:30:52 +01:00
} ,
2024-01-22 08:39:07 +01:00
-- snippets
2024-05-17 14:26:25 +02:00
vim.fn . has ( " nvim-0.10 " ) == 1
2024-05-16 18:03:58 +02:00
and {
2024-01-22 08:39:07 +01:00
" nvim-cmp " ,
dependencies = {
2024-05-21 19:22:41 +02:00
{
" garymjr/nvim-snippets " ,
opts = {
friendly_snippets = true ,
} ,
2024-05-21 19:54:20 +02:00
dependencies = { " rafamadriz/friendly-snippets " } ,
2024-05-21 19:22:41 +02:00
} ,
2024-01-22 08:39:07 +01:00
} ,
opts = function ( _ , opts )
2024-05-19 22:48:01 +02:00
opts.snippet = {
expand = function ( item )
return LazyVim.cmp . expand ( item.body )
end ,
}
2024-05-16 18:03:58 +02:00
table.insert ( opts.sources , { name = " snippets " } )
2024-01-22 08:39:07 +01:00
end ,
2024-05-16 18:03:58 +02:00
keys = {
{
" <Tab> " ,
function ( )
2024-05-18 21:32:53 +02:00
return vim.snippet . active ( { direction = 1 } ) and " <cmd>lua vim.snippet.jump(1)<cr> " or " <Tab> "
2024-05-16 18:03:58 +02:00
end ,
expr = true ,
silent = true ,
2024-05-18 21:32:53 +02:00
mode = { " i " , " s " } ,
2024-05-16 18:03:58 +02:00
} ,
{
" <S-Tab> " ,
function ( )
2024-05-18 21:32:53 +02:00
return vim.snippet . active ( { direction = - 1 } ) and " <cmd>lua vim.snippet.jump(-1)<cr> " or " <Tab> "
2024-05-16 18:03:58 +02:00
end ,
expr = true ,
silent = true ,
mode = { " i " , " s " } ,
} ,
} ,
}
or { import = " lazyvim.plugins.extras.coding.luasnip " , enabled = vim.fn . has ( " nvim-0.10 " ) == 0 } ,
2024-01-22 08:39:07 +01:00
2022-12-30 17:30:52 +01:00
-- auto pairs
{
" echasnovski/mini.pairs " ,
2022-12-30 18:19:57 +01:00
event = " VeryLazy " ,
2024-04-11 17:23:17 +02:00
opts = {
mappings = {
[ " ` " ] = { action = " closeopen " , pair = " `` " , neigh_pattern = " [^ \\ `]. " , register = { cr = false } } ,
} ,
} ,
2023-09-26 05:34:28 -06:00
keys = {
{
" <leader>up " ,
function ( )
vim.g . minipairs_disable = not vim.g . minipairs_disable
if vim.g . minipairs_disable then
2024-03-22 09:15:09 +01:00
LazyVim.warn ( " Disabled auto pairs " , { title = " Option " } )
2023-09-26 05:34:28 -06:00
else
2024-03-22 09:15:09 +01:00
LazyVim.info ( " Enabled auto pairs " , { title = " Option " } )
2023-09-26 05:34:28 -06:00
end
end ,
2024-03-27 00:56:44 -07:00
desc = " Toggle Auto Pairs " ,
2023-09-26 05:34:28 -06:00
} ,
} ,
2022-12-30 17:30:52 +01:00
} ,
-- comments
2023-09-26 13:24:03 +02:00
{
2024-05-21 19:31:40 +02:00
" folke/ts-comments.nvim " ,
event = " VeryLazy " ,
opts = { } ,
enabled = vim.fn . has ( " nvim-0.10 " ) == 1 ,
2023-09-26 13:24:03 +02:00
} ,
2024-05-18 12:05:19 +02:00
{
import = " lazyvim.plugins.extras.coding.mini-comment " ,
enabled = vim.fn . has ( " nvim-0.10 " ) == 0 ,
} ,
2024-05-18 21:52:16 +02:00
-- Better text-objects
{
" echasnovski/mini.ai " ,
event = " VeryLazy " ,
opts = function ( )
LazyVim.on_load ( " which-key.nvim " , function ( )
vim.schedule ( LazyVim.mini . ai_whichkey )
end )
local ai = require ( " mini.ai " )
return {
n_lines = 500 ,
custom_textobjects = {
o = ai.gen_spec . treesitter ( { -- code block
a = { " @block.outer " , " @conditional.outer " , " @loop.outer " } ,
i = { " @block.inner " , " @conditional.inner " , " @loop.inner " } ,
} ) ,
f = ai.gen_spec . treesitter ( { a = " @function.outer " , i = " @function.inner " } ) , -- function
c = ai.gen_spec . treesitter ( { a = " @class.outer " , i = " @class.inner " } ) , -- class
t = { " <([%p%w]-)%f[^<%w][^<>]->.-</%1> " , " ^<.->().*()</[^/]->$ " } , -- tags
d = { " %f[%d]%d+ " } , -- digits
e = { -- Word with case
{ " %u[%l%d]+%f[^%l%d] " , " %f[%S][%l%d]+%f[^%l%d] " , " %f[%P][%l%d]+%f[^%l%d] " , " ^[%l%d]+%f[^%l%d] " } ,
" ^().*()$ " ,
} ,
i = LazyVim.mini . ai_indent , -- indent
g = LazyVim.mini . ai_buffer , -- buffer
u = ai.gen_spec . function_call ( ) , -- u for "Usage"
U = ai.gen_spec . function_call ( { name_pattern = " [%w_] " } ) , -- without dot in function name
} ,
}
end ,
} ,
2022-12-30 17:30:52 +01:00
}