18
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

asyncomplete.vim を使い始めた

Last updated at Posted at 2018-10-06

もともと deoplete.nvim を使っていたけれど、私の環境(Windows10 Vim8)だと補完候補が表示されるまで一秒程度時間がかかるため asyncomplete.vim に移りました。

そこそこ快適に使えるようになるまで試行錯誤が必要だったので、そこらへんをコメントしてみます。
全体のコードは末尾へ。

前提

  • dein.vim を使って toml で設定を書いています。
  • lsp を使うために、python は pyls を、golang は go-langserver を別途インストールしています。

asyncomplete.vim 関連の依存関係

  • asyncomplete.vim
    • asyncomplete-buffer.vim
    • asyncomplete-file.vim
    • asyncomplete-necosyntax.vim
      • Shougo/neco-syntax
    • asyncomplete-necovim.vim
      • Shougo/neco-vim
    • prabirshrestha/asyncomplete-neosnippet.vim
      • Shougo/neosnippet.vim
        • Shougo/neosnippet-snippets
        • honza/vim-snippets
    • prabirshrestha/asyncomplete-lsp.vim
      • prabirshrestha/vim-lsp
        • prabirshrestha/async.vim

vimrc で augroup vimrc を定義している。

augroup vimrc
  autocmd!
augroup END

コメント

  • 数メガのテキストファイルを扱うことがあり、そのファイルに対して補完候補の収集がされないように、指定した filetype だけで補完が動くようにしています。
  let g:asyncomplete_enable_for_all = 0
  autocmd vimrc FileType autohotkey,autoit,cfg,git,go,groovy,java,javascript,python,snippet,toml,vim,vb,xsl call asyncomplete#enable_for_buffer()
  • 'whitelist': ['*']: whitelist は書いていなければ ['*'] 相当になると思ったけれど、そうならないこともあるようなのでそれぞれ書いています。

全体コード

[[plugins]]
repo = 'prabirshrestha/asyncomplete.vim'
on_ft = ['autohotkey', 'autoit', 'cfg', 'git', 'go', 'groovy', 'java', 'javascript', 'python', 'snippet', 'toml', 'vim', 'vb', 'xsl']
hook_add = '''
  " let g:asyncomplete_log_file = expand('~/_vim/.asyncomplete/log.log')
  let g:asyncomplete_enable_for_all = 0
  autocmd vimrc FileType autohotkey,autoit,cfg,git,go,groovy,java,javascript,python,snippet,toml,vim,vb,xsl call asyncomplete#enable_for_buffer()
'''

[[plugins]]
repo = 'prabirshrestha/asyncomplete-buffer.vim'
on_ft = ['autohotkey', 'autoit', 'cfg', 'git', 'go', 'groovy', 'java', 'javascript', 'python', 'snippet', 'toml', 'vim', 'vb', 'xsl']
hook_source = '''
  autocmd vimrc User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({
      \ 'name': 'buffer',
      \ 'priority': 5,
      \ 'whitelist': ['*'],
      \ 'completor': function('asyncomplete#sources#buffer#completor'),
      \ }))
'''

[[plugins]]
repo = 'prabirshrestha/asyncomplete-file.vim'
on_ft = ['autohotkey', 'autoit', 'cfg', 'git', 'go', 'groovy', 'java', 'javascript', 'python', 'snippet', 'toml', 'vim', 'vb', 'xsl']
hook_source = '''
  autocmd vimrc User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({
      \ 'name': 'file',
      \ 'priority': 3,
      \ 'whitelist': ['*'],
      \ 'completor': function('asyncomplete#sources#file#completor'),
      \ }))
'''

[[plugins]]
repo = 'prabirshrestha/asyncomplete-necosyntax.vim'
on_ft = ['autohotkey', 'autoit', 'cfg', 'git', 'go', 'groovy', 'java', 'javascript', 'python', 'snippet', 'toml', 'vim', 'vb', 'xsl']
depends = ['neco-syntax']
hook_source = '''
  autocmd vimrc User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#necosyntax#get_source_options({
      \ 'name': 'necosyntax',
      \ 'priority': 7,
      \ 'whitelist': ['*'],
      \ 'completor': function('asyncomplete#sources#necosyntax#completor'),
      \ }))
'''

