Code Monkey home page Code Monkey logo

vim-which-key's Introduction

vim-which-key

Introduction

vim-which-key is vim port of emacs-which-key that displays available keybindings in popup.

emacs-which-key started as a rewrite of guide-key, very likely, vim-which-key heavily rewrote vim-leader-guide. The features of vim-which-key has evolved a lot since then.


Vim config in the screenshot is space-vim.

Pros.

  • Better UI, vim's popup and neovim's floating_win are supported.
  • Show all mappings following a prefix, e.g., <leader>, <localleader>, etc.
  • Instant response for your every single input.
  • Dynamic update on every call.
  • Define group names and arbitrary descriptions.

Installation

Plugin Manager

Assuming you are using vim-plug:

Plug 'liuchengxu/vim-which-key'

" On-demand lazy load
Plug 'liuchengxu/vim-which-key', { 'on': ['WhichKey', 'WhichKey!'] }

" To register the descriptions when using the on-demand load feature,
" use the autocmd hook to call which_key#register(), e.g., register for the Space key:
" autocmd! User vim-which-key call which_key#register('<Space>', 'g:which_key_map')

For other plugin managers please refer to their document for more details.

Package management

Vim 8

$ mkdir -p ~/.vim/pack/git-plugins/start
$ git clone https://github.com/liuchengxu/vim-which-key.git --depth=1 ~/.vim/pack/git-plugins/start/vim-which-key

NeoVim

$ mkdir -p ~/.local/share/nvim/site/pack/git-plugins/start
$ git clone https://github.com/liuchengxu/vim-which-key.git --depth=1 ~/.local/share/nvim/site/pack/git-plugins/start/vim-which-key

Requirement

vim-which-key requires option timeout is on, see :h timeout.

Since timeout is on by default, all you need is not to set notimeout in your .vimrc.

Usage

timeoutlen

Let's say SPC is your leader key and you use it to trigger vim-which-key:

nnoremap <silent> <leader> :WhichKey '<Space>'<CR>

After pressing leader the guide buffer will pop up when there are no further keystrokes within timeoutlen.

" By default timeoutlen is 1000 ms
set timeoutlen=500

Pressing other keys within timeoutlen will either complete the mapping or open a subgroup. In the screenshot above SPCb will open up the buffer menu.

Please note that no matter which mappings and menus you configure, your original leader mappings will remain unaffected. The key guide is an additional layer. It will only activate, when you do not complete your input during the timeoutlen duration.

Special keys

  • Use BS to show the upper level mappings.

Configuration

  • For neovim, nvim-whichkey-setup.lua provides a wrapper around vim-which-key to simplify configuration in lua. It also solves issues (see #126) when the mapped command is more complex and makes it easy to also map localleader.

Minimal Configuration

:WhichKey and :WhichKeyVisual are the primary way of interacting with this plugin.

Assuming your leader and localleader key are <Space> and ,, respectively, even no description dictionary has been registered, all <Space> and , related mappings will be displayed regardless.

let g:mapleader = "\<Space>"
let g:maplocalleader = ','
nnoremap <silent> <leader>      :<c-u>WhichKey '<Space>'<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey  ','<CR>

The raw content displayed is normally not adequate to serve as a cheatsheet. See the following section for configuring it properly.

If no description dictionary is available, the right-hand-side of all mappings will be displayed:

The dictionary configuration is necessary to provide group names or a description text:

let g:which_key_map = {}
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']            ,
      \ }
call which_key#register('<Space>', "g:which_key_map")

If you wish to hide a mapping from the menu set it's description to 'which_key_ignore'. Useful for instance, to hide a list of [1-9] window swapping mappings. For example the below mapping will not be shown in the menu.

nnoremap <leader>1 :1wincmd w<CR>
let g:which_key_map.1 = 'which_key_ignore'

If you want to hide a group of non-top level mappings, set the name to 'which_key_ignore'. For example,

nnoremap <leader>_a :echom '_a'<CR>
nnoremap <leader>_b :echom '_b'<CR>
let g:which_key_map['_'] = { 'name': 'which_key_ignore' }

If you want to hide all mappings outside of the elements of the description dictionary, use: let g:which_key_ignore_outside_mappings = 1.

Example

You can configure a Dict for each prefix so that the display is more readable.

To make the guide pop up Register the description dictionary for the prefix first. Assuming Space is your leader key and the Dict for configuring Space is g:which_key_map:

nnoremap <silent> <leader> :<c-u>WhichKey '<Space>'<CR>
vnoremap <silent> <leader> :<c-u>WhichKeyVisual '<Space>'<CR>

call which_key#register('<Space>', "g:which_key_map")

The above registers the same description dictionary for both normal and visual modes. To use a separate description dictionary for each mode: add a third argument specifying which mode:

call which_key#register('<Space>', "g:which_key_map", 'n')
call which_key#register('<Space>', "g:which_key_map_visual", 'v')

The next step is to add items to g:which_key_map:

" Define prefix dictionary
let g:which_key_map =  {}

" Second level dictionaries:
" 'name' is a special field. It will define the name of the group, e.g., leader-f is the "+file" group.
" Unnamed groups will show a default empty string.

" =======================================================
" Create menus based on existing mappings
" =======================================================
" You can pass a descriptive text to an existing mapping.

let g:which_key_map.f = { 'name' : '+file' }

nnoremap <silent> <leader>fs :update<CR>
let g:which_key_map.f.s = 'save-file'

nnoremap <silent> <leader>fd :e $MYVIMRC<CR>
let g:which_key_map.f.d = 'open-vimrc'

nnoremap <silent> <leader>oq  :copen<CR>
nnoremap <silent> <leader>ol  :lopen<CR>
let g:which_key_map.o = {
      \ 'name' : '+open',
      \ 'q' : 'open-quickfix'    ,
      \ 'l' : 'open-locationlist',
      \ }

" =======================================================
" Create menus not based on existing mappings:
" =======================================================
" Provide commands(ex-command, <Plug>/<C-W>/<C-d> mapping, etc.)
" and descriptions for the existing mappings.
"
" Note:
" Some complicated ex-cmd may not work as expected since they'll be
" feed into `feedkeys()`, in which case you have to define a decicated
" Command or function wrapper to make it work with vim-which-key.
" Ref issue #126, #133 etc.
let g:which_key_map.b = {
      \ 'name' : '+buffer' ,
      \ '1' : ['b1'        , 'buffer 1']        ,
      \ '2' : ['b2'        , 'buffer 2']        ,
      \ 'd' : ['bd'        , 'delete-buffer']   ,
      \ 'f' : ['bfirst'    , 'first-buffer']    ,
      \ 'h' : ['Startify'  , 'home-buffer']     ,
      \ 'l' : ['blast'     , 'last-buffer']     ,
      \ 'n' : ['bnext'     , 'next-buffer']     ,
      \ 'p' : ['bprevious' , 'previous-buffer'] ,
      \ '?' : ['Buffers'   , 'fzf-buffer']      ,
      \ }

