Vimfiler をIDEでよくある感じな感じでつかう
だいぶまえから設定しているけど、Vimfiler でいわゆるIDEツリー的に使うのも結構快適です。
設定のさんぷるは、以下。
let g:vimfiler_tree_leaf_icon = ' ' let g:vimfiler_tree_opened_icon = '▾' let g:vimfiler_tree_closed_icon = '▸' let g:vimfiler_file_icon = '-' let g:vimfiler_marked_file_icon = '*' command! -nargs=? -complete=file VimFilerTree call s:vimfiler_tree_launch(<f-args>) let s:org_scrolloff=-1 function! s:noscrolloff_leftmouse() if s:org_scrolloff < 0 let s:org_scrolloff = &scrolloff endif let &scrolloff = 0 exe 'normal!' "\<LeftMouse>" " let &scrolloff = org_scrolloff endfunction function! s:restore_noscrolloff() if s:org_scrolloff < 0 return endif let &scrolloff = s:org_scrolloff let s:org_scrolloff = -1 endfunction autocmd CursorMoved * call s:restore_noscrolloff() function! s:vimfiler_tree_launch(...) "{{{4 let fpath = a:0 > 0 ? a:1 : getcwd() execute 'VimFiler -toggle -split -direction=topleft -buffer-name=ftree -simple -winwidth=40 file:' . fpath endfunction function! s:vimfiler_smart_tree_h() "{{{4 let file = vimfiler#get_file() let cmd = "\<Plug>(vimfiler_smart_h)" if !empty(file) if file.vimfiler__is_opened let cmd = "\<Plug>(vimfiler_expand_tree)" elseif file.vimfiler__nest_level > 0 let nest_level = file.vimfiler__nest_level while 1 exe 'normal!' 'k' let file = vimfiler#get_file() if empty(file) || file.vimfiler__nest_level < nest_level " let cmd = "\<Plug>(vimfiler_expand_tree)" | break normal! ^ return endif endwhile endif endif exe 'normal' cmd normal! ^ endfunction function! s:vimfiler_tree_edit(method) "{{{4 " let file = vimfiler#get_file() " if empty(file) || empty(a:method) | return | endif " let path = file.action__path " wincmd p " execute a:method " exe 'edit' path if empty(a:method) | return | endif let linenr = line('.') let context = s:vimfiler_create_action_context(a:method, linenr) wincmd p " call vimfiler#mappings#do_action(a:method, linenr) call context.execute() unlet context endfunction function! s:vimfiler_smart_tree_l(method, ...) "{{{4 let file = vimfiler#get_file() if empty(file) if (a:0 > 0 && a:1 == 1) exe 'normal' "\<Plug>(vimfiler_smart_h)" endif return endif let path = file.action__path if file.vimfiler__is_directory if (a:0 > 0 && a:1 == 2) exe 'normal' "\<Plug>(vimfiler_smart_l)" else exe 'normal' "\<Plug>(vimfiler_expand_tree)" endif normal! ^ return endif call s:vimfiler_tree_edit(a:method) endfunction "}}} function! s:vimfiler_tree_tabopen() " {{{4 let bnr = bufnr('%') let linenr = line('.') let context = s:vimfiler_create_action_context('tabopen', linenr) call context.execute() unlet context silent! exe printf('vsplit +wincmd\ H\|wincmd\ l #%d', bnr) endfunction let s:vimfiler_context = {} " {{{4 function! s:vimfiler_context.new(...) let dict = get(a:000, 0, {}) return extend(dict, self) endfunction function! s:vimfiler_context.execute() call unite#mappings#do_action(self.action, self.files, { \ 'vimfiler__current_directory' : self.current_dir, \ }) endfunction function! s:vimfiler_create_action_context(action, ...) " {{{4 let cursor_linenr = get(a:000, 0, line('.')) let vimfiler = vimfiler#get_current_vimfiler() let marked_files = vimfiler#get_marked_files() if empty(marked_files) let marked_files = [ vimfiler#get_file(cursor_linenr) ] endif let context = s:vimfiler_context.new({ \ 'action' : a:action, \ 'files' : marked_files, \ 'current_dir' : vimfiler.current_dir, \ }) return context endfunction function! s:vimfiler_my_settings() " {{{3 if exists('b:vimfiler') if exists('b:vimfiler.context') && b:vimfiler.context.profile_name == 'ftree' nnoremap <silent><buffer> e :call <SID>vimfiler_tree_edit('open')<CR> nnoremap <silent><buffer> E :call <SID>vimfiler_tree_tabopen()<CR> nnoremap <silent><buffer> l :call <SID>vimfiler_smart_tree_l('')<CR> nnoremap <silent><buffer> <LeftMouse> <Esc>:set eventignore=all<CR>:call <SID>noscrolloff_leftmouse()<CR>:call <SID>vimfiler_smart_tree_l('', 1)<CR>:set eventignore=<CR> nnoremap <silent><buffer> <2-LeftMouse> <Esc>:set eventignore=all<CR>:call <SID>noscrolloff_leftmouse()<CR>::set eventignore=<CR>:call <SID>vimfiler_smart_tree_l('open', 2)<CR> nmap <buffer> L <Plug>(vimfiler_smart_l) nnoremap <silent><buffer> h :call <SID>vimfiler_smart_tree_h()<CR> endif endif endfunction
h でディレクトリ戻り or ディレクトリ閉じ、l でディレクトリ展開。
L は下位ディレクトリ移動です。
e/E は最後にアクティブなウィンドウで開く/タブで開くような挙動です。
マウスのだぶくりはディレクトリ開閉です。
b:vimfiler を使っていて、これって公式に触っていいの?という疑問はさておき、、、しばらくつかっておりますが、問題なく動作しております。
eventignore=all をしているのは、主にマウス関連の挙動調整です。
scrolloff とか設定していると、真ん中にきちゃったりしたりするので、それ用の対応策。
CursorMoved とか使わなくてもできるのかもしれないけど、僕の少ない vim 力だとこれで精一杯…(・´з`・)