102 lines
3.3 KiB
VimL
102 lines
3.3 KiB
VimL
let g:compe = {}
|
|
let g:compe.enabled = v:true
|
|
let g:compe.autocomplete = v:true
|
|
let g:compe.debug = v:false
|
|
let g:compe.min_length = 1
|
|
let g:compe.preselect = 'enable'
|
|
let g:compe.throttle_time = 80
|
|
let g:compe.source_timeout = 200
|
|
let g:compe.resolve_timeout = 800
|
|
let g:compe.incomplete_delay = 400
|
|
let g:compe.max_abbr_width = 100
|
|
let g:compe.max_kind_width = 100
|
|
let g:compe.max_menu_width = 100
|
|
let g:compe.documentation = v:true
|
|
|
|
let g:compe.source = {}
|
|
let g:compe.source.path = v:true
|
|
let g:compe.source.buffer = v:true
|
|
let g:compe.source.calc = v:true
|
|
let g:compe.source.nvim_lsp = v:true
|
|
let g:compe.source.nvim_lua = v:true
|
|
let g:compe.source.vsnip = v:true
|
|
let g:compe.source.ultisnips = v:true
|
|
let g:compe.source.luasnip = v:true
|
|
let g:compe.source.emoji = v:false
|
|
|
|
" NOTE: You can use other key to expand snippet.
|
|
|
|
|
|
" Expand
|
|
imap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
|
|
smap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
|
|
|
|
" Expand or jump
|
|
imap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
|
|
smap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
|
|
|
|
" Jump forward or backward
|
|
imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
|
|
smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
|
|
imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
|
|
smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
|
|
|
|
" Select or cut text to use as $TM_SELECTED_TEXT in the next snippet.
|
|
" See https://github.com/hrsh7th/vim-vsnip/pull/50
|
|
nmap s <Plug>(vsnip-select-text)
|
|
xmap s <Plug>(vsnip-select-text)
|
|
nmap S <Plug>(vsnip-cut-text)
|
|
xmap S <Plug>(vsnip-cut-text)
|
|
|
|
" " If you want to use snippet for multiple filetypes, you can `g:vsnip_filetypes` for it.
|
|
" let g:vsnip_filetypes = {}
|
|
" let g:vsnip_filetypes.javascriptreact = ['javascript']
|
|
" let g:vsnip_filetypes.typescriptreact = ['typescript']
|
|
|
|
lua << EOF
|
|
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 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
|
|
|
|
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})
|
|
|
|
--This line is important for auto-import
|
|
vim.api.nvim_set_keymap('i', '<cr>', 'compe#confirm("<cr>")', { expr = true })
|
|
vim.api.nvim_set_keymap('i', '<c-space>', 'compe#complete()', { expr = true })
|
|
EOF
|
|
|
|
let g:vsnip_snippet_dir = expand('~/.config/nvim/vsnips')
|
|
|