let g:which_key_map.l = {
      \ 'name' : '+lsp',
      \ 'f' : ['spacevim#lang#util#Format()'          , 'formatting']       ,
      \ 'r' : ['spacevim#lang#util#FindReferences()'  , 'references']       ,
      \ 'R' : ['spacevim#lang#util#Rename()'          , 'rename']           ,
      \ 's' : ['spacevim#lang#util#DocumentSymbol()'  , 'document-symbol']  ,
      \ 'S' : ['spacevim#lang#util#WorkspaceSymbol()' , 'workspace-symbol'] ,
      \ 'g' : {
        \ 'name': '+goto',
        \ 'd' : ['spacevim#lang#util#Definition()'     , 'definition']      ,
        \ 't' : ['spacevim#lang#util#TypeDefinition()' , 'type-definition'] ,
        \ 'i' : ['spacevim#lang#util#Implementation()' , 'implementation']  ,
        \ },
      \ }

The guide will be up to date at all times. Native vim mappings will always take precedence over dictionary-only mappings.

It is possible to call the guide for keys other than leader:

nnoremap <localleader> :<c-u>WhichKey  ','<CR>
vnoremap <localleader> :<c-u>WhichKeyVisual  ','<CR>
  • Refer to space-vim for more detailed example.

Hide statusline

Since the theme of provided statusline is not flexible and all the information has been echoed already, I prefer to hide it.

autocmd! FileType which_key
autocmd  FileType which_key set laststatus=0 noshowmode noruler
  \| autocmd BufLeave <buffer> set laststatus=2 showmode ruler

Commands

See more details about commands and options via :h vim-which-key.

Command Description
:WhichKey {prefix} Open the guide window for the given prefix
:WhichKey! {dict} Open the guide window for a given dictionary directly

Options

Variable Default Description
g:which_key_vertical 0 show popup vertically
g:which_key_position botright split a window at the bottom
g:which_key_hspace 5 minimum horizontal space between columns
g:which_key_centered 1 make all keybindings centered in the middle

FAQ

How to map some special keys like <BS>?

See #178.

How to set keybindings on filetype or other condition?

You may use BufEnter/BufLeave #132, a dictionary-function #209, or [experimental] setup per buffer #48.

How to map lua functions?

This is possible via nvim-whichkey-setup.lua. For example, if one wanted to map spectre's open to <leader>S, which in vimscipt would be nnoremap <leader>S <cmd>lua require('spectre').open()<CR>, one could use the following in one's init.vim:

lua<<EOF
local wk = require('whichkey_setup')

local keymap = {
    S = {':lua require("spectre").open()<CR>', 'Search'},
}

wk.register_keymap('leader', keymap)
EOF

NB that keymaps can only be registered once. The entirety of one's vim-which-key configuration must be ported to nvim-whichkey-setup.lua in order to enable this functionality.

Credit

vim-which-key's People

Contributors

0x450x6c avatar 2019342a avatar acdifran avatar acksld avatar aelkazdadi avatar antoinemadec avatar brglng avatar brotifypacha avatar burnettk avatar chandlercjy avatar freed-wu avatar guillaumeallain avatar haletsky avatar indexxuan avatar jeffhertzler avatar leoatchina avatar liuchengxu avatar mayrixon avatar mmrwoods avatar qadzek avatar rene-descartes2021 avatar spapas avatar spinks avatar svvac avatar thisisrandy avatar tracyone avatar tseeker avatar twistoy avatar yatesco avatar z0rc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-which-key's Issues

what is the use of timeoutlen ? Why setting it to 10 break gcc commentary ?

Hello,
Using neovim, with tpope commentary and which-key.
I set up timeoutlen to 10, because 500 was a bit slow, but now it broke gcc mapping from tpope commentary plugin.
I tryed to put it to 300, and now it fells like I have to press gcc in less than 0,3s to make it work.
Can you please explain what is the meaning of timeoutlen and why it has to exist ?
Coming form spacemacs its seems that both space-menu and gcc could live together without the need of a timeoulen variable.
Thanks for your work !

Different mappings depending on normal/visual mode

  • OS: Ubuntu 18.04

  • Vim:

VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 22 2018 11:42:48)
Included patches: 1-369
Modified by [email protected]
Compiled by [email protected]
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     +tag_old_static
+arabic            +farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    +tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
+balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
+browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +timers
+byte_offset       -hangul_input      +num64             +title
+channel           +iconv             +packages          +toolbar
+cindent           +insert_expand     +path_extra        +user_commands
+clientserver      +job               +perl              +vartabs
+clipboard         +jumplist          +persistent_undo   +vertsplit
+cmdline_compl     +keymap            +postscript        +virtualedit
+cmdline_hist      +lambda            +printer           +visual
+cmdline_info      +langmap           +profile           +visualextra
+comments          +libcall           -python            +viminfo
+conceal           +linebreak         +python3           +vreplace
+cryptv            +lispindent        +quickfix          +wildignore
+cscope            +listcmds          +reltime           +wildmenu
+cursorbind        +localmap          +rightleft         +windows
+cursorshape       +lua               +ruby              +writebackup
+dialog_con_gui    +menu              +scrollbind        +X11
+diff              +mksession         +signs             -xfontset
+digraphs          +modify_fname      +smartindent       +xim
+dnd               +mouse             +startuptime       +xpm
-ebcdic            +mouseshape        +statusline        +xsmp_interact
+emacs_tags        +mouse_dec         -sun_workshop      +xterm_clipboard
+eval              +mouse_gpm         +syntax            -xterm_save
+ex_extra          -mouse_jsbterm     +tag_binary        
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time  -g -O2 -fdebug-prefix-map=/build/vim-u2a9M3/vim-8.1.0369=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.26/CORE -lperl -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu -lpython3.6m -lpthread -ldl -lutil -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-2.5 -lpthread -lgmp -ldl -lcrypt -lm

Problem Description

Is there an option to define different mappings for same combination depending on whether it's visual or normal mode?

For example Zeavim defines its mappings like this: https://github.com/KabbAmine/zeavim.vim#mapping-. But in my case I disable them and compose which_key_map myself. So I need to replicate similar behavior within which-key configuration.

Vim:E492: Not an editor command: GVgg

  • OS: Arch linux

  • Vim: NVIM v0.3.4

Problem Description

Hi. i use these mapping:

let g:which_key_map.g = {
            \ 'name' : '+file' ,
            \ 'c' : ['d'            , 'Cut']     ,
            \ 'o' : ['e $MYVIMRC'   , 'Open vimrc']     ,
            \ 's' : ['w'            , 'Save']    ,
            \ 'x' : ['GVgg'        , 'Select whole file']     ,
            \ }

