個人的にVimでNimをいい感じに書けるようになったので書いておく。
いまからVimでNimを書く人の参考に。
こんなかんじ
環境
- Arch Linux
- nvim v0.4.2
プラグイン
暗黒パワー
- Shougo/dein.vim
- Shougo/context_filetype.vim
- Shougo/neomru.vim
- Shougo/neosnippet-snippets
- Shougo/neosnippet.vim
- Shougo/unite.vim
基本
Nim
- baabelfish/nvim-nim
シンタックスハイライトとか色々
LSP(Language Server Protocol)
- prabirshrestha/async.vim
- prabirshrestha/asyncomplete-buffer.vim
- prabirshrestha/asyncomplete-file.vim
- prabirshrestha/asyncomplete-lsp.vim
- prabirshrestha/asyncomplete-neosnippet.vim
- prabirshrestha/asyncomplete.vim
- prabirshrestha/vim-lsp
補完とかIDE的な環境
非同期コードチェック
- w0rp/ale
ステータスバー
- itchyny/lightline.vim
見た目とかいい感じに
- ryanoasis/vim-devicons
NerdFontが必要。
Arch LinuxだとAURにrictyのやつがあるから便利
https://aur.archlinux.org/packages/nerd-fonts-ricty/
init.vim
コンパイルと実行
init.vim
function! s:ExecThis()
:if expand("%:e") == "nim"
:execute "!nim c -r %"
:else
:execute "terminal " . &ft . " %"
:endif
:endfunction
map <silent> <C-p> :call <SID>ExecThis()<CR>
Ctrl+pで編集中のコードを実行
dein.toml
めんどくさくなったんでtoml晒す。
dein.toml
[[plugins]]
repo = 'Shougo/unite.vim'
hook_add = 'nnoremap <leader>f :<C-u>Unite buffer file file_mru<CR>'
lazy = 1
[[plugins]]
repo = 'Shougo/neomru.vim'
on_source = ['unite.vim']
lazy = 1
[[plugins]]
repo = 'cespare/vim-toml'
[[plugins]]
repo = 'tpope/vim-fugitive'
[[plugins]]
repo = 'w0rp/ale'
hook_add = '''
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 1
let g:ale_sign_error = ''
let g:ale_sign_warning = ''
nmap <silent> <C-j> <Plug>(ale_next_wrap)
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
'''
[[plugins]]
repo = 'osyo-manga/vim-precious'
depends = ['context_filetype.vim']
[[plugins]]
repo = 'Shougo/context_filetype.vim'
[[plugins]]
repo = 'prabirshrestha/async.vim'
[[plugins]]
repo = 'prabirshrestha/vim-lsp'
hook_add = '''
let g:lsp_async_completion = 1
'''
[[plugins]]
repo = 'prabirshrestha/asyncomplete-lsp.vim'
[[plugins]]
repo = 'prabirshrestha/asyncomplete.vim'
hook_add = '''
inoremap <expr><C-j> pumvisible() ? "\<C-n>" : "\<C-j>"
inoremap <expr><C-k> pumvisible() ? "\<C-p>" : "\<C-k>"
inoremap <expr> <cr> pumvisible() ? asyncomplete#close_popup()."\<CR>" : "\<CR>"
'''
[[plugins]]
repo = 'prabirshrestha/asyncomplete-buffer.vim'
hook_add = '''
call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({
\ 'name': 'buffer',
\ 'whitelist': ['*'],
\ 'blacklist': ['go'],
\ 'completor': function('asyncomplete#sources#buffer#completor'),
\ }))
'''
[[plugins]]
repo = 'yami-beta/asyncomplete-omni.vim'
hook_add = '''
call asyncomplete#register_source(asyncomplete#sources#omni#get_source_options({
\ 'name': 'omni',
\ 'whitelist': ['*'],
\ 'blacklist': ['c', 'cpp', 'html'],
\ 'completor': function('asyncomplete#sources#omni#completor')
\ }))
'''
[[plugins]]
repo = 'prabirshrestha/asyncomplete-file.vim'
hook_add = '''
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({
\ 'name': 'file',
\ 'whitelist': ['*'],
\ 'priority': 10,
\ 'completor': function('asyncomplete#sources#file#completor')
\ }))
'''
[[plugins]]
repo = 'Shougo/neosnippet.vim'
hook_add = '''
imap <C-o> <Plug>(neosnippet_expand_or_jump)
smap <C-o> <Plug>(neosnippet_expand_or_jump)
xmap <C-o> <Plug>(neosnippet_expand_target)
'''
[[plugins]]
repo = 'Shougo/neosnippet-snippets'
[[plugins]]
repo = 'prabirshrestha/asyncomplete-neosnippet.vim'
hook_add = '''
call asyncomplete#register_source(asyncomplete#sources#neosnippet#get_source_options({
\ 'name': 'neosnippet',
\ 'whitelist': ['*'],
\ 'completor': function('asyncomplete#sources#neosnippet#completor'),
\ }))
'''
[[plugins]]
repo = 'alaviss/nim.nvim'
on_ft = ['nim']
hook_add= '''
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)})}
\ })
'''
[[plugins]]
repo = 'ryanoasis/vim-devicons'
hook_add = '''
let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols = {} " needed
let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['nim'] = ''
'''
[[plugins]]
repo = 'scrooloose/nerdtree'
hook_add = '''
let g:NERDTreeWinPos = "right"
nnoremap <silent><C-e> :NERDTreeToggle<CR>
'''
[[plugins]]
repo = 'itchyny/lightline.vim'
hook_add = '''
let g:lightline = {
\ 'colorscheme': 'Tomorrow_Night_Blue',
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '', 'right': '' },
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ],
\ 'right': [ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype' ],
\ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_ok' ] ],
\ },
\ 'component': {
\ 'lineinfo': ' %3l:%-2v',
\ },
\ 'component_function': {
\ 'readonly': 'LightlineReadonly',
\ 'gitbranch': 'LightlineFugitive',
\ 'filetype': 'MyFiletype',
\ 'fileformat': 'MyFileformat',
\ },
\}
function! LightlineReadonly()
return &readonly ? '' : ''
endfunction
function! LightlineFugitive()
if exists('*fugitive#head')
let branch = fugitive#head()
return branch !=# '' ? ' '.branch : ''
endif
return ''
endfunction
function! MyFiletype()
return winwidth(0) > 70 ? (strlen(&filetype) ? &filetype . ' ' . WebDevIconsGetFileTypeSymbol() : 'no ft') : ''
endfunction
function! MyFileformat()
return winwidth(0) > 70 ? (&fileformat . ' ' . WebDevIconsGetFileFormatSymbol()) : ''
endfunction
'''
[[plugins]]
repo = 'maximbaz/lightline-ale'
depends = ['lightline.vim', 'ale']
hook_add = '''
let g:lightline.component_expand = {
\ 'linter_checking': 'lightline#ale#checking',
\ 'linter_warnings': 'lightline#ale#warnings',
\ 'linter_errors': 'lightline#ale#errors',
\ 'linter_ok': 'lightline#ale#ok',
\ }
let g:lightline.component_type = {
\ 'linter_checking': 'left',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error',
\ 'linter_ok': 'left',
\ }
let g:lightline#ale#indicator_checking = ""
let g:lightline#ale#indicator_warnings = " "
let g:lightline#ale#indicator_errors = " "
let g:lightline#ale#indicator_ok = ""
'''
[[plugins]]
repo = 'tpope/vim-surround'
[[plugins]]
repo = 'simeji/winresizer'
hook_add = '''
let g:winresizer_start_key = '<C-r>'
'''
以上です。