From 774b7e3fb1d6b90234edb005849d2fab1e4f92e1 Mon Sep 17 00:00:00 2001 From: Zach Bai <10970845+zachbai@users.noreply.github.com> Date: Tue, 24 Nov 2020 13:47:38 -0800 Subject: [PATCH] Use vim-vsnip for LSP snippet completion. --- tmux.conf | 2 +- vim/lua/lsp.lua | 28 ++++++++++++++++++++++------ vim/plugin/vim-vsnip.vim | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 vim/plugin/vim-vsnip.vim diff --git a/tmux.conf b/tmux.conf index 8987880..f19ab79 100644 --- a/tmux.conf +++ b/tmux.conf @@ -47,7 +47,7 @@ bind c new-window -c "#{pane_current_path}" # mouse mode set -g mouse on -bind -n C-F run "tmux new-window 'zsh -ci fs'" +bind -n C-g run "tmux new-window 'zsh -ci fs'" # Plugins installed via TPM. # None currently. diff --git a/vim/lua/lsp.lua b/vim/lua/lsp.lua index c4b23a7..2dbc22e 100644 --- a/vim/lua/lsp.lua +++ b/vim/lua/lsp.lua @@ -5,25 +5,39 @@ local onAttach = function(client) require'diagnostic'.on_attach(client) end +-- Completion settings +vim.o.completeopt='menuone,noinsert,noselect' +vim.g.completion_enable_snippet = 'vim-vsnip' +vim.g.completion_matching_strategy_list = {'exact', 'substring', 'fuzzy'} +vim.g.completion_confirm_key = '' +vim.g.completion_matching_ignore_case = true + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.snippetSupport = true + -- TS/JS nvimLsp.tsserver.setup{ - on_attach = onAttach; - root_dir = nvimLsp.util.root_pattern(".git", "package.json") + on_attach = onAttach, + root_dir = nvimLsp.util.root_pattern(".git", "package.json"), + capabilities = capabilities } -- JSON nvimLsp.jsonls.setup{ - on_attach = onAttach; + on_attach = onAttach, + capabilities = capabilities } -- Lua nvimLsp.sumneko_lua.setup{ - on_attach = onAttach; + on_attach = onAttach, + capabilities = capabilities } -- Viml nvimLsp.vimls.setup{ - on_attach = onAttach; + on_attach = onAttach, + capabilities = capabilities } -- Dart @@ -38,6 +52,8 @@ nvimLsp.vimls.setup{ -- -- cpp +-- Use vim-lsc for cpp until https://github.com/neovim/neovim/issues/12972 is resolved. nvimLsp.clangd.setup{ - on_attach = onAttach; + on_attach = onAttach, + capabilities = capabilities } diff --git a/vim/plugin/vim-vsnip.vim b/vim/plugin/vim-vsnip.vim new file mode 100644 index 0000000..3209dd7 --- /dev/null +++ b/vim/plugin/vim-vsnip.vim @@ -0,0 +1,15 @@ +" NOTE: You can use other key to expand snippet. + +" Expand +imap vsnip#expandable() ? '(vsnip-expand)' : '' +smap vsnip#expandable() ? '(vsnip-expand)' : '' + +" Expand or jump +imap vsnip#available(1) ? '(vsnip-expand-or-jump)' : '' +smap vsnip#available(1) ? '(vsnip-expand-or-jump)' : '' + +" Jump forward or backward +imap vsnip#jumpable(1) ? '(vsnip-jump-next)' : '' +imap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : '' +smap vsnip#jumpable(1) ? '(vsnip-jump-next)' : '' +smap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : ''