From be99bfda32cfbaeeffbb352b9a99bccd20626899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20BENO=C3=8ET?= Date: Sun, 18 Jun 2023 14:04:54 +0200 Subject: [PATCH] Handle keyboard shortcuts at plugin load time Don't load plugins based on keyboard shortcuts, as this conflicts with vim-which-key. Instead, create shortcuts when plugins are declared, and load them when the commands they provide are used. --- plugins/ctrlp.vim.cfg.vim | 4 ---- plugins/ctrlp.vim.load.vim | 8 +++++--- plugins/dein-ui.vim.cfg.vim | 3 --- plugins/dein-ui.vim.load.vim | 8 +++++--- plugins/nerdtree.cfg.vim | 1 - plugins/nerdtree.load.vim | 4 +++- plugins/undotree.cfg.vim | 3 --- plugins/undotree.load.vim | 4 +++- plugins/vim-which-key.post.vim | 1 - 9 files changed, 16 insertions(+), 20 deletions(-) delete mode 100644 plugins/dein-ui.vim.cfg.vim diff --git a/plugins/ctrlp.vim.cfg.vim b/plugins/ctrlp.vim.cfg.vim index 7fca27a..331583c 100644 --- a/plugins/ctrlp.vim.cfg.vim +++ b/plugins/ctrlp.vim.cfg.vim @@ -1,6 +1,2 @@ let g:ctrlp_working_path_mode = '' " Disable CtrlP-controlled chdir let g:ctrlp_map = '' " Disable default mapping - -nnoremap pp :CtrlPBuffer -nnoremap po :CtrlPMRUFiles -nnoremap pi :CtrlP diff --git a/plugins/ctrlp.vim.load.vim b/plugins/ctrlp.vim.load.vim index 4dd7ae3..2321c73 100644 --- a/plugins/ctrlp.vim.load.vim +++ b/plugins/ctrlp.vim.load.vim @@ -1,6 +1,8 @@ call dein#add('ctrlpvim/ctrlp.vim', #{ \ lazy: 1, - \ on_map: #{ - \ n: [ 'pi' , 'po', 'pp' ] - \ } + \ on_cmd: ['CtrlPBuffer', 'CtrlPMRUFiles', 'CtrlP'] \ }) + +nnoremap pp :CtrlPBuffer +nnoremap po :CtrlPMRUFiles +nnoremap pi :CtrlP diff --git a/plugins/dein-ui.vim.cfg.vim b/plugins/dein-ui.vim.cfg.vim deleted file mode 100644 index 6b34899..0000000 --- a/plugins/dein-ui.vim.cfg.vim +++ /dev/null @@ -1,3 +0,0 @@ -" Add key mappings for updates and installation -nnoremap Pu :DeinUpdate -nnoremap Pi :call CheckDeinInstall() diff --git a/plugins/dein-ui.vim.load.vim b/plugins/dein-ui.vim.load.vim index d41acde..5b773dc 100644 --- a/plugins/dein-ui.vim.load.vim +++ b/plugins/dein-ui.vim.load.vim @@ -1,6 +1,8 @@ call dein#add('wsdjeg/dein-ui.vim', #{ \ lazy: 1, - \ on_map: #{ - \ n: [ 'Pu' , 'Pi' ] - \ } + \ on_cmd: ['DeinUpdate'], \ }) + +" Add key mappings for updates and installation +nnoremap Pu :DeinUpdate +nnoremap Pi :call CheckDeinInstall() diff --git a/plugins/nerdtree.cfg.vim b/plugins/nerdtree.cfg.vim index 57e9dfd..5999e1f 100644 --- a/plugins/nerdtree.cfg.vim +++ b/plugins/nerdtree.cfg.vim @@ -1,6 +1,5 @@ " NERDTree: ' e' = toggle side bar let g:NERDTreeGitStatusUpdateOnWrite = 1 -nnoremap e :NERDTreeToggle " Set the bookmarks file's path let g:NERDTreeBookmarksFile = GetVardataPath( 'NTBookmarks' ) diff --git a/plugins/nerdtree.load.vim b/plugins/nerdtree.load.vim index 6a16b69..c63f007 100644 --- a/plugins/nerdtree.load.vim +++ b/plugins/nerdtree.load.vim @@ -1,4 +1,6 @@ call dein#add('scrooloose/nerdtree', #{ \ lazy: 1, - \ on_map: #{ n: ['e'] }, + \ on_cmd: [ 'NERDTree', 'NERDTreeToggle' ], \ }) + +nnoremap e :NERDTreeToggle diff --git a/plugins/undotree.cfg.vim b/plugins/undotree.cfg.vim index b408cbf..a2c9c1b 100644 --- a/plugins/undotree.cfg.vim +++ b/plugins/undotree.cfg.vim @@ -1,5 +1,2 @@ -" Keyboard shortcut -nnoremap u :UndotreeToggle - " Hide the sign column autocmd FileType undotree setlocal signcolumn=no diff --git a/plugins/undotree.load.vim b/plugins/undotree.load.vim index 77d4ced..7fa5901 100644 --- a/plugins/undotree.load.vim +++ b/plugins/undotree.load.vim @@ -1,4 +1,6 @@ call dein#add('mbbill/undotree', #{ \ lazy: 1 , - \ on_map: #{ n: [ 'u' ] }, + \ on_cmd: [ 'UndotreeShow', 'UndotreeToggle' ], \ }) + +nnoremap u :UndotreeToggle diff --git a/plugins/vim-which-key.post.vim b/plugins/vim-which-key.post.vim index 73ab423..4d84913 100644 --- a/plugins/vim-which-key.post.vim +++ b/plugins/vim-which-key.post.vim @@ -2,7 +2,6 @@ nnoremap :WhichKey '' let g:which_key_map = {} call which_key#register('', 'g:which_key_map') -let g:which_key_fallback_to_native_key = 1 " Direct commands let g:which_key_map[' '] = [ 'call feedkeys(":nohlsearch\n")' , 'clear-search' ]