211 lines
6.5 KiB
Lua
211 lines
6.5 KiB
Lua
return {
|
|
|
|
-- auto completion
|
|
{
|
|
"hrsh7th/nvim-cmp",
|
|
version = false, -- last release is way too old
|
|
event = "InsertEnter",
|
|
dependencies = {
|
|
"hrsh7th/cmp-nvim-lsp",
|
|
"hrsh7th/cmp-buffer",
|
|
"hrsh7th/cmp-path",
|
|
},
|
|
-- 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" }
|
|
-- }
|
|
-- ```
|
|
|
|
opts = function()
|
|
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
|
|
local cmp = require("cmp")
|
|
local defaults = require("cmp.config.default")()
|
|
return {
|
|
auto_brackets = {}, -- configure any filetype to auto add brackets
|
|
completion = {
|
|
completeopt = "menu,menuone,noinsert",
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
|
|
["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
|
|
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
|
["<C-Space>"] = cmp.mapping.complete(),
|
|
["<C-e>"] = cmp.mapping.abort(),
|
|
["<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.
|
|
["<C-CR>"] = function(fallback)
|
|
cmp.abort()
|
|
fallback()
|
|
end,
|
|
}),
|
|
sources = cmp.config.sources({
|
|
{ name = "nvim_lsp" },
|
|
{ name = "path" },
|
|
}, {
|
|
{ name = "buffer" },
|
|
}),
|
|
formatting = {
|
|
format = function(_, item)
|
|
local icons = require("lazyvim.config").icons.kinds
|
|
if icons[item.kind] then
|
|
item.kind = icons[item.kind] .. item.kind
|
|
end
|
|
return item
|
|
end,
|
|
},
|
|
experimental = {
|
|
ghost_text = {
|
|
hl_group = "CmpGhostText",
|
|
},
|
|
},
|
|
sorting = defaults.sorting,
|
|
}
|
|
end,
|
|
---@param opts cmp.ConfigSchema | {auto_brackets?: string[]}
|
|
config = function(_, opts)
|
|
for _, source in ipairs(opts.sources) do
|
|
source.group_index = source.group_index or 1
|
|
end
|
|
|
|
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
|
|
|
|
local cmp = require("cmp")
|
|
cmp.setup(opts)
|
|
cmp.event:on("confirm_done", function(event)
|
|
if vim.tbl_contains(opts.auto_brackets or {}, vim.bo.filetype) then
|
|
LazyVim.cmp.auto_brackets(event.entry)
|
|
end
|
|
end)
|
|
cmp.event:on("menu_opened", function(event)
|
|
LazyVim.cmp.add_missing_snippet_docs(event.window)
|
|
end)
|
|
end,
|
|
},
|
|
|
|
-- snippets
|
|
vim.fn.has("nvim-0.10") == 1
|
|
and {
|
|
"nvim-cmp",
|
|
dependencies = {
|
|
{
|
|
"garymjr/nvim-snippets",
|
|
opts = {
|
|
friendly_snippets = true,
|
|
},
|
|
dependencies = { "rafamadriz/friendly-snippets" },
|
|
},
|
|
},
|
|
opts = function(_, opts)
|
|
opts.snippet = {
|
|
expand = function(item)
|
|
return LazyVim.cmp.expand(item.body)
|
|
end,
|
|
}
|
|
table.insert(opts.sources, { name = "snippets" })
|
|
end,
|
|
keys = {
|
|
{
|
|
"<Tab>",
|
|
function()
|
|
return vim.snippet.active({ direction = 1 }) and "<cmd>lua vim.snippet.jump(1)<cr>" or "<Tab>"
|
|
end,
|
|
expr = true,
|
|
silent = true,
|
|
mode = { "i", "s" },
|
|
},
|
|
{
|
|
"<S-Tab>",
|
|
function()
|
|
return vim.snippet.active({ direction = -1 }) and "<cmd>lua vim.snippet.jump(-1)<cr>" or "<Tab>"
|
|
end,
|
|
expr = true,
|
|
silent = true,
|
|
mode = { "i", "s" },
|
|
},
|
|
},
|
|
}
|
|
or { import = "lazyvim.plugins.extras.coding.luasnip", enabled = vim.fn.has("nvim-0.10") == 0 },
|
|
|
|
-- auto pairs
|
|
{
|
|
"echasnovski/mini.pairs",
|
|
event = "VeryLazy",
|
|
opts = {
|
|
mappings = {
|
|
["`"] = { action = "closeopen", pair = "``", neigh_pattern = "[^\\`].", register = { cr = false } },
|
|
},
|
|
},
|
|
keys = {
|
|
{
|
|
"<leader>up",
|
|
function()
|
|
vim.g.minipairs_disable = not vim.g.minipairs_disable
|
|
if vim.g.minipairs_disable then
|
|
LazyVim.warn("Disabled auto pairs", { title = "Option" })
|
|
else
|
|
LazyVim.info("Enabled auto pairs", { title = "Option" })
|
|
end
|
|
end,
|
|
desc = "Toggle Auto Pairs",
|
|
},
|
|
},
|
|
},
|
|
|
|
-- comments
|
|
{
|
|
"folke/ts-comments.nvim",
|
|
event = "VeryLazy",
|
|
opts = {},
|
|
enabled = vim.fn.has("nvim-0.10") == 1,
|
|
},
|
|
{
|
|
import = "lazyvim.plugins.extras.coding.mini-comment",
|
|
enabled = vim.fn.has("nvim-0.10") == 0,
|
|
},
|
|
|
|
-- 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,
|
|
},
|
|
}
|