defx.nvim

defx.nvim

defx.nvim is a dark powered plugin for Neovim/Vim to browse files. It replaces the deprecated vimfiler plugin.

nerdtree, 文件導航界經典工具.

defx.nvim 乃後起之秀,因爲其異步特性,理論上較 nerdtree 更快(瀏覽特大型項目才會感知到).

安裝

對於 neovim + vim-plug, 僅需添加如下一行:

Plug 'Shougo/defx.nvim', { 'do': ':UpdateRemotePlugins' }

defx.nvim 外部依賴 python, 確保 pynvim 有裝.

$ pip3 install --user pynvim

使用

:Defx

然而, defx.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>
posted @ 2021-04-07 20:01  银河系的小龙王  阅读(370)  评论(0)    收藏  举报