Everything works except when i hit: leader+g+x and it says:
Vim:E492: Not an editor command: GVgg
tip: it actually select whole file in normal mode.

Error

  • OS: linux
  • Vim: neovim 0.3.2, vim 8.0 (everywhere)

Problem Description

Error detected while processing function which_key#start[46]..which_key#window#open[3]..which_key#win
dow#fill[6]..which_key#util#create_rows:
line   54:
E684: list index out of range: 30
E116: Invalid arguments for function len
E15: Invalid expression: i < len(rows[j])

Vim(call):E107: Missing parentheses

  • OS: mac

  • Vim: vim8

If you think it's a bug, please provide a minimal vimrc to reproduce:

let g:which_key_map.e = {
            \'name': 'Edit',
            \'f': {
                \'name': 'File',
                \'c': ['let @+=expand("%:f")', 'Copy File Name With Path'],
                \}
            \}

Problem Description

when call <leader>efc,it show:

Vim(call):E107: Missing parentheses: let @+=expand("%:f")

errors when use alt key as m

  • OS: debian9, ubuntu18.04, macOS 10.13.6

  • Vim: neovim0.3.1+ (vim , gvim works mainly well)

If you think it's a bug, please provide a minimal vimrc to reproduce:

My config is here leoatchina-vim
I alias alt to meta as an import key like ctrl according to skywind3000's Vim 中正确使用 Alt映射, but only alias it when use vim, notice that not set alt as esc+ for nvim since it is built in

function! Alt_meta_map()
    set ttimeout
    if $TMUX != ''
        set ttimeoutlen=20
    elseif &ttimeoutlen > 60 || &ttimeoutlen <= 0
        set ttimeoutlen=60
    endif
    map ÏP <F1>
    map ÏQ <F2>
    map ÏR <F3>
    map ÏS <F4>
    inoremap ÏP <Nop>
    inoremap ÏQ <Nop>
    inoremap ÏR <Nop>
    inoremap ÏS <Nop>
    inoremap <F5> <Nop>
    inoremap <F6> <Nop>
    inoremap <F7> <Nop>
    inoremap <F8> <Nop>
    inoremap <F9> <Nop>
    inoremap <F10> <Nop>
    inoremap <F11> <Nop>
    inoremap <F12> <Nop>
    function! s:metacode(key) # import here
        if has('gui_macvim')
            exec "map <D-".a:key."> <M-".a:key.">"
            exec "imap <D-".a:key."> <Nop>"
        elseif !(has('nvim') || has('gui_running') && !OSX())   # not for nvim
            exec "set <M-".a:key.">=\e".a:key
            exec "imap <M-".a:key."> <Nop>"
        else
            exec "imap <M-".a:key."> <Nop>"
        endif
    endfunction
    for i in range(26)
        call s:metacode(nr2char(char2nr('a') + i))
        call s:metacode(nr2char(char2nr('A') + i))
    endfor
    let s:list = [',', '.', ';', ':', '/', '?', '{', '}', '-', '_']
    for c in s:list
        call s:metacode(c)
    endfor
    if has('gui_macvim')
        nnoremap <D-1> :tabn1<CR>
        nnoremap <D-2> :tabn2<CR>
        nnoremap <D-3> :tabn3<CR>
        nnoremap <D-4> :tabn4<CR>
        nnoremap <D-5> :tabn5<CR>
        nnoremap <D-6> :tabn6<CR>
        nnoremap <D-7> :tabn7<CR>
        nnoremap <D-8> :tabn8<CR>
        nnoremap <D-9> :tabn9<CR>
        nnoremap <D-0> :tablast<CR>
    else
        for i in range(10)
            call s:metacode(nr2char(char2nr('0') + i))
        endfor
        nnoremap <M-1> :tabn1<CR>
        nnoremap <M-2> :tabn2<CR>
        nnoremap <M-3> :tabn3<CR>
        nnoremap <M-4> :tabn4<CR>
        nnoremap <M-5> :tabn5<CR>
        nnoremap <M-6> :tabn6<CR>
        nnoremap <M-7> :tabn7<CR>
        nnoremap <M-8> :tabn8<CR>
        nnoremap <M-9> :tabn9<CR>
        nnoremap <M-0> :tablast<CR>
        nnoremap <M-c> "*y
        xnoremap <M-c> "*y
        nnoremap <M-x> "*x
        xnoremap <M-x> "*x
        nnoremap <M-v> "*gP
        xnoremap <M-v> "*gP
        inoremap <M-v> <C-r>*
        cnoremap <M-v> <C-r>*
    endif
    inoremap <M-w> <ESC>
    inoremap <M-q> <ESC>
    cnoremap <M-w> <ESC>
    cnoremap <M-q> <ESC>
endfunction
call Alt_meta_map()

M-s raise errors

nnoremap <M-s>n :set invrelativenumber<CR>
" togglePaste
nnoremap <M-s>p :set nopaste! nopaste?<CR>
" toggleFold
nnoremap <M-s>f :set nofoldenable! nofoldenable?<CR>
" toggleWrap
nnoremap <M-s>w :set nowrap! nowrap?<CR>
" toggleTrueclore
nnoremap <M-s>t :set notermguicolors! notermguicolors?<CR>
" toggle highlight
nnoremap <M-s>h :set nohlsearch! nohlsearch?<CR>
" indent_guides
if HasDirectory("vim-indent-guides")
   let g:indent_guides_enable_on_vim_startup = 0
   nnoremap <M-s>i :IndentGuidesToggle<Cr>
endif
" which-key
if HasDirectory("vim-which-key")
   set timeoutlen=300
   nnoremap <silent> <M-s> :<c-u>WhichKey '<M-s>'<CR>
endif

M-o, for lsp , errors

nmap <M-N>  :call LanguageClient#textDocument_hover()<CR>
nmap <M-o>d :call LanguageClient#textDocument_definition()<CR>
nmap <M-o>= :sp<CR>:call LanguageClient#textDocument_definition()<CR>
nmap <M-o>\ :vs<CR>:call LanguageClient#textDocument_definition()<CR>
nmap <M-o>t :call LanguageClient#textDocument_typeDefinition()<CR>
nmap <M-o>r :call LanguageClient#textDocument_references()<CR>
nmap <M-o>l :call LanguageClient#contextMenu()<CR>
nmap <M-o>n :call LanguageClient#textDocument_rename()<CR>
nmap <M-o>i :call LanguageClient#textDocument_implementation()<CR>
nmap <M-o>s :call LanguageClient#textDocument_documentSymbol(()<CR>

M-g works for vim, seems good for nvim, but actually it is the same as g

" fugitive
if HasDirectory("vim-fugitive")
    nnoremap <M-G>     :Gcommit -a -v<CR>
    nnoremap <M-g><Cr> :Git<Space>
    if HasDirectory('gv.vim')
        nnoremap <M-g>' :GV<CR>
    endif
endif
if HasDirectory('vim-signify')
    nnoremap <M-g>\ :SignifyDiff<Cr>
    nnoremap <M-g>/ :Signify
endif

Vim8
image

Nvim
image

<C-p> for leaderf/fzf, neigher vim8 nor nvim not work
It seems cannot hook ctrl + other key ?
image

if HasDirectory("LeaderF")
    let g:Lf_ShortcutF = '<C-p><C-p>'
    let g:Lf_ShortcutB = '<C-p>b'
    let g:Lf_ReverseOrder = 0
    let g:Lf_PythonVersion = g:python_version
    let g:Lf_CacheDirectory = expand("~/.cache/leaderf")
    let g:Lf_DefaultMode = 'Fuzzy'
    if !isdirectory(g:Lf_CacheDirectory)
        silent! call mkdir(g:Lf_CacheDirectory, 'p')
    endif
    let g:Lf_WildIgnore = {
            \ 'dir': ['.svn','.git','.hg'],
            \ 'file': ['*.sw?','~$*','*.bak','*.exe','*.o','*.so','*.py[co]']
        \}
    nnoremap T      :Leaderf bufTag<cr>
    nnoremap <C-p>l :Leaderf line<cr>
    nnoremap <C-p>f :Leaderf function<cr>
    nnoremap <C-p>m :Leaderf marks<cr>
    nnoremap <C-p>c :Leaderf colorscheme --reverse<Cr>
    nnoremap <C-p>h :Leaderf cmdHistory --reverse<Cr>
    nnoremap <C-p>H :Leaderf history --reverse<Cr>
    nnoremap <C-p>p :Leaderf
    nnoremap <C-p>F :LeaderfF
    nnoremap <C-p>M :LeaderfM
    nnoremap <C-p>B :LeaderfB
    nnoremap <C-p>F :set syntax=
    nnoremap <C-p> :<c-u>WhichKey '<C-p>'<CR>
elseif HasDirectory("fzf.vim")
    nnoremap <C-p><C-p> :Files<CR>
    nnoremap T      :BTags<CR>
    nnoremap <C-p>l :Lines<CR>
    nnoremap <C-p>b :Buffers<CR>
    nnoremap <C-p>m :Marks<CR>
    nnoremap <C-p>g :GFiles?<CR>
    nnoremap <C-p>h :History/<CR>
    nnoremap <C-p>c :Colors<CR>
    nnoremap <C-p>t :Tags<CR>
    nnoremap <C-p>A :Ag<CR>
    nnoremap <C-p>R :Rg<CR>
    nnoremap <C-p>F :Filetypes<CR>
    nnoremap <C-p>M :Maps<CR>
    nnoremap <C-p>H :History
    " Mapping selecting mkppings
    nmap <C-p><tab> <plug>(fzf-maps-n)
    xmap <C-p><tab> <plug>(fzf-maps-x)
    omap <C-p><tab> <plug>(fzf-maps-o)
    imap <C-p><C-w> <plug>(fzf-complete-word)
    imap <C-p><C-p> <plug>(fzf-complete-path)
    imap <C-p><C-f> <plug>(fzf-complete-file-ag)
    imap <C-p><C-l> <plug>(fzf-complete-line)
    nnoremap <C-p> :<c-u>WhichKey '<C-p>'<CR>
endif

Problem Description

It is errors when use m-s, m-o is quite the same, just s -> o in the last line

Error detected while processing function which_key#start[16]..which_key#map#parse:
line    8:
E716: Key not present in Dictionary: lhs =~? '<Plug>.*' || mapd.lhs =~? '<SNR>.*'
E15: Invalid expression: mapd.lhs =~? '<Plug>.*' || mapd.lhs =~? '<SNR>.*'
line   12:
E716: Key not present in Dictionary: rhs])
E116: Invalid arguments for function call
E15: Invalid expression: call(g:WhichKeyFormatFunc, [mapd.rhs])
line   14:
E716: Key not present in Dictionary: lhs, key, '', '')
E116: Invalid arguments for function substitute
E15: Invalid expression: substitute(mapd.lhs, key, '', '')
line   16:
E716: Key not present in Dictionary: lhs ==? '<Space>'
E15: Invalid expression: mapd.lhs ==? '<Space>'
line   20:
E716: Key not present in Dictionary: lhs, "<Space>", " ", "g")
E116: Invalid arguments for function substitute
E15: Invalid expression: substitute(mapd.lhs, "<Space>", " ", "g")
line   21:
E716: Key not present in Dictionary: lhs, "<Tab>", "<C-I>", "g")
E116: Invalid arguments for function substitute
E15: Invalid expression: substitute(mapd.lhs, "<Tab>", "<C-I>", "g")
line   23:
E716: Key not present in Dictionary: rhs, "<SID>", "<SNR>".mapd['sid']."_", "g")
E116: Invalid arguments for function substitute
E15: Invalid expression: substitute(mapd.rhs, "<SID>", "<SNR>".mapd['sid']."_", "g")
line   25:
E716: Key not present in Dictionary: lhs != '' && mapd.display !~# 'WhichKey.*'
E15: Invalid expression: mapd.lhs != '' && mapd.display !~# 'WhichKey.*'
s : is undefined

image

如何映射Ctrl快捷键

  • OS: ubuntu16.04

  • Vim: 8.1

请问如何映射Ctrl键呢?我在文档里面没有看到类似的例子。
这样写是错误的。

nnoremap <silent> <ctrl> :<c-u>WhichKeyVisual '<ctrl>'<CR>

g:which_key_hspace Still not well aligned

  • OS: Linux
  • NeoVim: 0.3.7
  • Vim:8.1
call plug#begin('~/.vim/plugged')
	Plug 'liuchengxu/vim-which-key'
call plug#end()
let g:mapleader = ";"
let g:maplocalleader = ","
set timeoutlen=300          " 按键响应 延时500毫秒

let g:which_key_hspace = 8
nnoremap <silent> <leader> :WhichKey ';'<CR>
nnoremap <silent> <localleader> :WhichKey ','<CR>

let g:which_key_map = {}

let g:which_key_map.y = ['', '复制']
let g:which_key_map.p = ['', '粘贴']
let g:which_key_map.x = ['', '剪切']
let g:which_key_map.bd = ['', '关闭buffer']
let g:which_key_map.ch = [')', '标尺']
if has("win32")
    let g:which_key_map.mw = ['', '最大化']
    let g:which_key_map.nw = ['', '窗口化']
    let g:which_key_map.sw = ['', 'sw 待测试']
else
    let g:which_key_map.mw = ['', '切换窗口化']
endif

