1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:40:05 +08:00

Add defx support (#2282)

This commit is contained in:
Wang Shidong 2019-03-10 20:49:12 +08:00 committed by GitHub
parent 714926260b
commit 7179777ff5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 345 additions and 175 deletions

View File

@ -498,6 +498,7 @@ let g:spacevim_colorscheme_default = 'desert'
let g:spacevim_simple_mode = 0 let g:spacevim_simple_mode = 0
"" ""
" The default file manager of SpaceVim. Default is 'vimfiler'. " The default file manager of SpaceVim. Default is 'vimfiler'.
" you can also use nerdtree or defx
let g:spacevim_filemanager = 'vimfiler' let g:spacevim_filemanager = 'vimfiler'
let g:spacevim_sidebar_direction = '' let g:spacevim_sidebar_direction = ''
@ -685,6 +686,7 @@ let g:spacevim_smartcloseignorewin = ['__Tagbar__' , 'vimfiler:default']
let g:spacevim_smartcloseignoreft = [ let g:spacevim_smartcloseignoreft = [
\ 'tagbar', \ 'tagbar',
\ 'vimfiler', \ 'vimfiler',
\ 'defx',
\ 'SpaceVimRunner', \ 'SpaceVimRunner',
\ 'SpaceVimREPL', \ 'SpaceVimREPL',
\ 'SpaceVimQuickFix', \ 'SpaceVimQuickFix',
@ -963,6 +965,9 @@ function! SpaceVim#welcome() abort
if exists(':VimFiler') == 2 if exists(':VimFiler') == 2
VimFiler VimFiler
wincmd p wincmd p
elseif exists(':Defx') == 2
Defx
wincmd p
endif endif
endif endif
endfunction endfunction

View File

@ -17,6 +17,8 @@ function! SpaceVim#layers#core#plugins() abort
call add(plugins, ['Shougo/vimfiler.vim',{'merged' : 0, 'loadconf' : 1 , 'loadconf_before' : 1, 'on_cmd' : ['VimFiler', 'VimFilerBufferDir']}]) call add(plugins, ['Shougo/vimfiler.vim',{'merged' : 0, 'loadconf' : 1 , 'loadconf_before' : 1, 'on_cmd' : ['VimFiler', 'VimFilerBufferDir']}])
call add(plugins, ['Shougo/unite.vim',{ 'merged' : 0 , 'loadconf' : 1}]) call add(plugins, ['Shougo/unite.vim',{ 'merged' : 0 , 'loadconf' : 1}])
call add(plugins, ['Shougo/vimproc.vim', {'build' : [(executable('gmake') ? 'gmake' : 'make')]}]) call add(plugins, ['Shougo/vimproc.vim', {'build' : [(executable('gmake') ? 'gmake' : 'make')]}])
elseif g:spacevim_filemanager ==# 'defx'
call add(plugins, ['Shougo/defx.nvim',{'merged' : 0, 'loadconf' : 1 , 'loadconf_before' : 1}])
endif endif
if !g:spacevim_vimcompatible if !g:spacevim_vimcompatible
@ -183,6 +185,12 @@ function! SpaceVim#layers#core#config() abort
call SpaceVim#mapping#space#def('nnoremap', ['f', 'T'], 'NERDTree', 'show_file_tree', 1) call SpaceVim#mapping#space#def('nnoremap', ['f', 'T'], 'NERDTree', 'show_file_tree', 1)
call SpaceVim#mapping#space#def('nnoremap', ['f', 'o'], 'NERDTreeFind', 'open_file_tree', 1) call SpaceVim#mapping#space#def('nnoremap', ['f', 'o'], 'NERDTreeFind', 'open_file_tree', 1)
call SpaceVim#mapping#space#def('nnoremap', ['b', 't'], 'NERDTree %', 'show_file_tree_at_buffer_dir', 1) call SpaceVim#mapping#space#def('nnoremap', ['b', 't'], 'NERDTree %', 'show_file_tree_at_buffer_dir', 1)
elseif g:spacevim_filemanager ==# 'defx'
" TODO: fix all these command
call SpaceVim#mapping#space#def('nnoremap', ['f', 't'], 'Defx', 'toggle_file_tree', 1)
call SpaceVim#mapping#space#def('nnoremap', ['f', 'T'], 'Defx -no-toggle', 'show_file_tree', 1)
call SpaceVim#mapping#space#def('nnoremap', ['f', 'o'], 'Defx -find', 'open_file_tree', 1)
call SpaceVim#mapping#space#def('nnoremap', ['b', 't'], 'Defx -no-toggle', 'show_file_tree_at_buffer_dir', 1)
endif endif
call SpaceVim#mapping#space#def('nnoremap', ['f', 'y'], 'call zvim#util#CopyToClipboard()', 'show-and-copy-buffer-filename', 1) call SpaceVim#mapping#space#def('nnoremap', ['f', 'y'], 'call zvim#util#CopyToClipboard()', 'show-and-copy-buffer-filename', 1)
let g:_spacevim_mappings_space.f.v = {'name' : '+Vim(SpaceVim)'} let g:_spacevim_mappings_space.f.v = {'name' : '+Vim(SpaceVim)'}

View File

@ -351,6 +351,9 @@ function! SpaceVim#layers#core#statusline#get(...) abort
\ . '%#SpaceVim_statusline_b#' \ . '%#SpaceVim_statusline_b#'
\ . ' vimfiler %#SpaceVim_statusline_b_SpaceVim_statusline_c#' \ . ' vimfiler %#SpaceVim_statusline_b_SpaceVim_statusline_c#'
\ . s:lsep \ . s:lsep
elseif &filetype ==# 'defx'
return '%#SpaceVim_statusline_ia#' . s:winnr(1) . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' . s:lsep
\ . '%#SpaceVim_statusline_b# defx %#SpaceVim_statusline_b_SpaceVim_statusline_c#' . s:lsep . ' '
elseif &filetype ==# 'gista-list' elseif &filetype ==# 'gista-list'
return '%#SpaceVim_statusline_ia#' return '%#SpaceVim_statusline_ia#'
\ . s:winnr(1) . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' \ . s:winnr(1) . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#'

View File

@ -114,4 +114,4 @@ function! s:search_line(path, term) abort "{{{
return 0 return 0
endfunction "}}} endfunction "}}}
" vim:set et sw=2: " vim:set et sw=2 cc=80 nowrap:

