Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow providing a descriptive text to the existing mapping without registering its rhs explicitly #2

Closed
tracyone opened this issue Sep 6, 2018 · 10 comments
Labels
enhancement New feature or request

Comments

@tracyone
Copy link
Contributor

tracyone commented Sep 6, 2018

let g:which_key_map['w'] = {
      \ 'name' : '+windows' ,
      \ 'w' : ['<C-W>w'     , 'other-window']          ,
      \ 'd' : ['<C-W>c'     , 'delete-window']         ,
      \ '-' : ['<C-W>s'     , 'split-window-below']    ,
      \ '|' : ['<C-W>v'     , 'split-window-right']    ,
      \ '2' : ['<C-W>v'     , 'layout-double-columns'] ,
      \ 'h' : ['<C-W>h'     , 'window-left']           ,
      \ 'j' : ['<C-W>j'     , 'window-below']          ,
      \ 'l' : ['<C-W>l'     , 'window-right']          ,
      \ 'k' : ['<C-W>k'     , 'window-up']             ,
      \ 'H' : ['<C-W>5<'    , 'expand-window-left']    ,
      \ 'J' : ['resize +5'  , 'expand-window-below']   ,
      \ 'L' : ['<C-W>5>'    , 'expand-window-right']   ,
      \ 'K' : ['resize -5'  , 'expand-window-up']      ,
      \ '=' : ['<C-W>='     , 'balance-window']        ,
      \ 's' : ['<C-W>s'     , 'split-window-below']    ,
      \ 'v' : ['<C-W>v'     , 'split-window-below']    ,
      \ '?' : ['Windows'    , 'fzf-window']            ,
      \ }

如上,dict的value,list变量的第一个元素,是指定快捷键的实现,这样就给配置带来了极大不方便。

如果能做到下面这种,自然是非常好:

let g:which_key_map['w'] = {
      \ 'name' : '+windows' ,
      \ 'w' :  'other-window'          ,
      \ 'd' :  'delete-window'         ,
      \ '-' :  'split-window-below'    ,
      \ '|' :  'split-window-right'    ,
      \ '2' :  'layout-double-columns' ,
      \ 'h' :  'window-left'           ,
      \ 'j' :  'window-below'          ,
      \ 'l' :  'window-right'          ,
      \ 'k' :  'window-up'             ,
      \ 'H' :  'expand-window-left'    ,
      \ 'J' :  'expand-window-below'   ,
      \ 'L' :  'expand-window-right'   ,
      \ 'K' :  'expand-window-up'      ,
      \ '=' :  'balance-window'        ,
      \ 's' :  'split-window-below'    ,
      \ 'v' :  'split-window-below'    ,
      \ '?' :  'fzf-window'            ,
      \ }

理由是,有的快捷键,后面是一大串

@liuchengxu
Copy link
Owner

That's possible, I'll find some time to take a closer look.

@liuchengxu liuchengxu changed the title 能否做到只配置指定快捷键的描述 Allow providing a descriptive text to the existing mapping without registering its rhs explicitly Sep 6, 2018
@spapas
Copy link
Contributor

spapas commented Sep 6, 2018

Hello @liuchengxu thanks for this plugin!

I'd like to also vote for this issue i.e allow to just add a description for the vim leader mappings to be shown on the menu without the need to redefine them.

Thanks!

@liuchengxu
Copy link
Owner

liuchengxu commented Sep 8, 2018

Please try this branch, which should support only register a description to an existing mapping. Any feedback is welcome.

@spapas
Copy link
Contributor

spapas commented Sep 8, 2018

Hello @liuchengxu , I tried the new branch and it seems to be working fine in gvim!

However, when I tried it in (command line) vim, after I press space and a key I see the following error:
Error detected while processing BufLeave Auto commands for "<buffer=3>": E464: Ambiguous use of user-defined command: V

I am not sure if it related, I've commented out my bufleave autocmd but I still get it. Also notice I am using windows.

@liuchengxu
Copy link
Owner

I need a minimal vimrc to reproduce.

@spapas
Copy link
Contributor

spapas commented Sep 8, 2018

Hello @liuchengxu here's a minimal vimrc that throws the error:

" Basic settings ---------------------- {{{
set nocompatible " Important
filetype plugin indent on " Enable ft
let mapleader = "\<Space>"
set timeout
set timeoutlen=500

" Toggle spelling
nnoremap <leader>sp :set spell!<CR>
" Reverse lines without changing unnamed register
nnoremap <Leader>sd "udd"up
" Clear search nightlight
nnoremap <Leader>sc :noh<CR>
" }}}

" Plugins --------------------- {{{
call plug#begin('~/vimfiles/plugged')
Plug 'liuchengxu/vim-which-key', { 'branch': 'allow-provide-description-only' }
call plug#end()
" }}}

" Other Plugin configuration ------------------ {{{
nnoremap <silent> <leader> :WhichKey '<Space>'<CR>
let g:which_key_map =  {}
let g:which_key_map.s = { 'name' : '+TEST' }
let g:which_key_map.s.p = 'Toggle spell'
let g:which_key_map.s.d = 'Change lines'
let g:which_key_map.s.c = 'Clear highlight'
call which_key#register('<Space>', "g:which_key_map")

" }}}

Please keep in mind that this error is only thrown in the command line vim, not in gvim and in Windows (I haven't tested in Linux).

@liuchengxu
Copy link
Owner

@spapas This miminal vimrc seemingly works well on my mac, both terminal vim and macvim. I will try to reproduce on Windows later when I get one.

@spapas
Copy link
Contributor

spapas commented Sep 8, 2018

Thanks @liuchengxu. Please notice that I also tested the main branch and it throws the same error when used with command line vim in windows. So it's not related to this branch but is a general error.

Should I open a new issue for that ?

@liuchengxu
Copy link
Owner

@spapas Feel free to file another issue.

@tracyone
Copy link
Contributor Author

tracyone commented Sep 8, 2018

暂时没有试出问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants