DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Nim IDE in NeoVim


Install nim language server PMunch/nimlsp with:

nimble install nimlsp

Add the following into init.vim:

" asyncomplete
inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr>    pumvisible() ? "\<C-y>" : "\<cr>"
imap <c-space> <Plug>(asyncomplete_force_refresh)

au User asyncomplete_setup call asyncomplete#register_source({
    \ 'name': 'nim',
    \ 'whitelist': ['nim'],
    \ 'completor': {opt, ctx -> nim#suggest#sug#GetAllCandidates({start, candidates -> asyncomplete#complete(opt['name'], ctx, start, candidates)})}
    \ })

" nim LSP
if executable('nimlsp')
   au User lsp_setup call lsp#register_server({
     \ 'name': 'nimlsp',
     \ 'cmd': {server_info->['nimlsp']},
     \ 'whitelist': ['nim'],
     \ })
endif

let g:lsp_log_verbose = 1
let g:lsp_log_file = expand('/tmp/vim-lsp.log')

" for asyncomplete.vim log
let g:asyncomplete_log_file = expand('/tmp/asyncomplete.log')

let g:asyncomplete_auto_popup = 1

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>" :
  \ asyncomplete#force_refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

Plug 'alaviss/nim.nvim'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'

As completion framework, prabirshrestha/asyncomplete.vim is written is pure vimscript. While Shougo/deoplete.nvim is written partly in Python, and depends on Python package pynvim. In conda or asdf environment this could be a problem when environment switching. So I prefer prabirshrestha/asyncomplete.vim to deoplete.

When a nim file is opened by neovim, /home/leo/.nimble/bin/nimlsp will start. It quits when the file is closed.

Now open a nim file and write some code. The intelligent help of static language is much better than dynamic languages.



Published

Feb 24, 2020

Last Updated

Feb 24, 2020

Category

Tech

Tags

  • lsp 1
  • nim 2
  • vim 92

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor