feat: more volume aliases
This commit is contained in:
parent
e7ab3b8f26
commit
0c4f5418a0
5 changed files with 50 additions and 56 deletions
dotfiles/neovim/lua/my/plugins
|
@ -1,6 +1,6 @@
|
|||
local M = {}
|
||||
|
||||
local function has_words_before ()
|
||||
local function has_words_before()
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil
|
||||
end
|
||||
|
@ -8,8 +8,16 @@ end
|
|||
function M.setup()
|
||||
local cmp = require("cmp")
|
||||
local lspkind = require('lspkind')
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
local options = {
|
||||
formatting = {format = lspkind.cmp_format()},
|
||||
snippet = {
|
||||
-- REQUIRED - you must specify a snippet engine
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body)
|
||||
end
|
||||
},
|
||||
mapping = {
|
||||
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), {'i', 'c'}),
|
||||
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), {'i', 'c'}),
|
||||
|
@ -17,28 +25,34 @@ function M.setup()
|
|||
['<C-y>'] = cmp.config.disable,
|
||||
['<C-e>'] = cmp.mapping({i = cmp.mapping.abort(), c = cmp.mapping.close()}),
|
||||
['<CR>'] = cmp.mapping.confirm({select = true}),
|
||||
-- https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings
|
||||
-- https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings
|
||||
['<C-Space>'] = cmp.mapping.confirm {behavior = cmp.ConfirmBehavior.Insert, select = true},
|
||||
['<Tab>'] = function(fallback)
|
||||
if not cmp.select_next_item() then
|
||||
if vim.bo.buftype ~= 'prompt' and has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
-- TODO: abstract booth of those away perhaps?
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
['<S-Tab>'] = function(fallback)
|
||||
if not cmp.select_prev_item() then
|
||||
if vim.bo.buftype ~= 'prompt' and has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, {"i", "s"}),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
end, {"i", "s"})
|
||||
},
|
||||
sources = cmp.config.sources({{name = 'nvim_lsp'}}, {{name = 'buffer'}})
|
||||
sources = cmp.config.sources({
|
||||
{name = 'nvim_lsp'}, -- lsp completion
|
||||
{name = 'luasnip'} -- snippets
|
||||
}, {{name = 'buffer'}})
|
||||
}
|
||||
|
||||
cmp.setup(options)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue