以前からdenite.nvimを愛用していたのですが、v3のアップデートでもろもろと変わったので、設定を修正するついでにfloating windowを活用するように修正しましたので、紹介します。
機能
:Dgrep
でgrep:Dresume
で検索結果を再度開く:Dnext
,:Dprev
で前後の検索結果へ移動
動作イメージ
.vimrc
augroup denite_filter
autocmd FileType denite calls:denite_my_settings()function!s:denite_my_settings() abort
nnoremap <silent><buffer><expr><CR> \ denite#do_map('do_action')
nnoremap <silent><buffer><expr>d \ denite#do_map('do_action','delete')
nnoremap <silent><buffer><expr>p \ denite#do_map('do_action','preview')
nnoremap <silent><buffer><expr>q \ denite#do_map('quit')
nnoremap <silent><buffer><expr>i \ denite#do_map('open_filter_buffer')
nnoremap <silent><buffer><expr><Space> \ denite#do_map('toggle_select').'j'endfunction
augroup END
" use floatinglets:denite_win_width_percent=0.85lets:denite_win_height_percent=0.7lets:denite_default_options={ \'split':'floating', \'winwidth': float2nr(&columns * s:denite_win_width_percent), \'wincol': float2nr((&columns -(&columns * s:denite_win_width_percent)) / 2), \'winheight': float2nr(&lines * s:denite_win_height_percent), \'winrow': float2nr((&lines -(&lines * s:denite_win_height_percent)) / 2), \'highlight_filter_background':'DeniteFilter', \'prompt':'$ ', \'start_filter':v:true, \}lets:denite_option_array=[]for[key, value]in items(s:denite_default_options)call add(s:denite_option_array,'-'.key.'='.value)endforcall denite#custom#option('default',s:denite_default_options)call denite#custom#var('file/rec','command', \['ag','--follow','--nocolor','--nogroup','-g',''])call denite#custom#filter('matcher/ignore_globs','ignore_globs', \['.git/','.ropeproject/','__pycache__/', \'venv/','images/','*.min.*','img/','fonts/'])" Ag command on grep sourcecall denite#custom#var('grep','command',['ag'])call denite#custom#var('grep','default_opts',['-i','--vimgrep'])call denite#custom#var('grep','recursive_opts',[])call denite#custom#var('grep','pattern_opt',[])call denite#custom#var('grep','separator',['--'])call denite#custom#var('grep','final_opts',[])" grep
command!-nargs=? Dgrep calls:Dgrep(<f-args>)functions:Dgrep(...)ifa:0>0
execute(':Denite -buffer-name=grep-buffer-denite grep -path='.a:1)else
execute(':Denite -buffer-name=grep-buffer-denite '.join(s:denite_option_array,' ').' grep')endifendfunction" show Denite grep results
command! Dresume execute(':Denite -resume -buffer-name=grep-buffer-denite '.join(s:denite_option_array,' ').'')" next Denite grep result
command! Dnext execute(':Denite -resume -buffer-name=grep-buffer-denite -cursor-pos=+1 -immediately '.join(s:denite_option_array,' ').'')" previous Denite grep result
command! Dprev execute(':Denite -resume -buffer-name=grep-buffer-denite -cursor-pos=-1 -immediately '.join(s:denite_option_array,' ').'')" keymapcall denite#custom#map('insert','<C-n>','<denite:move_to_next_line>','noremap')call denite#custom#map('insert','<C-p>','<denite:move_to_previous_line>','noremap')
環境
使用しているneovimのバージョンは下記です。
※floating windowを利用しているので、v0.4以上が必要です。
$ vi --version
NVIM v0.4.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
参考
[vim]denite.nvimのgrepの検索結果をquickfixみたいに移動する
【Vim】新しい Denite に爆速で対応する