View File

@ -1,216 +1,218 @@
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
function! s:install_manager() abort function! s:install_manager() abort
" Fsep && Psep " Fsep && Psep
if has('win16') || has('win32') || has('win64') if has('win16') || has('win32') || has('win64')
let s:Psep = ';' let s:Psep = ';'
let s:Fsep = '\' let s:Fsep = '\'
else
let s:Psep = ':'
let s:Fsep = '/'
endif
" auto install plugin manager
if g:spacevim_plugin_manager ==# 'neobundle'
"auto install neobundle
if filereadable(expand(g:spacevim_plugin_bundle_dir)
\ . 'neobundle.vim'. s:Fsep. 'README.md')
let g:_spacevim_neobundle_installed = 1
else else
let s:Psep = ':' if executable('git')
let s:Fsep = '/' exec '!git clone '
\ .'https://github.com/'
\ .'Shougo/neobundle.vim'
\ . ' '
\ . fnameescape(g:spacevim_plugin_bundle_dir)
\ . 'neobundle.vim'
let g:_spacevim_neobundle_installed = 1
else
echohl WarningMsg
echom 'You need install git!'
echohl None
endif
endif endif
" auto install plugin manager exec 'set runtimepath+='
if g:spacevim_plugin_manager ==# 'neobundle' \ . fnameescape(g:spacevim_plugin_bundle_dir)
"auto install neobundle \ . 'neobundle.vim'
if filereadable(expand(g:spacevim_plugin_bundle_dir) elseif g:spacevim_plugin_manager ==# 'dein'
\ . 'neobundle.vim'. s:Fsep. 'README.md') "auto install dein
let g:_spacevim_neobundle_installed = 1 if filereadable(expand(g:spacevim_plugin_bundle_dir)
else \ . join(['repos', 'github.com',
if executable('git') \ 'Shougo', 'dein.vim', 'README.md'],
exec '!git clone ' \ s:Fsep))
\ .'https://github.com/' let g:_spacevim_dein_installed = 1
\ .'Shougo/neobundle.vim' else
\ . ' ' if executable('git')
\ . fnameescape(g:spacevim_plugin_bundle_dir) exec '!git clone https://github.com/Shougo/dein.vim "'
\ . 'neobundle.vim' \ . expand(g:spacevim_plugin_bundle_dir)
let g:_spacevim_neobundle_installed = 1 \ . join(['repos', 'github.com',
else \ 'Shougo', 'dein.vim"'], s:Fsep)
echohl WarningMsg let g:_spacevim_dein_installed = 1
echom 'You need install git!' else
echohl None echohl WarningMsg
endif echom 'You need install git!'
endif echohl None
exec 'set runtimepath+=' endif
\ . fnameescape(g:spacevim_plugin_bundle_dir)
\ . 'neobundle.vim'
elseif g:spacevim_plugin_manager ==# 'dein'
"auto install dein
if filereadable(expand(g:spacevim_plugin_bundle_dir)
\ . join(['repos', 'github.com',
\ 'Shougo', 'dein.vim', 'README.md'],
\ s:Fsep))
let g:_spacevim_dein_installed = 1
else
if executable('git')
exec '!git clone https://github.com/Shougo/dein.vim "'
\ . expand(g:spacevim_plugin_bundle_dir)
\ . join(['repos', 'github.com',
\ 'Shougo', 'dein.vim"'], s:Fsep)
let g:_spacevim_dein_installed = 1
else
echohl WarningMsg
echom 'You need install git!'
echohl None
endif
endif
exec 'set runtimepath+='. fnameescape(g:spacevim_plugin_bundle_dir)
\ . join(['repos', 'github.com', 'Shougo',
\ 'dein.vim'], s:Fsep)
elseif g:spacevim_plugin_manager ==# 'vim-plug'
"auto install vim-plug
if filereadable(expand('~/.cache/vim-plug/autoload/plug.vim'))
let g:_spacevim_vim_plug_installed = 1
else
if executable('curl')
exec '!curl -fLo '
\ . '~/.cache/vim-plug/autoload/plug.vim'
\ . ' --create-dirs '
\ . 'https://raw.githubusercontent.com/'
\ . 'junegunn/vim-plug/master/plug.vim'
let g:_spacevim_vim_plug_installed = 1
else
echohl WarningMsg
echom 'You need install curl!'
echohl None
endif
endif
exec 'set runtimepath+=~/.cache/vim-plug/'
endif endif
exec 'set runtimepath+='. fnameescape(g:spacevim_plugin_bundle_dir)
\ . join(['repos', 'github.com', 'Shougo',
\ 'dein.vim'], s:Fsep)
elseif g:spacevim_plugin_manager ==# 'vim-plug'
"auto install vim-plug
if filereadable(expand('~/.cache/vim-plug/autoload/plug.vim'))
let g:_spacevim_vim_plug_installed = 1
else
if executable('curl')
exec '!curl -fLo '
\ . '~/.cache/vim-plug/autoload/plug.vim'
\ . ' --create-dirs '
\ . 'https://raw.githubusercontent.com/'
\ . 'junegunn/vim-plug/master/plug.vim'
let g:_spacevim_vim_plug_installed = 1
else
echohl WarningMsg
echom 'You need install curl!'
echohl None
endif
endif
exec 'set runtimepath+=~/.cache/vim-plug/'
endif
endf endf
if get(g:,'spacevim_enable_plugins', 1) if get(g:,'spacevim_enable_plugins', 1)
call s:install_manager() call s:install_manager()
endif endif
function! zvim#plug#begin(path) abort function! zvim#plug#begin(path) abort
let g:unite_source_menu_menus.AddedPlugins = let g:unite_source_menu_menus.AddedPlugins =
\ {'description': \ {'description':
\ 'All the Added plugins' \ 'All the Added plugins'
\ . ' <leader>lp'} \ . ' <leader>lp'}
let g:unite_source_menu_menus.AddedPlugins.command_candidates = [] let g:unite_source_menu_menus.AddedPlugins.command_candidates = []
nnoremap <silent><Leader>lp :Unite -silent nnoremap <silent><Leader>lp :Unite -silent
\ -winheight=17 -start-insert menu:AddedPlugins<CR> \ -winheight=17 -start-insert menu:AddedPlugins<CR>
if g:spacevim_plugin_manager ==# 'neobundle' if g:spacevim_plugin_manager ==# 'neobundle'
call neobundle#begin(a:path) call neobundle#begin(a:path)
elseif g:spacevim_plugin_manager ==# 'dein' elseif g:spacevim_plugin_manager ==# 'dein'
call dein#begin(a:path) call dein#begin(a:path)
elseif g:spacevim_plugin_manager ==# 'vim-plug' elseif g:spacevim_plugin_manager ==# 'vim-plug'
call plug#begin(a:path) call plug#begin(a:path)
endif endif
endfunction endfunction
function! zvim#plug#end() abort function! zvim#plug#end() abort
if g:spacevim_plugin_manager ==# 'neobundle' if g:spacevim_plugin_manager ==# 'neobundle'
call neobundle#end() call neobundle#end()
if g:spacevim_checkinstall == 1 if g:spacevim_checkinstall == 1
silent! let g:_spacevim_checking_flag = neobundle#exists_not_installed_bundles() silent! let g:_spacevim_checking_flag = neobundle#exists_not_installed_bundles()
if g:_spacevim_checking_flag if g:_spacevim_checking_flag
augroup SpaceVimCheckInstall augroup SpaceVimCheckInstall
au! au!
au VimEnter * SPInstall au VimEnter * SPInstall
augroup END augroup END
endif endif
endif
elseif g:spacevim_plugin_manager ==# 'dein'
call dein#end()
if g:spacevim_checkinstall == 1
silent! let g:_spacevim_checking_flag = dein#check_install()
if g:_spacevim_checking_flag
augroup SpaceVimCheckInstall
au!
au VimEnter * SPInstall
augroup END
endif
endif
call dein#call_hook('source')
elseif g:spacevim_plugin_manager ==# 'vim-plug'
call plug#end()
endif endif
elseif g:spacevim_plugin_manager ==# 'dein'
call dein#end()
if g:spacevim_checkinstall == 1
silent! let g:_spacevim_checking_flag = dein#check_install()
if g:_spacevim_checking_flag
augroup SpaceVimCheckInstall
au!
au VimEnter * SPInstall
augroup END
endif
endif
call dein#call_hook('source')
elseif g:spacevim_plugin_manager ==# 'vim-plug'
call plug#end()
endif
endfunction endfunction
function! zvim#plug#defind_hooks(bundle) abort function! zvim#plug#defind_hooks(bundle) abort
if g:spacevim_plugin_manager ==# 'neobundle' if g:spacevim_plugin_manager ==# 'neobundle'
let s:hooks = neobundle#get_hooks(a:bundle) let s:hooks = neobundle#get_hooks(a:bundle)
func! s:hooks.on_source(bundle) abort func! s:hooks.on_source(bundle) abort
call zvim#util#source_rc('plugins/' . split(a:bundle['name'],'\.')[0] . '.vim') call zvim#util#source_rc('plugins/' . split(a:bundle['name'],'\.')[0] . '.vim')
endf endf
elseif g:spacevim_plugin_manager ==# 'dein' elseif g:spacevim_plugin_manager ==# 'dein'
call dein#config(g:dein#name, { call dein#config(g:dein#name, {
\ 'hook_source' : "call zvim#util#source_rc('plugins/" . split(g:dein#name,'\.')[0] . ".vim')" \ 'hook_source' : "call zvim#util#source_rc('plugins/" . split(g:dein#name,'\.')[0] . ".vim')"
\ }) \ })
endif endif
endfunction endfunction
function! zvim#plug#fetch() abort function! zvim#plug#fetch() abort
if g:spacevim_plugin_manager ==# 'neobundle' if g:spacevim_plugin_manager ==# 'neobundle'
NeoBundleFetch 'Shougo/neobundle.vim' NeoBundleFetch 'Shougo/neobundle.vim'
elseif g:spacevim_plugin_manager ==# 'dein' elseif g:spacevim_plugin_manager ==# 'dein'
call dein#add('Shougo/dein.vim') call dein#add('Shougo/dein.vim')
endif endif
endfunction endfunction
let s:plugins = [] let s:plugins = []
fu! s:parser(args) abort fu! s:parser(args) abort
return a:args return a:args
endf endf
let g:_spacevim_plugins = [] let g:_spacevim_plugins = []
function! zvim#plug#add(repo,...) abort function! zvim#plug#add(repo,...) abort
let g:spacevim_plugin_name = '' let g:spacevim_plugin_name = ''
if g:spacevim_plugin_manager ==# 'neobundle' if g:spacevim_plugin_manager ==# 'neobundle'
exec 'NeoBundle "'.a:repo.'"'.','.join(a:000,',') exec 'NeoBundle "'.a:repo.'"'.','.join(a:000,',')
let g:spacevim_plugin_name = split(a:repo, '/')[-1] let g:spacevim_plugin_name = split(a:repo, '/')[-1]
elseif g:spacevim_plugin_manager ==# 'dein' elseif g:spacevim_plugin_manager ==# 'dein'
if len(a:000) > 0 if len(a:000) > 0
call dein#add(a:repo,s:parser(a:000[0])) call dein#add(a:repo,s:parser(a:000[0]))
else else
call dein#add(a:repo) call dein#add(a:repo)
endif
let g:spacevim_plugin_name = g:dein#name
call add(g:_spacevim_plugins, g:dein#name)
elseif g:spacevim_plugin_manager ==# 'vim-plug'
if len(a:000) > 0
exec "Plug '".a:repo."', ".join(a:000,',')
else
exec "Plug '".a:repo."'"
endif
let g:spacevim_plugin_name = split(a:repo, '/')[-1]
endif endif
let str = get(g:,'_spacevim_plugin_layer', 'custom plugin') let g:spacevim_plugin_name = g:dein#name
let str = '[' . str . ']' call add(g:_spacevim_plugins, g:dein#name)
let str = str . repeat(' ', 25 - len(str)) elseif g:spacevim_plugin_manager ==# 'vim-plug'
exec 'call add(g:unite_source_menu_menus' if len(a:000) > 0
\ . '.AddedPlugins.command_candidates, ["'. str . '[' exec "Plug '".a:repo."', ".join(a:000,',')
\ . a:repo else
\ . (len(a:000) > 0 ? (']' exec "Plug '".a:repo."'"
\ . repeat(' ', 40 - len(a:repo)) endif
\ . '[lazy loaded] [' . string(a:000[0])) : '') let g:spacevim_plugin_name = split(a:repo, '/')[-1]
\ . ']","OpenBrowser https://github.com/' endif
\ . a:repo let str = get(g:,'_spacevim_plugin_layer', 'custom plugin')
\ . '"])' let str = '[' . str . ']'
call add(s:plugins, a:repo) let str = str . repeat(' ', 25 - len(str))
exec 'call add(g:unite_source_menu_menus'
\ . '.AddedPlugins.command_candidates, ["'. str . '['
\ . a:repo
\ . (len(a:000) > 0 ? (']'
\ . repeat(' ', 40 - len(a:repo))
\ . '[lazy loaded] [' . string(a:000[0])) : '')
\ . ']","OpenBrowser https://github.com/'
\ . a:repo
\ . '"])'
call add(s:plugins, a:repo)
endfunction endfunction
function! zvim#plug#tap(plugin) abort function! zvim#plug#tap(plugin) abort
if g:spacevim_plugin_manager ==# 'neobundle' if g:spacevim_plugin_manager ==# 'neobundle'
return neobundle#tap(a:plugin) return neobundle#tap(a:plugin)
elseif g:spacevim_plugin_manager ==# 'dein' elseif g:spacevim_plugin_manager ==# 'dein'
return dein#tap(a:plugin) return dein#tap(a:plugin)
endif endif
endfunction endfunction
function! zvim#plug#enable_plug() abort function! zvim#plug#enable_plug() abort
return g:_spacevim_neobundle_installed return g:_spacevim_neobundle_installed
\ || g:_spacevim_dein_installed \ || g:_spacevim_dein_installed
\ || g:_spacevim_vim_plug_installed \ || g:_spacevim_vim_plug_installed
endfunction endfunction
function! zvim#plug#loadPluginBefore(plugin) abort function! zvim#plug#loadPluginBefore(plugin) abort
if matchend(a:plugin, '.vim') == len(a:plugin) if matchend(a:plugin, "\\.vim") == len(a:plugin)
call zvim#util#source_rc('plugins_before/' . a:plugin) call zvim#util#source_rc('plugins_before/' . a:plugin)
else elseif matchend(a:plugin, "\\.nvim") == len(a:plugin)
call zvim#util#source_rc('plugins_before/' . a:plugin . '.vim') call zvim#util#source_rc('plugins_before/' . a:plugin[:-6] . '.vim')
endif else
call zvim#util#source_rc('plugins_before/' . a:plugin . '.vim')
endif
endfunction endfunction
let &cpo = s:save_cpo let &cpo = s:save_cpo

145
config/plugins/defx.vim Normal file
View File

@ -0,0 +1,145 @@
"=============================================================================
" defx.vim --- defx config
" Copyright (c) 2016-2017 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg at 163.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
" defx supported is added in https://github.com/SpaceVim/SpaceVim/pull/2282
let s:SYS = SpaceVim#api#import('system')
call defx#custom#option('_', {
\ 'winwidth': g:spacevim_sidebar_width,
\ 'split': 'vertical',
\ 'direction': 'botright',
\ 'show_ignored_files': 0,
\ 'buffer_name': '',
\ 'toggle': 1,
\ 'resume': 1
\ })
call defx#custom#column('mark', {
\ 'readonly_icon': '',
\ 'selected_icon': '',
\ })
call defx#custom#column('filename', {
\ 'directory_icon': '',
\ 'opened_icon': '',
\ })
augroup vfinit
au!
autocmd FileType defx call s:defx_init()
" auto close last defx windows
" autocmd BufEnter * nested if (!has('vim_starting')
" \ && winnr('$') == 1 && &filetype ==# 'vimfiler') |
" \ q | endif
augroup END
function! s:defx_init()
setl nonumber
setl norelativenumber
setl listchars=
silent! nunmap <buffer> <Space>
silent! nunmap <buffer> <C-l>
silent! nunmap <buffer> <C-j>
silent! nunmap <buffer> E
silent! nunmap <buffer> gr
silent! nunmap <buffer> gf
silent! nunmap <buffer> -
silent! nunmap <buffer> s
" nnoremap <silent><buffer><expr> st vimfiler#do_action('tabswitch')
" nnoremap <silent><buffer> yY :<C-u>call <SID>copy_to_system_clipboard()<CR>
nnoremap <silent><buffer><expr> '
\ defx#do_action('toggle_select') . 'j'
" TODO: we need an action to clear all selections
nnoremap <silent><buffer><expr> V
\ defx#do_action('toggle_select_all')
" nmap <buffer> v <Plug>(vimfiler_quick_look)
" nmap <buffer> p <Plug>(vimfiler_preview_file)
" nmap <buffer> i <Plug>(vimfiler_switch_to_history_directory)
" Define mappings
nnoremap <silent><buffer><expr> gx
\ defx#do_action('execute_system')
nnoremap <silent><buffer><expr> yy
\ defx#do_action('copy')
nnoremap <silent><buffer><expr> q
\ defx#do_action('quit')
nnoremap <silent><buffer><expr> m
\ defx#do_action('move')
nnoremap <silent><buffer><expr> P
\ defx#do_action('paste')
nnoremap <silent><buffer><expr> h defx#do_action('call', 'DefxSmartH')
nnoremap <silent><buffer><expr> <Left> defx#do_action('call', 'DefxSmartH')
nnoremap <silent><buffer><expr> l
\ defx#is_directory() ?
\ defx#do_action('open_tree') . 'j' : defx#do_action('open')
nnoremap <silent><buffer><expr> <Right>
\ defx#is_directory() ?
\ defx#do_action('open_tree') . 'j' : defx#do_action('open')
nnoremap <silent><buffer><expr> <Cr>
\ defx#is_directory() ?
\ defx#do_action('open_directory') : defx#do_action('drop')
nnoremap <silent><buffer><expr> <2-LeftMouse>
\ defx#is_directory() ?
\ defx#do_action('open_tree') : defx#do_action('drop')
nnoremap <silent><buffer><expr> sg
\ defx#do_action('drop', 'vsplit')
nnoremap <silent><buffer><expr> sv
\ defx#do_action('drop', 'split')
nnoremap <silent><buffer><expr> p
\ defx#do_action('open', 'pedit')
nnoremap <silent><buffer><expr> N
\ defx#do_action('new_file')
nnoremap <silent><buffer><expr> d
\ defx#do_action('remove')
nnoremap <silent><buffer><expr> r
\ defx#do_action('rename')
nnoremap <silent><buffer><expr> yy
\ defx#do_action('yank_path')
nnoremap <silent><buffer><expr> .
\ defx#do_action('toggle_ignored_files')
nnoremap <silent><buffer><expr> ~
\ defx#do_action('cd')
nnoremap <silent><buffer><expr> j
\ line('.') == line('$') ? 'gg' : 'j'
nnoremap <silent><buffer><expr> k
\ line('.') == 1 ? 'G' : 'k'
nnoremap <silent><buffer><expr> <C-r>
\ defx#do_action('redraw')
nnoremap <silent><buffer><expr> <C-g>
\ defx#do_action('print')
nnoremap <silent><buffer><expr> cd
\ defx#do_action('change_vim_cwd')
endf
function! DefxSmartH(_)
" candidate is opend tree?
if defx#is_opened_tree()
return defx#call_action('close_tree')
endif
" parent is root?
let s:candidate = defx#get_candidate()
let s:parent = fnamemodify(s:candidate['action__path'], s:candidate['is_directory'] ? ':p:h:h' : ':p:h')
let sep = s:SYS.isWindows ? '\\' : '/'
if s:trim_right(s:parent, sep) == s:trim_right(b:defx.paths[0], sep)
return defx#call_action('cd', ['..'])
endif
" move to parent.
call defx#call_action('search', s:parent)
" if you want close_tree immediately, enable below line.
call defx#call_action('close_tree')
endfunction
function! s:trim_right(str, trim)
return substitute(a:str, printf('%s$', a:trim), '', 'g')
endfunction