let g:which_key_map.f = ['', '格式化选区']
let g:which_key_map.tt = ['', '翻译']
let g:which_key_map.dt = ['', 'vimwiki 更新日期']
let g:which_key_map.vt = ['', 'vimwiki todo选中']
call which_key#register(';', "g:which_key_map")

Problem Description

你要的最小化 .vimrc文件 @liuchengxu
img

listchar display is not normal when trigger whickey

  • OS: macos

  • Vim: nvim 0.3.4

If you think it's a bug, please provide a minimal vimrc to reproduce:

Problem Description

触发whichkey之后 listchar的显示不正常。更新了最新的whichkey,之前的版本并没有这个问题。

go

Don't display group names

  • OS: Win10

  • Vim: neovim0.3.0

If you think it's a bug, please provide a minimal vimrc to reproduce:

nnoremap <silent> <space> :WhichKey '<Space>'<CR>
set timeoutlen=500
autocmd! FileType which_key
autocmd  FileType which_key set laststatus=0 noshowmode noruler
  \| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
let g:which_key_map.f = { 'name' : '+file' }

Problem Description

Don't display group names "file"

E492: Not an editor command: WhichKey ' '

  • OS: macOS 10.14

  • Vim: VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 14 2018 05:28:49)
    macOS version
    Included patches: 1-280

If you think it's a bug, please provide a minimal vimrc to reproduce:

Plugin 'liuchengxu/vim-which-key'
nnoremap <silent> <leader>      :<c-u>WhickKey '<Space>'<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey ','<CR>

Problem Description

When click I get the error E492: Not an editor command: WhichKey ' '. Mapping works for localleader.

Don't flash menu for a split second when running commands defined through key map dictionary

I noticed that if you define a mapping only through the dictionary, rather than having dual definitions for it, entering the mapping, even if you do it within timeoutlen, will cause the menu to flash open for a split second then close, and then run the command. This super quick flash of the menu is rather disruptive / annoying.

I tried working around this by setting timeoutlen to 0 and just always relying on the expectation that which_key would open immediately, and that felt good except for the fact that it caused #3

Solving #2 would let me fix this issue well enough for my satisfaction in that I would make sure all my mappings are defined outside of the key map, and my key map dictionary entries would only contain information about names and aliases, not any actual command definitions.

[feature request] Backspace back to upper level + don't break at nonexist keymap

I like what vim-leader-guide does. There are some scenarios where the current behavior might be annoying:

  1. just browse through some the keymaps. But currently after going into one dict (e.g. '<leader>g'), I don't know how to go directly back (to '<leader>').
  2. I typed wrong keys. Currently it will break and show an error message. I think it might be better to do nothing and allow user to delete the wrong key and continue with the desired one.

So the point is change how <backspace> key works. Actually now hitting <backspace> will change the focus to popup window somehow which does nothing good.

Here I found how to use `<C->` and `<M->` to invoke Whichkey command

This is not an issue about bugs, just share my config

  • OS: LINUX (manjaro, ubuntu 18.04), macOS
    Have not tested windows, but I guess also can work

  • Vim: GVim8.1, neovim0.3.5, vim8.1

I have test lots of ways to make use of <C-> and <M->, and at last, I succeed
Just donot map <C-> and <M-> directly, use function to create them

PS: I map alt as meta in vim8 without gui according to Vim 中正确使用 Alt映射, so <M-> looks strange when use vim8.

    set timeoutlen=300
    nnoremap <silent> gg 1G
    function! MapKey(key)
        if len(a:key) == 3 && a:key[1] == "-" && (a:key[0] == "C" || a:key[0] == "M") "special map
            if has('nvim')
                let s:mapkey = "<" . a:key . ">"
            else
                if a:key[0] == "C" " ctrl
                    let s:mapkey = "<" . a:key . ">"
                elseif a:key[0] == "M"  "alt
                    let s:mapkey = a:key[2]
                    let s:mapkey = char2nr(s:mapkey) + 128
                    let s:mapkey = nr2char(s:mapkey)
                endif
            endif
        else
            let s:mapkey = a:key
        endif
        return s:mapkey
    endfunction
    function! MapWhichKey(key)
        execute "WhichKey '". MapKey(a:key). "'"
    endfunction
    nnoremap <localleader> :call MapWhichKey('\')<Cr>
    nnoremap <leader>      :call MapWhichKey(' ')<Cr>
    nnoremap g             :call MapWhichKey('g')<Cr>
    nnoremap m             :call MapWhichKey('m')<Cr>
    nnoremap z             :call MapWhichKey('z')<Cr>
    nnoremap [             :call MapWhichKey('[')<Cr>
    nnoremap ]             :call MapWhichKey(']')<Cr>
    nnoremap <C-p>         :call MapWhichKey('C-p')<Cr>  # plz notice not `<>`  in MapWhichKey
    nnoremap <C-f>         :call MapWhichKey('C-f')<Cr>
    nnoremap <C-b>         :call MapWhichKey('C-b')<Cr>
    nnoremap <C-l>         :call MapWhichKey('C-l')<Cr>
    nnoremap <C-h>         :call MapWhichKey('C-h')<Cr>
    nnoremap <C-g>         :call MapWhichKey('C-g')<Cr>
    nnoremap <M-z>         :call MapWhichKey('M-z')<Cr>
    nnoremap <M-g>         :call MapWhichKey('M-g')<Cr>

SceenShot

  • Gvim, <C-p>
    image

  • neovim
    image

  • vim8, <M-C> (<M-C> is different from <M-c>)
    image

why gitgutter automaticly add binding to my space menu ?

Hello,
After installing gitgutter with vim-plug, I was surprised that which_key_map.h was assign to 'prefix'
and this menu was filled with :
p → GitGutterPreviewHunk
u → GitGutterUndoHunk
s → GitGutterStageHunk
Where does this mapping come from and how can I edit it ?

Unknown function which_key#register

Hello, I'm using your great plugin with Vim 8.1. I've installed the plugin as a Git submodule into Vim's pack/plugins/start directory, so it gets loaded when Vim starts.

The plugin is working fine, but when I try to create a dictionary in my .vimrc, then I get the following error message:

E117: Unknown function: which_key#register

My configuration is very simple:

let mapleader=","

let g:which_key_map = {}
call which_key#register(',', "g:which_key_map")
nnoremap <silent> <leader> :<c-u>WhichKey ','<CR>
vnoremap <silent> <leader> :<c-u>WhichKey ','<CR>
set timeoutlen=500

It seems like that at the time .vimrc is executed, the plugin is not yet loaded? Any hints?

How to register vim-which-key when using on-demand feature of vim-plug

  • OS: osx 10.13.6

  • Vim: neovim 0.3.1

If you think it's a bug, please provide a minimal vimrc to reproduce:

  call plug#begin('~/.vim/plugged')

  Plug 'liuchengxu/vim-which-key', { 'on': ['WhichKey', 'WhichKey!'] }

  nnoremap <silent> <leader>      :<c-u>WhichKey '<Space>'<CR>
  nnoremap <silent> <localleader> :<c-u>WhichKey  ','<CR>

  let g:which_key_map = {}

  call which_key#register('<Space>', 'g:which_key_map')

  call plug#end()

Problem Description

E117: Unknown function: which_key#register

default

加了这一句的话就报错,不加的话定义的快捷键就无效

按下Leader键没有中文提示

  • OS: ubuntu16.04

  • Vim: 8.1

let g:which_key_map = {
      \ 'name' : '+Leader',
      \ 'w'    : '保存文件',
      \ 'x'    : '保存并退出文件',
      \ 'q'    : '退出文件',
      \ 'a'    : '退出所有文件',
      \ 's'    : '全文范围内替换光标处的单词',
      \ 'f'    : {
               \ 'name' : '+LeaderF',
               \ 'i'    : '搜索当前目录下的文件',
               \ 'm'    : '搜索最近使用过的文件',
               \ 'c'    : '搜索历史命令',
               \ 'f'    : '搜索当前文件中定义的函数',
               \ 'w'    : '搜索光标处的单词',
               \ 'r'    : '重新打开上一次的搜索结果',
               \ },
\ }

call which_key#register('<leader>', "g:which_key_map")
nnoremap <silent> <leader> :<c-u>WhichKey '<leader>'<CR>

我是按照README配置的,不知道为什么不能显示自定义的中文提示。

Play nicely with keybind combinations that assume timeoutlen > 0

It seems that once you enter the WhichKey menu it will immediately exit upon hitting the first valid mapping, regardless of if there are additional mappings that are supersets(right term?) of that mapping.

The example that I've run into comes from commentary, which defines 'gc' and 'gcc'. If I run :WhichKey '' its impossible to enter the second binding. As long as I don't open the whichkey menu and I do enter the correct keyset inside of timeoutlen's duration it works fine. But its impossible to reach some keymappings that would otherwise be reachable when calling them through which-key.

I noticed this because I tried setting timeoutlen to 0 and it completely broke some useful mappings.

I think it would be useful to have something like an additional whichkey specific timeout value that would allow it to keep waiting for more keys to satisfy a longer binding even if a shorter binding has already been satisfied.

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

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'            ,
      \ }

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