[[plugins]]
repo = 'Shougo/neco-syntax'
lazy = 1

[[plugins]]
repo = 'prabirshrestha/asyncomplete-necovim.vim'
on_ft = ['vim']
depends = ['neco-vim']
hook_source = '''
  autocmd vimrc User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#necovim#get_source_options({
      \ 'name': 'necovim',
      \ 'whitelist': ['vim'],
      \ 'priority': 10,
      \ 'completor': function('asyncomplete#sources#necovim#completor'),
      \ }))
'''

[[plugins]]
repo = 'Shougo/neco-vim'
lazy = 1

[[plugins]]
repo = 'prabirshrestha/asyncomplete-neosnippet.vim'
on_ft = ['autohotkey', 'autoit', 'cfg', 'git', 'go', 'groovy', 'java', 'javascript', 'python', 'snippet', 'toml', 'vim', 'vb', 'xsl']
depends = ['neosnippet.vim']
hook_source = '''
  autocmd vimrc User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#neosnippet#get_source_options({
      \ 'name': 'neosnippet',
      \ 'whitelist': ['*'],
      \ 'priority': 9,
      \ 'completor': function('asyncomplete#sources#neosnippet#completor'),
      \ }))
'''

[[plugins]]
repo = 'Shougo/neosnippet.vim'
depends = 'neosnippet-snippets'
hook_source = '''
  " <TAB>: completion.
  inoremap <expr> <S-TAB> pumvisible() ? '<C-p>' : '<S-TAB>'

  " Plugin key-mappings.
  imap <C-k> <Plug>(neosnippet_expand_or_jump)
  smap <C-k> <Plug>(neosnippet_expand_or_jump)

  " SuperTab like snippets behavior.
  imap <expr> <TAB> neosnippet#jumpable() ? '<Plug>(neosnippet_expand_or_jump)' : pumvisible() ? '<C-n>' : '<TAB>'
  smap <expr> <TAB> neosnippet#jumpable() ? '<Plug>(neosnippet_expand_or_jump)' : '<TAB>'

  let g:neosnippet#data_directory = expand('~/_vim/.neosnippet')

  " Tell Neosnippet about the other snippets
  " gosnippets は vim-go がうまいことやってくれるはずだけど、なんかうまくいかないので直接追加。
  let g:neosnippet#snippets_directory = [
        \   '~/vimfiles/snippets',
        \   '~/_vim/dein/repos/github.com/honza/vim-snippets/snippets/',
        \   '~/_vim/dein/repos/github.com/fatih/vim-go/gosnippets/snippets/',
        \ ]
'''

[[plugins]]
repo = 'Shougo/neosnippet-snippets'

[[plugins]]
repo = 'honza/vim-snippets'
# snippets ファイルだけを使うので runtimepath へ追加しない
rtp = ''

[[plugins]]
repo = 'prabirshrestha/async.vim'

[[plugins]]
repo = 'prabirshrestha/vim-lsp'
hook_add = '''
  " hook_source だとうまく動かなかった

  if executable('pyls')
      autocmd vimrc User lsp_setup call lsp#register_server({
          \ 'name': 'pyls',
          \ 'cmd': {server_info->['pyls']},
          \ 'whitelist': ['python'],
          \ })
  endif
  if executable('go-langserver')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'go-langserver',
        \ 'cmd': {server_info->['go-langserver', '-gocodecompletion']},
        \ 'whitelist': ['go'],
        \ })
   endif
'''

[[plugins]]
repo = 'prabirshrestha/asyncomplete-lsp.vim'
on_ft = ['python', 'go']
depends = ['asyncomplete.vim', 'vim-lsp']

18
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?