Skip to content

Commit

Permalink
Use vim-vsnip for LSP snippet completion.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachbai committed Nov 24, 2020
1 parent 910b7db commit 774b7e3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 22 additions & 6 deletions vim/lua/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<CR>'
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
Expand All @@ -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
}
15 changes: 15 additions & 0 deletions vim/plugin/vim-vsnip.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
" 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> <Tab> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<Tab>'
smap <expr> <Tab> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<Tab>'
" Jump forward or backward
imap <expr> <C-f> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<C-f>'
imap <expr> <C-b> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<C-b>'
smap <expr> <C-f> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<C-f>'
smap <expr> <C-b> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<C-b>'

0 comments on commit 774b7e3

Please sign in to comment.