Treat <expr> mapping as normal mapping

  • OS: Ubuntu 16.04

  • Vim: Vi IMproved 8.1-1729

set nocompatible
let mapleader="\<Space>"

call plug#begin('~/.vim/plug')
Plug 'liuchengxu/vim-which-key'
call plug#end()

nnoremap <silent> <leader> :<C-u>WhichKey '<Space>'<CR>
let g:which_key_map = {}
call which_key#register('<Space>', "g:which_key_map")

function W() abort
    return ":echo 'test'\<CR>"
endfunction

nnoremap <expr> <leader>t W()

Problem Description

In the minimal vimrc above, a <expr> mapping is defined (<leader>t to echo 'test').
It works fine if you press <leader>t without a break.
But if you press <leader> and wait until which-key window appear, then press t, which-key will ignore <expr> and just execute W() in normal mode.

highlight with floatwindow

  • OS: macos

  • Vim: 0.4.0 dev

If you think it's a bug, please provide a minimal vimrc to reproduce:

Problem Description

i found the floatwindow highlight of whichkey is pmenu. so i cant use this to change highlight

highlight NormalFloat cterm=NONE ctermfg=14 ctermbg=0 gui=NONE guifg=#93a1a1 guibg=#002931

please check here

  if exists('&winhighlight')
    setlocal winhighlight=Normal:Pmenu
  endif

g:which_key_hspace Still not well aligned

  • OS: Linux
  • NeoVim: 0.3.7
  • Vim:8.1
call plug#begin('~/.vim/plugged')
	Plug 'liuchengxu/vim-which-key'
call plug#end()
let g:mapleader = ";"
let g:maplocalleader = ","
set timeoutlen=300          " 按键响应 延时500毫秒

let g:which_key_hspace = 8
nnoremap <silent> <leader> :WhichKey ';'<CR>
nnoremap <silent> <localleader> :WhichKey ','<CR>

let g:which_key_map = {}

let g:which_key_map.y = ['', '复制']
let g:which_key_map.p = ['', '粘贴']
let g:which_key_map.x = ['', '剪切']
let g:which_key_map.bd = ['', '关闭buffer']
let g:which_key_map.ch = [')', '标尺']
if has("win32")
    let g:which_key_map.mw = ['', '最大化']
    let g:which_key_map.nw = ['', '窗口化']
    let g:which_key_map.sw = ['', 'sw 待测试']
else
    let g:which_key_map.mw = ['', '切换窗口化']
endif

let g:which_key_map.f = ['', '格式化选区']
let g:which_key_map.tt = ['', '翻译']
let g:which_key_map.dt = ['', 'vimwiki 更新日期']
let g:which_key_map.vt = ['', 'vimwiki todo选中']
call which_key#register(';', "g:which_key_map")

Problem Description

Minimize the vimrc file you want @liuchengxu
68747470733a2f2f73322e617831782e636f6d2f323031392f30382f31312f6576703130532e706e67

mirror from #61, #61 is already closed, I can only resend it

有时候键位查找出问题,leader键可以定义map吗?

  • OS: mac os 10.13.6

  • Vim: neovim 0.3.5

If you think it's a bug, please provide a minimal vimrc to reproduce:

N/A

Problem Description

有时候可以检测到leader+e有时候检测不到但是我还是可以正常使用,我映射leader+e 打开nerdtree,leader的map能定义吗?我使用dein并且懒加载whichkey通过on_cmd调用

whichkey

Can not recognize tab

Can not recognize tab or number

minimal vimrc:

for allow-provide-description-only branch

set nocompatible
let &rtp=&rtp.','.$HOME.'/.vim/bundle/vim-which-key'
let g:mapleader="\<Space>"
nnoremap <silent> <leader>      :<c-u>WhichKey '<Space>'<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey  ','<CR>

nnoremap <Leader>a<Tab> :echom "Hello, World"<cr>
nnoremap <Leader>1 :echom "THis is one"<cr>

let g:which_key_map = {}
let g:which_key_map.a = { 
            \ 'name':"Test",
            \ '<Tab>':"Hello world"
            \} 
let g:which_key_map.1 = { 
            \ 'name':"One",
            \} 
call which_key#register('<Space>', "g:which_key_map")
colorscheme desert "default setting 
filetype plugin indent on
syntax on

for master branch

set nocompatible
let &rtp=&rtp.','.$HOME.'/.vim/bundle/vim-which-key'
let g:mapleader="\<Space>"
nnoremap <silent> <leader>      :<c-u>WhichKey '<Space>'<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey  ','<CR>

