From b10a4b55000912008233cb8fb2ca9d72319ec1da Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 30 May 2022 21:15:48 +0800 Subject: [PATCH] feat(filetree): add user autocmd to override key binding --- config/plugins/defx.vim | 1 + config/plugins/nerdtree.vim | 1 + config/plugins/vimfiler.vim | 1 + docs/documentation.md | 20 ++++++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/config/plugins/defx.vim b/config/plugins/defx.vim index 55e3feee3..b00b267bf 100644 --- a/config/plugins/defx.vim +++ b/config/plugins/defx.vim @@ -173,6 +173,7 @@ function! s:defx_init() \ defx#get_context().winwidth + 10) nnoremap < defx#do_action('resize', \ defx#get_context().winwidth - 10) + doautocmd User DefxInit endf " in this function we should vim-choosewin if possible diff --git a/config/plugins/nerdtree.vim b/config/plugins/nerdtree.vim index 0f7f432c7..a39a502e6 100644 --- a/config/plugins/nerdtree.vim +++ b/config/plugins/nerdtree.vim @@ -38,6 +38,7 @@ function! s:nerdtreeinit() abort " nnoremap :silent! exe 'NERDTree' g:NERDTreeFileNode.GetSelected().path.str() nnoremap :call cursor(2, 1) nnoremap :call cursor(line('$'), 1) + doautocmd User NerdTreeInit endfunction function! s:paste_to_file_manager() abort diff --git a/config/plugins/vimfiler.vim b/config/plugins/vimfiler.vim index baa88858a..7eb259b73 100644 --- a/config/plugins/vimfiler.vim +++ b/config/plugins/vimfiler.vim @@ -108,6 +108,7 @@ function! s:vimfilerinit() nmap (vimfiler_smart_h) nmap (vimfiler_smart_l) nmap <2-LeftMouse> (vimfiler_expand_or_edit) + doautocmd User VimfilerInit endf function! s:vimfiler_vsplit() abort diff --git a/docs/documentation.md b/docs/documentation.md index 9b9b9bc85..5ed72b701 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -33,6 +33,7 @@ description: "General documentation about how to use SpaceVim, including the qui - [File tree](#file-tree) - [File tree navigation](#file-tree-navigation) - [Open file with file tree.](#open-file-with-file-tree) + - [Override filetree key bindings](#override-filetree-key-bindings) - [General usage](#general-usage) - [Native functions](#native-functions) - [Command line mode key bindings](#command-line-mode-key-bindings) @@ -954,6 +955,25 @@ If only one file buffer is opened, a file is opened in the active window, otherw | `s g` | open file in a vertically split window | | `s v` | open file in a horizontally split window | + +#### Override filetree key bindings + +If you want to override the default key bindings in filetree windows. You can use User autocmd in bootstrap function. for examples: + +```vim +function! myspacevim#before() abort + autocmd User NerdTreeInit + \ nnoremap :call + \ g:NERDTreeKeyMap.Invoke('o') +endfunction +``` + +Here is all the autocmd for filetree: + +- nerdtree: `User NerdTreeInit` +- defx: `User DefxInit` +- vimfiler: `User VimfilerInit` + ## General usage The following key bindings are the general key bindings for moving the cursor.