View File

@ -0,0 +1,2 @@
nnoremap <silent> <F3> :Defx<Cr>

View File

@ -566,7 +566,8 @@ plugins will be installed.
< <
*g:spacevim_filemanager* *g:spacevim_filemanager*
The default file manager of SpaceVim. Default is 'vimfiler'. The default file manager of SpaceVim. Default is 'vimfiler'. you can also use
nerdtree or defx
*g:spacevim_plugin_manager_processes* *g:spacevim_plugin_manager_processes*
Set the max process of SpaceVim plugin manager Set the max process of SpaceVim plugin manager

View File

@ -33,6 +33,7 @@ To use this configuration layer, update custom configuration file with:
SpaceVim uses remark to format Markdown file by default, but we suggest using [Prettier](https://github.com/prettier/prettier) on Windows. SpaceVim uses remark to format Markdown file by default, but we suggest using [Prettier](https://github.com/prettier/prettier) on Windows.
You can install remark via [npm](https://www.npmjs.com/get-npm), the commands are shown as below. You can install remark via [npm](https://www.npmjs.com/get-npm), the commands are shown as below.
```sh ```sh
npm -g install remark npm -g install remark
npm -g install remark-cli npm -g install remark-cli
@ -42,10 +43,13 @@ npm -g install remark-stringify
You can install [Prettier](https://github.com/prettier/prettier) via [yarn](https://yarnpkg.com/lang/zh-hans/docs/install/#windows-stable) or [npm](https://www.npmjs.com/get-npm), the commands are shown as below: You can install [Prettier](https://github.com/prettier/prettier) via [yarn](https://yarnpkg.com/lang/zh-hans/docs/install/#windows-stable) or [npm](https://www.npmjs.com/get-npm), the commands are shown as below:
1. Via `yarn` 1. Via `yarn`
```sh ```sh
yarn global add prettier yarn global add prettier
``` ```
2. Via `npm` 2. Via `npm`
```sh ```sh
npm install --global prettier npm install --global prettier
``` ```