nnoremap <Leader>a<Tab> :echom "Hello, World"<cr>
nnoremap <Leader>1 :echom "THis is one"<cr>

let g:which_key_map = {}
let g:which_key_map.a = { 
            \ 'name':"Test",
            \ '<Tab>':[':echom "THis is one"<cr>',"Hello world"]
            \} 
let g:which_key_map.1 = { 
            \ 'name':"One",
            \} 
call which_key#register('<Space>', "g:which_key_map")
colorscheme desert "default setting 
filetype plugin indent on
syntax on

Feature Request: View output categorized by mode

Suggestion

It would be nice if it were easy to determine what mode a binding was set for.

This example output show 3 configured bindings; 2 are set using nnoremap while 1 is set with inoremap. As we can see, it's not possible to understand at a glance which binding will only work when used in insert mode.

a -> foo
b -> bar
c -> baz

\-

注册函数启动时出错

call which_key#register('', "g:which_key_map")
image
这个函数,在打开gvim的时候会出现如图所示的错误。但是打开后在手动运行这个函数可以。

以下是代码:
Plug 'liuchengxu/vim-which-key'
set timeoutlen=500
let g:mapleader = "<Space>"
let g:maplocalleader = ','
" nnoremap :WhichKey ''
" nnoremap :WhichKey ','

let g:which_key_map = {}

" name 是一个特殊字段,如果 dict 里面的元素也是一个 dict,那么表明一个 group,比如 +file, 就会高亮和显示 +file 。默认是 +prefix.

" =======================================================
" 基于已经存在的快捷键映射,直接使用一个字符串说明介绍信息即可
" =======================================================
" You can pass a descriptive text to an existing mapping.

let g:which_key_map.f = { 'name' : '+file' }

nnoremap fs :update
let g:which_key_map.f.s = 'save-file'

nnoremap fd :e $MYVIMRC
let g:which_key_map.f.d = 'open-vimrc'

nnoremap oq :copen
nnoremap ol :lopen

let g:which_key_map.o = {
\ 'name' : '+open',
\ 'q' : 'open-quickfix' ,
\ 'l' : 'open-locationlist',
\ }
" =======================================================
" 不存在相关的快捷键映射,需要用一个 list:
" 第一个元素表明执行的操作,第二个是该操作的介绍
" =======================================================
" Provide commands(ex-command, // mapping, etc.) and descriptions for existing mappings
let g:which_key_map.b = {
\ 'name' : '+buffer' ,
\ '1' : ['b1' , 'buffer 1'] ,
\ '2' : ['b2' , 'buffer 2'] ,
\ 'd' : ['bd' , 'delete-buffer'] ,
\ 'f' : ['bfirst' , 'first-buffer'] ,
\ 'h' : ['Startify' , 'home-buffer'] ,
\ 'l' : ['blast' , 'last-buffer'] ,
\ 'n' : ['bnext' , 'next-buffer'] ,
\ 'p' : ['bprevious' , 'previous-buffer'] ,
\ }

call which_key#register('', "g:which_key_map")
nnoremap :WhichKey ''
vnoremap :WhichKeyVisual ''

Request allow to run native mappings

  • OS: unix

  • Vim: nvim-3.2

If you think it's a bug, please provide a minimal vimrc to reproduce:

	Plug 'liuchengxu/vim-which-key'
	nnoremap <silent> <leader> :WhichKey '<Space>'<CR>
	nnoremap <silent> <localleader> :WhichKey 'g'<CR>

Problem Description

I map <localleader> to g. But I cannot press gg because I get g g is undefined.

Please allow to run native mappings.

One of the best plugins I've seen in a long time. Thanks!

annoying message

  • OS: ALL

  • Vim: ALL

not a bug, press esc immediatey after press space will show following message

screen shot 2019-01-16 at 21 02 46

Unable to add description for maps

  • OS: openSUSE Tumbleweed

  • Vim: 8.1

If you think it's a bug, please provide a minimal vimrc to reproduce:

Problem Description

