defx.nvim
defx.nvim is a dark powered plugin for Neovim/Vim to browse files. It replaces the deprecated vimfiler plugin.
nerdtree, vim 文件导航界经典工具.
defx.nvim 乃后起之秀,因为其异步特性,理论上较 nerdtree 更快(浏览特大型项目才会感知到).
安装
对于 neovim + vim-plug, 仅需添加如下一行:
Plug 'Shougo/defx.nvim', { 'do': ':UpdateRemotePlugins' }
defx.nvim 外部依赖 python, 确保 pynvim 有装.
$ pip3 install --user pynvim
使用
:Defx
然而, defx.nvim 强烈依赖自定义,默认状态非常简陋.
可根据 :help defx
帮助文档进行配置.
如何在左边栏显示
在 ~/.config/nvim/init.vim
中添加:
call defx#custom#option('_', {
\ 'winwidth': 30,
\ 'split': 'vertical',
\ 'direction': 'topleft',
\ 'show_ignored_files': 0,
\ 'buffer_name': '',
\ 'toggle': 1,
\ 'resume': 1
\ })
自定义快捷键
执行 :help defx
, 在帮助文档中查找 defx_my_settings, 其中有自定义的快捷键设置:
autocmd FileType defx call s:defx_my_settings()
function! s:defx_my_settings() abort
" Define mappings
setl nonu " 勿在 defx 栏显示行号
nnoremap <silent><buffer><expr> <CR> " 点击 enter 键打开
\ defx#is_directory() ?
\ defx#do_action('open_or_close_tree') :
\ defx#do_action('drop',)
nnoremap <silent><buffer><expr> c " 复制
\ defx#do_action('copy')
nnoremap <silent><buffer><expr> K " 新建文件夾
\ defx#do_action('new_directory')
nnoremap <silent><buffer><expr> N " 新建文件
\ defx#do_action('new_file')
endfunction
图标支持
安装 defx-icons.
defx-icons 依赖 nerd-fonts.
安装 nerd-fonts 之后,在 init.vim 中添加:
Plug 'kristijanhusak/defx-icons'
使用方法:
:Defx -columns=icons:indent:filename:type
可将其添加为快捷键:
nmap <silent> <leader>e :Defx -columns=indent:icons:filename:type<cr>
可再安裝 defx-git:
Plug 'kristijanhusak/defx-git'
修改快捷键为:
nmap <silent> <leader>e :Defx -columns=indent:icons:git:filename:type<cr>