mirror of
https://github.com/LunarVim/LunarVim.git
synced 2024-09-21 02:55:09 +02:00
improve completion
This commit is contained in:
parent
f4f7a96496
commit
102b46ca4a
3 changed files with 163 additions and 92 deletions
|
@ -1,77 +1,99 @@
|
||||||
require('nvim-autopairs').setup()
|
-- require('nvim-autopairs').setup()
|
||||||
|
-- local npairs = require('nvim-autopairs')
|
||||||
|
|
||||||
|
-- local function imap(lhs, rhs, opts)
|
||||||
|
-- local options = {noremap = false}
|
||||||
|
-- if opts then options = vim.tbl_extend('force', options, opts) end
|
||||||
|
-- vim.api.nvim_set_keymap('i', lhs, rhs, options)
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- _G.MUtils = {}
|
||||||
|
|
||||||
|
-- -- TEST
|
||||||
|
-- vim.g.completion_confirm_key = ""
|
||||||
|
-- MUtils.completion_confirm = function()
|
||||||
|
-- if vim.fn.pumvisible() ~= 0 then
|
||||||
|
-- if vim.fn.complete_info()["selected"] ~= -1 then
|
||||||
|
-- vim.fn["compe#confirm"]()
|
||||||
|
-- -- return npairs.esc("<c-y>")
|
||||||
|
-- return npairs.esc("")
|
||||||
|
-- else
|
||||||
|
-- vim.defer_fn(function()
|
||||||
|
-- vim.fn["compe#confirm"]("<cr>")
|
||||||
|
-- end, 20)
|
||||||
|
-- return npairs.esc("<c-n>")
|
||||||
|
-- end
|
||||||
|
-- else
|
||||||
|
-- return npairs.check_break_line_char()
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
-- -- TEST
|
||||||
|
|
||||||
|
-- MUtils.completion_confirm = function()
|
||||||
|
-- if vim.fn.pumvisible() ~= 0 then
|
||||||
|
-- if vim.fn.complete_info()["selected"] ~= -1 then
|
||||||
|
-- vim.fn["compe#confirm"]()
|
||||||
|
-- return npairs.esc("")
|
||||||
|
-- else
|
||||||
|
-- vim.api.nvim_select_popupmenu_item(0, false, false, {})
|
||||||
|
-- vim.fn["compe#confirm"]()
|
||||||
|
-- return npairs.esc("<c-n>")
|
||||||
|
-- end
|
||||||
|
-- else
|
||||||
|
-- return npairs.check_break_line_char()
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- MUtils.tab = function()
|
||||||
|
-- if vim.fn.pumvisible() ~= 0 then
|
||||||
|
-- return npairs.esc("<C-n>")
|
||||||
|
-- else
|
||||||
|
-- if vim.fn["vsnip#available"](1) ~= 0 then
|
||||||
|
-- vim.fn.feedkeys(string.format('%c%c%c(vsnip-expand-or-jump)', 0x80, 253, 83))
|
||||||
|
-- return npairs.esc("")
|
||||||
|
-- else
|
||||||
|
-- return npairs.esc("<Tab>")
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- MUtils.s_tab = function()
|
||||||
|
-- if vim.fn.pumvisible() ~= 0 then
|
||||||
|
-- return npairs.esc("<C-p>")
|
||||||
|
-- else
|
||||||
|
-- if vim.fn["vsnip#jumpable"](-1) ~= 0 then
|
||||||
|
-- vim.fn.feedkeys(string.format('%c%c%c(vsnip-jump-prev)', 0x80, 253, 83))
|
||||||
|
-- return npairs.esc("")
|
||||||
|
-- else
|
||||||
|
-- return npairs.esc("<C-h>")
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- -- Autocompletion and snippets
|
||||||
|
-- vim.api.nvim_set_keymap('i', '<CR>', 'v:lua.MUtils.completion_confirm()', {expr = true, noremap = true})
|
||||||
|
-- -- imap("<CR>", "v:lua.MUtils.completion_confirm()", {expr = true, noremap = true})
|
||||||
|
-- imap("<Tab>", "v:lua.MUtils.tab()", {expr = true, noremap = true})
|
||||||
|
-- imap("<S-Tab>", "v:lua.MUtils.s_tab()", {expr = true, noremap = true})
|
||||||
|
|
||||||
|
local remap = vim.api.nvim_set_keymap
|
||||||
local npairs = require('nvim-autopairs')
|
local npairs = require('nvim-autopairs')
|
||||||
|
|
||||||
local function imap(lhs, rhs, opts)
|
-- skip it, if you use another global object
|
||||||
local options = {noremap = false}
|
_G.MUtils= {}
|
||||||
if opts then options = vim.tbl_extend('force', options, opts) end
|
|
||||||
vim.api.nvim_set_keymap('i', lhs, rhs, options)
|
|
||||||
end
|
|
||||||
|
|
||||||
_G.MUtils = {}
|
|
||||||
|
|
||||||
-- TEST
|
|
||||||
vim.g.completion_confirm_key = ""
|
vim.g.completion_confirm_key = ""
|
||||||
MUtils.completion_confirm = function()
|
MUtils.completion_confirm=function()
|
||||||
if vim.fn.pumvisible() ~= 0 then
|
if vim.fn.pumvisible() ~= 0 then
|
||||||
if vim.fn.complete_info()["selected"] ~= -1 then
|
if vim.fn.complete_info()["selected"] ~= -1 then
|
||||||
vim.fn["compe#confirm"]()
|
return vim.fn["compe#confirm"](npairs.esc("<cr>"))
|
||||||
-- return npairs.esc("<c-y>")
|
|
||||||
return npairs.esc("")
|
|
||||||
else
|
|
||||||
vim.defer_fn(function()
|
|
||||||
vim.fn["compe#confirm"]("<cr>")
|
|
||||||
end, 20)
|
|
||||||
return npairs.esc("<c-n>")
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
return npairs.check_break_line_char()
|
return npairs.esc("<cr>")
|
||||||
end
|
|
||||||
end
|
|
||||||
-- TEST
|
|
||||||
|
|
||||||
MUtils.completion_confirm = function()
|
|
||||||
if vim.fn.pumvisible() ~= 0 then
|
|
||||||
if vim.fn.complete_info()["selected"] ~= -1 then
|
|
||||||
vim.fn["compe#confirm"]()
|
|
||||||
return npairs.esc("")
|
|
||||||
else
|
|
||||||
vim.api.nvim_select_popupmenu_item(0, false, false, {})
|
|
||||||
vim.fn["compe#confirm"]()
|
|
||||||
return npairs.esc("<c-n>")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return npairs.check_break_line_char()
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
return npairs.autopairs_cr()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
MUtils.tab = function()
|
|
||||||
if vim.fn.pumvisible() ~= 0 then
|
|
||||||
return npairs.esc("<C-n>")
|
|
||||||
else
|
|
||||||
if vim.fn["vsnip#available"](1) ~= 0 then
|
|
||||||
vim.fn.feedkeys(string.format('%c%c%c(vsnip-expand-or-jump)', 0x80, 253, 83))
|
|
||||||
return npairs.esc("")
|
|
||||||
else
|
|
||||||
return npairs.esc("<Tab>")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
MUtils.s_tab = function()
|
remap('i' , '<CR>','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true})
|
||||||
if vim.fn.pumvisible() ~= 0 then
|
|
||||||
return npairs.esc("<C-p>")
|
|
||||||
else
|
|
||||||
if vim.fn["vsnip#jumpable"](-1) ~= 0 then
|
|
||||||
vim.fn.feedkeys(string.format('%c%c%c(vsnip-jump-prev)', 0x80, 253, 83))
|
|
||||||
return npairs.esc("")
|
|
||||||
else
|
|
||||||
return npairs.esc("<C-h>")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Autocompletion and snippets
|
|
||||||
vim.api.nvim_set_keymap('i', '<CR>', 'v:lua.MUtils.completion_confirm()', {expr = true, noremap = true})
|
|
||||||
-- imap("<CR>", "v:lua.MUtils.completion_confirm()", {expr = true, noremap = true})
|
|
||||||
imap("<Tab>", "v:lua.MUtils.tab()", {expr = true, noremap = true})
|
|
||||||
imap("<S-Tab>", "v:lua.MUtils.s_tab()", {expr = true, noremap = true})
|
|
||||||
|
|
|
@ -15,20 +15,20 @@ require'compe'.setup {
|
||||||
documentation = true,
|
documentation = true,
|
||||||
|
|
||||||
source = {
|
source = {
|
||||||
path = {kind = " "},
|
path = {kind = " (Path)"},
|
||||||
buffer = {kind = " "},
|
buffer = {kind = " (Buffer)"},
|
||||||
calc = {kind = " "},
|
calc = {kind = " (Calc)"},
|
||||||
vsnip = {kind = " "},
|
vsnip = {kind = " (Snippet)"},
|
||||||
nvim_lsp = {kind = " "},
|
nvim_lsp = {kind = " (LSP)"},
|
||||||
-- nvim_lua = {kind = " "},
|
-- nvim_lua = {kind = " "},
|
||||||
nvim_lua = false,
|
nvim_lua = false,
|
||||||
spell = {kind = " "},
|
spell = {kind = " (Spell)"},
|
||||||
tags = false,
|
tags = false,
|
||||||
vim_dadbod_completion = true,
|
vim_dadbod_completion = true,
|
||||||
-- snippets_nvim = {kind = " "},
|
-- snippets_nvim = {kind = " "},
|
||||||
-- ultisnips = {kind = " "},
|
-- ultisnips = {kind = " "},
|
||||||
-- treesitter = {kind = " "},
|
-- treesitter = {kind = " "},
|
||||||
emoji = {kind = " ﲃ ", filetypes={"markdown", "text"}}
|
emoji = {kind = " ﲃ (Emoji)", filetypes={"markdown", "text"}}
|
||||||
-- for emoji press : (idk if that in compe tho)
|
-- for emoji press : (idk if that in compe tho)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,56 @@ require'compe'.setup {
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
|
|
||||||
|
-- local t = function(str)
|
||||||
|
-- return vim.api.nvim_replace_termcodes(str, true, true, true)
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- local check_back_space = function()
|
||||||
|
-- local col = vim.fn.col('.') - 1
|
||||||
|
-- if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
|
||||||
|
-- return true
|
||||||
|
-- else
|
||||||
|
-- return false
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- -- Use (s-)tab to:
|
||||||
|
-- --- move to prev/next item in completion menuone
|
||||||
|
-- --- jump to prev/next snippet's placeholder
|
||||||
|
-- _G.tab_complete = function()
|
||||||
|
-- if vim.fn.pumvisible() == 1 then
|
||||||
|
-- return t "<C-n>"
|
||||||
|
-- elseif vim.fn.call("vsnip#available", {1}) == 1 then
|
||||||
|
-- return t "<Plug>(vsnip-expand-or-jump)"
|
||||||
|
-- elseif check_back_space() then
|
||||||
|
-- return t "<Tab>"
|
||||||
|
-- else
|
||||||
|
-- return vim.fn['compe#complete']()
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
-- _G.s_tab_complete = function()
|
||||||
|
-- if vim.fn.pumvisible() == 1 then
|
||||||
|
-- return t "<C-p>"
|
||||||
|
-- elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
|
||||||
|
-- return t "<Plug>(vsnip-jump-prev)"
|
||||||
|
-- else
|
||||||
|
-- return t "<S-Tab>"
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||||
|
-- vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||||
|
-- vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||||
|
-- vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local t = function(str)
|
local t = function(str)
|
||||||
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local check_back_space = function()
|
local check_back_space = function()
|
||||||
|
@ -76,24 +124,24 @@ end
|
||||||
--- move to prev/next item in completion menuone
|
--- move to prev/next item in completion menuone
|
||||||
--- jump to prev/next snippet's placeholder
|
--- jump to prev/next snippet's placeholder
|
||||||
_G.tab_complete = function()
|
_G.tab_complete = function()
|
||||||
if vim.fn.pumvisible() == 1 then
|
if vim.fn.pumvisible() == 1 then
|
||||||
return t "<C-n>"
|
return t "<C-n>"
|
||||||
elseif vim.fn.call("vsnip#available", {1}) == 1 then
|
elseif vim.fn.call("vsnip#available", {1}) == 1 then
|
||||||
return t "<Plug>(vsnip-expand-or-jump)"
|
return t "<Plug>(vsnip-expand-or-jump)"
|
||||||
elseif check_back_space() then
|
elseif check_back_space() then
|
||||||
return t "<Tab>"
|
return t "<Tab>"
|
||||||
else
|
else
|
||||||
return vim.fn['compe#complete']()
|
return vim.fn['compe#complete']()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
_G.s_tab_complete = function()
|
_G.s_tab_complete = function()
|
||||||
if vim.fn.pumvisible() == 1 then
|
if vim.fn.pumvisible() == 1 then
|
||||||
return t "<C-p>"
|
return t "<C-p>"
|
||||||
elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
|
elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
|
||||||
return t "<Plug>(vsnip-jump-prev)"
|
return t "<Plug>(vsnip-jump-prev)"
|
||||||
else
|
else
|
||||||
return t "<S-Tab>"
|
return t "<S-Tab>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||||
|
|
|
@ -83,6 +83,7 @@ return require("packer").startup(
|
||||||
require_plugin("nvim-lspconfig")
|
require_plugin("nvim-lspconfig")
|
||||||
require_plugin("lspsaga.nvim")
|
require_plugin("lspsaga.nvim")
|
||||||
require_plugin("nvim-lspinstall")
|
require_plugin("nvim-lspinstall")
|
||||||
|
require_plugin("friendly-snippets")
|
||||||
require_plugin("popup.nvim")
|
require_plugin("popup.nvim")
|
||||||
require_plugin("plenary.nvim")
|
require_plugin("plenary.nvim")
|
||||||
require_plugin("telescope.nvim")
|
require_plugin("telescope.nvim")
|
||||||
|
|
Loading…
Reference in a new issue