nvim: modules: completion: Move key bindings in lua module
nvim-compe recently included instructions on using backspace and tab correctly. Include the same configuration.
This commit is contained in:
parent
9c889caa9a
commit
c5cd375c25
2 changed files with 41 additions and 16 deletions
|
@ -1,16 +0,0 @@
|
||||||
function! s:check_back_space() abort
|
|
||||||
let col = col('.') - 1
|
|
||||||
return !col || getline('.')[col - 1] =~ '\s'
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
inoremap <silent><expr> <TAB>
|
|
||||||
\ pumvisible() ? "\<C-n>" :
|
|
||||||
\ <SID>check_back_space() ? "\<TAB>" :
|
|
||||||
\ compe#complete()
|
|
||||||
|
|
||||||
inoremap <silent><expr> <CR> compe#confirm('<CR>')
|
|
||||||
inoremap <silent><expr> <C-e> compe#close('<C-e>')
|
|
||||||
|
|
||||||
" Use <Tab> and <S-Tab> to navigate through popup menu
|
|
||||||
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
|
|
||||||
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
local remap = vim.api.nvim_set_keymap
|
||||||
|
|
||||||
require'compe'.setup {
|
require'compe'.setup {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
autocomplete = true;
|
autocomplete = true;
|
||||||
|
@ -22,3 +24,42 @@ require'compe'.setup {
|
||||||
vsnip = false;
|
vsnip = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
_G.tab_complete = function()
|
||||||
|
if vim.fn.pumvisible() == 1 then
|
||||||
|
return t "<C-n>"
|
||||||
|
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>"
|
||||||
|
else
|
||||||
|
return t "<S-Tab>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
remap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||||
|
remap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||||
|
remap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||||
|
remap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||||
|
|
Loading…
Reference in a new issue