mirror of
https://git.disroot.org/FollieHiyuki/dotfiles.git
synced 2024-12-12 17:18:22 -05:00
3cefe864f4
- nvim-compe -> nvim-cmp - combine multple modules config into category files - add some more plugins
157 lines
4.9 KiB
Lua
157 lines
4.9 KiB
Lua
local M = {}
|
|
|
|
function M.cmp_conf()
|
|
local cmp = require('cmp')
|
|
local luasnip = require('luasnip')
|
|
|
|
local check_back_space = function()
|
|
local col = vim.fn.col '.' - 1
|
|
return col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' ~= nil
|
|
end
|
|
|
|
local t = function(str)
|
|
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
|
end
|
|
|
|
cmp.setup {
|
|
formatting = {
|
|
format = function(entry, vim_item)
|
|
local lspkind_icons = {
|
|
Text = '',
|
|
Method = '',
|
|
Function = '',
|
|
Constructor = '',
|
|
Field = 'ﰠ',
|
|
Variable = '',
|
|
Class = 'ﴯ',
|
|
Interface = '',
|
|
Module = '',
|
|
Property = 'ﰠ',
|
|
Unit = '塞',
|
|
Value = '',
|
|
Enum = '',
|
|
Keyword = '',
|
|
Snippet = '',
|
|
Color = '',
|
|
File = '',
|
|
Reference = '',
|
|
Folder = '',
|
|
EnumMember = '',
|
|
Constant = '',
|
|
Struct = 'פּ',
|
|
Event = '',
|
|
Operator = '',
|
|
TypeParameter = ''
|
|
}
|
|
-- load lspkind icons
|
|
vim_item.kind = string.format('%s %s', lspkind_icons[vim_item.kind], vim_item.kind)
|
|
|
|
vim_item.menu = ({
|
|
luasnip = '[SNIP]',
|
|
path = '[PATH]',
|
|
buffer = '[BUF]',
|
|
-- calc = '[CALC]',
|
|
-- nuspell = '[SPELL]',
|
|
spell = '[SPELL]',
|
|
emoji = '[EMOJI]',
|
|
nvim_lsp = '[LSP]',
|
|
latex_symbols = '[TEX]',
|
|
tmux = '[TMUX]',
|
|
orgmode = '[ORG]'
|
|
})[entry.source.name]
|
|
|
|
return vim_item
|
|
end
|
|
},
|
|
mapping = {
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-e>'] = cmp.mapping.close(),
|
|
-- supertab-like mapping
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
if vim.fn.pumvisible() == 1 then
|
|
vim.fn.feedkeys(t('<C-n>'), 'n')
|
|
elseif luasnip.expand_or_jumpable() then
|
|
vim.fn.feedkeys(t('<Plug>luasnip-expand-or-jump'), '')
|
|
elseif check_back_space() then
|
|
vim.fn.feedkeys(t('<Tab>'), 'n')
|
|
else
|
|
fallback()
|
|
end
|
|
end, {'i', 's'}),
|
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
|
if vim.fn.pumvisible() == 1 then
|
|
vim.fn.feedkeys(t('<C-p>'), 'n')
|
|
elseif luasnip.jumpable(-1) then
|
|
vim.fn.feedkeys(t('<Plug>luasnip-jump-prev'), '')
|
|
else
|
|
fallback()
|
|
end
|
|
end, {'i', 's'})
|
|
},
|
|
snippet = {
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end
|
|
},
|
|
sources = {
|
|
{name = 'luasnip'},
|
|
{name = 'path'},
|
|
{name = 'buffer'},
|
|
-- {name = 'calc'},
|
|
-- {name = 'nuspell'},
|
|
{name = 'spell'},
|
|
{name = 'emoji'},
|
|
{name = 'nvim_lsp'},
|
|
{name = 'latex_symbols'},
|
|
{name = 'tmux'},
|
|
{name = 'orgmode'}
|
|
}
|
|
}
|
|
end
|
|
|
|
function M.autopairs_conf()
|
|
require('nvim-autopairs').setup {fast_wrap = {}}
|
|
require('nvim-autopairs.completion.cmp').setup({
|
|
map_cr = true, -- map <CR> on insert mode
|
|
map_complete = true, -- it will auto insert `(` after select function or method item
|
|
auto_select = true -- automatically select the first item
|
|
})
|
|
end
|
|
|
|
function M.snippets_conf()
|
|
require('luasnip').config.set_config({
|
|
updateevents = 'TextChanged, TextChangedI',
|
|
history = true
|
|
})
|
|
|
|
-- Loading vscode-like snippets from 'friendly-snippets'
|
|
require('luasnip/loaders/from_vscode').lazy_load()
|
|
end
|
|
|
|
function M.coq_conf()
|
|
-- To add snippets from lsp servers, change lsp.lua:
|
|
-----
|
|
-- local coq = require('coq')
|
|
-- lspconf.<server>.setup(...) --> lspconf.<server>.setup(coq.lsp_ensure_capabilities(...))
|
|
vim.g.coq_settings = {
|
|
auto_start = true,
|
|
display = {
|
|
icons = {
|
|
mode = 'none'
|
|
}
|
|
}
|
|
}
|
|
end
|
|
|
|
function M.autotag_conf()
|
|
require('nvim-treesitter.configs').setup {
|
|
autotag = {enable = true}
|
|
}
|
|
end
|
|
|
|
return M
|