I'm following the README.md file+#53 to add description text for maps
using the following lines(I'm using space-vim, so some of them are not actually needed):

function! UserConfig()
    let g:which_key_map = {}
    autocmd VimEnter * call which_key#register('<Space>', "g:which_key_map")
    nnoremap <silent> <leader> :<c-u>WhichKey '<Space>'<CR>
    vnoremap <silent> <leader> :<c-u>WhichKeyVisual '<Space>'<CR>

   " ...


endfunction

But the following error message is displayed when I open vim:

Error detected while processing VimEnter Autocommands for "*":
E117: Unknown function: which_key#register
Press ENTER or type command to continue

When I add

   nnoremap <Leader>ff :Files<CR>
   let g:which_key_map.f.f = 'Files in current dir'

to add description for a map, the following error message is displayed:

Error detected while processing function spacevim#bootstrap[2]..spacevim#end[9]..UserConfig:
line   71:
E716: Key not present in Dictionary: f.f = 'Files in current dir'
Press ENTER or type command to continue

So what should I exactly do to add description for a map?

allow a user defined escape key

  • OS: WSL ubuntu (bash on windows)

  • Vim: Nvim v 0.3.7

Problem Description

I'd like to ask for an option to add a user defined escape key. A character of 27 (the unicode equivalent of escape) is hardcoded into use here and here. I'd like a new optional variable which if not null, is also checked alongside escape. In my case, I'd like it to be Ctrl-g. that's the same key I use as an alias for escape in most other modes & having to use escape to exit which-key breaks my flow. I believe some users also rebind TAB to escape so this could also be useful for them. This shouldn't be too big of a change, thoughts?

Error when using series command

  • OS: Linux

  • Vim: 8.1

let g:which_key_map.a = {
          \ 'name' : '+apps' ,
~         \ 't' : ['botright terminal' , 'terminal']                        
          \ }

Problem Description

When i use series command like: botright terminal, it doesn't invoke the command but instead append the command text to my current buffer

Vim window become blank after resize when which-key is active

  • OS: Ubuntu 18.04

  • Vim: Neovim 0.3.1

If you think it's a bug, please provide a minimal vimrc to reproduce:

call plug#begin('~/.config/nvim/plugged')
Plug 'liuchengxu/vim-which-key', { 'on': ['WhichKey', 'WhichKey!'] }
call plug#end()

let mapleader = ' '
let maplocalleader = '\'

augroup vimrc
  autocmd!
  autocmd! User vim-which-key call which_key#register('<Space>', 'g:which_key_map')
  autocmd! FileType which_key
  autocmd  FileType which_key set laststatus=0
    \| autocmd BufLeave <buffer> set laststatus=2
augroup END

" ----------------------------------------------------------------------------
" vim-which-key
" ----------------------------------------------------------------------------
nnoremap <silent> <leader>      :<c-u>WhichKey '<Space>'<CR>
vnoremap <silent> <leader>      :<c-u>WhichKeyVisual '<Space>'<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey '\'<CR>
let g:which_key_map = {}
let g:which_key_map.2 = 'which_key_ignore'
let g:which_key_map.3 = 'which_key_ignore'
let g:which_key_map.4 = 'which_key_ignore'
let g:which_key_map.5 = 'which_key_ignore'
let g:which_key_map.6 = 'which_key_ignore'
let g:which_key_map.7 = 'which_key_ignore'
let g:which_key_map.8 = 'which_key_ignore'
let g:which_key_map.9 = 'which_key_ignore'
let g:which_key_map.b = {
      \ 'name' : '+buffer' ,
      \ '1' : ['b1'        , 'buffer 1']        ,
      \ '2' : ['b2'        , 'buffer 2']        ,
      \ 'd' : ['bd'        , 'delete-buffer']   ,
      \ 'f' : ['bfirst'    , 'first-buffer']    ,
      \ 'h' : ['Startify'  , 'home-buffer']     ,
      \ 'l' : ['blast'     , 'last-buffer']     ,
      \ 'n' : ['bnext'     , 'next-buffer']     ,
      \ 'p' : ['bprevious' , 'previous-buffer'] ,
      \ '?' : ['Buffers'   , 'fzf-buffer']      ,
      \ }

Problem Description

If I press <Space> to active which-key, then resize neovim pane size in tmux, the neovim pane become blank until I press <ESC> to quit which-key or complete some mapping in which-key table.

image
image

<leader><leader> bindings display with '\'

Hey, I'm exited to see that leader-guide ideas live on with your project, nice work.

I'm curious whether vim-which-key solves issue I have with vim-leader-guide. See hecal3/vim-leader-guide#29 (comment)

Short version, I'm using default leader \ and easymotion, that by default uses <leader><leader> as prefix for commands (like <leader><leader>f) and I find it quite handy. leader-guide has issues when trying to add definition to these bindings. Is vim-which-key able to handle this case?

Support for vim 7?

  • OS: Mac 10.12

  • Vim: 7.4.8056

Error detected while processing function which_key#register:
line    3:
E121: Undefined variable: key:val
E15: Invalid expression: key:val
E116: Invalid arguments for function extend
Press ENTER or type command to continue

Problem Description

vim-which-key works OK on vim 8 but should we support vim-which-key for vim 7?

:source session.vim is making vim-which-key not work properly

  • OS: latest manjaro
:mksession mysession.vim
" exit vim
:source mysession.vim

Problem Description

Plugin is working as expected, but after sourcing last sessions this strange thing occure and I'm no longer to use keybindings.
I'm not quite sure what can be the problem? Maybe I should source it different way?
Or after sourcing call some function that will rebuild correctly plugin?

sourcing sessions

- Vim: 
VIM - Vi IMproved 8.1 (2018 May 18, compiled Mar  6 2019 21:38:32)
Included patches: 1-996
vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Mar  6 2019 21:38:32)
Included patches: 1-996
Compiled by Arch Linux
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     +tag_old_static
+arabic            -farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    +tcl/dyn
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
+balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
+browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +textprop
+byte_offset       -hangul_input      +num64             +timers
+channel           +iconv             +packages          +title
+cindent           +insert_expand     +path_extra        +toolbar
+clientserver      +job               +perl/dyn          +user_commands
+clipboard         +jumplist          +persistent_undo   +vartabs
+cmdline_compl     +keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      +langmap           +profile           +visual
+comments          +libcall           +python/dyn        +visualextra
+conceal           +linebreak         +python3/dyn       +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
+cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          +rightleft         +wildmenu
+cursorshape       +lua/dyn           +ruby/dyn          +windows
+dialog_con_gui    +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             +X11
+digraphs          +modify_fname      +smartindent       -xfontset
+dnd               +mouse             +startuptime       +xim
-ebcdic            +mouseshape        +statusline        -xpm
+emacs_tags        +mouse_dec         -sun_workshop      +xsmp_interact
+eval              +mouse_gpm         +syntax            +xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save`

Support vim's popup

The floating window of neovim has been supported in #39. Now it's time to support vim's popup window. The advantage of floating or popup window is to get your current window layout untouched.

屏幕快照 2019-09-12 下午3 48 04

Problem when running on command line vim on Windows

Hello, continuing from #2 , when I try it in command line vim in Windows, 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

Using gvim works great.

Question: Possible to display available text objects?

  • OS: Arch Linux

  • Vim: Neovim 0.3.1

If you think it's a bug, please provide a minimal vimrc to reproduce:

  • N/A

Problem Description

First off, thank you for the great plugin/substantial improvement on leader-guide!

One of the nicest parts (for me) about which-key with evil in Emacs is the display of available text objects when in operator-pending mode. For example, if I type d and wait, a menu of the text objects and movements I could delete appears; if I continue to di, the menu shows the objects I could delete inside of.

Is this possible to set up with vim-which-key? I imagine one could try manually mapping all of the operators and text objects/movements to vim-which-key dictionaries, but that seems very tedious and brittle. Is there a better/easier way? Thanks!

Hide specific mappings

Is it possible to hide some mappings? For example do I use some mappings to jump to a buffer or window by their number. Thereby the which-key window shows each single mapping from 1 to 9 in these cases. I would like to summerize them. The former part already works, as you stated in the README that the entries of the mapping must not actually exist.

Conflict with `<C-w>`(any arrow)

  • OS: linux

  • Vim: NVIM v0.4.2

If you think it's a bug, please provide a minimal vimrc to reproduce:

let g:mapleader = "\<Space>"
nnoremap <silent> <Leader> :WhichKey '<Space>'<CR>
nnoremap <silent> <Space><Up> <C-w><Up>

Problem Description

Using above vimrc and press space (wait 1s), and then press <up> key
Or even just press <C-w><Up> when the popup menu showing

PS:
I can even use visual mode in this tab(if let g:which_key_use_floating_win = 0)
image

Can I map a key which is not leader key

  • OS: Mac

  • Vim: NeoVim 0.4

If you think it's a bug, please provide a minimal vimrc to reproduce:

Problem Description

A Great Plugin ! Can I map a key which is not leader key ?
Right now, I map ';' as leader and use well, can I map Space as well, it is a normal key

 let g:which_key_map = {
     " xxx works well with leader
  }
 let g:which_key_map['<Space>'] = {
    " xxx not work with normal key <Space>
 }
  nnoremap <silent> <leader> :<c-u>WhichKey '<leader>'<CR>
  nnoremap <silent> <Space> :<c-u>WhichKey '<Space>'<CR>
  autocmd! User vim-which-key call which_key#register(g:mapleader, 'g:which_key_map')

when I enter 'Space', only native parse of vim, cannot get my description for
map be the usage of which_key#register ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.