vim-which-key
vim-which-key copied to clipboard
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!
Good to know emac-which-key's operator support. It would be nice for vim-which-key to have this feature as well, but I don't know when I'll have time to work on it, just a little busy recently :(.
I'd be happy to help (once I have time myself; I'm also quite busy recently), but my Vimscript knowledge is pretty weak...
Update: Thanks to the dynamic update, this is now sort of possible if you make a lot of omap
bindings manually, e.g.
omap a :<c-u>WhichKey 'a'<CR>
Update: Thanks to the dynamic update, this is now sort of possible if you make a lot of
omap
bindings manually, e.g.omap a :<c-u>WhichKey 'a'<CR>
Could you elaborate ? Just tryed this and pretty unsuccessful unfortunately.
Other awesomes additions can be the default bindings mappings, It is implemented in SpaceVim so you can see which-key on g or z keypress. I saw that Spacevim isnt using this plugin directly tho
Well, I don't know much about SpaceVim but I knew its code is also based on https://github.com/hecal3/vim-leader-guide like vim-which-key, see the credit and introduction section of vim-which-key README.
I think the right direction is to checkout Operating-pending
, see if that works or something, see :h Operator-pending-mode
. But I currently don't have much time for this discovery. You may try @wbthomason 's solution right now @adberard.
Im also quite buzy lately, I did a quick ripoff of the Spacevim bindings, there is a lot of code repetetion a factoring that can be done but here is what I have :
first create a new g:mapping_X
feedkey send the keys to vim like if it was the user that pressed them
remap the bindings
"g {{
" nnoremap <silent><nowait> [G] :<c-u>LeaderGuide "g"<CR>
nnoremap <silent><nowait> [G] :<c-u>WhichKey 'g'<cr>
nmap g [G]
let g:which_key_g= {}
let g:which_key_g['<C-G>'] = ['call feedkeys("g\<c-g>", "n")', 'show cursor info']
nnoremap g<c-g> g<c-g>
let g:which_key_g['&'] = ['call feedkeys("g&", "n")', 'repeat last ":s" on all lines']
nnoremap g& g&
let g:which_key_g["'"] = ['call feedkeys("g' . "'" . '", "n")', 'jump to mark']
nnoremap g' g'
let g:which_key_g['`'] = ['call feedkeys("g' . '`' . '", "n")', 'jump to mark']
nnoremap g` g`
let g:which_key_g['+'] = ['call feedkeys("g+", "n")', 'newer text state']
nnoremap g+ g+
let g:which_key_g['-'] = ['call feedkeys("g-", "n")', 'older text state']
nnoremap g- g-
let g:which_key_g[','] = ['call feedkeys("g,", "n")', 'newer position in change list']
nnoremap g, g,
let g:which_key_g[';'] = ['call feedkeys("g;", "n")', 'older position in change list']
nnoremap g; g;
let g:which_key_g['@'] = ['call feedkeys("g@", "n")', 'call operatorfunc']
nnoremap g@ g@
let g:which_key_g['#'] = ['call feedkeys("\<Plug>(incsearch-nohl-g#)")', 'search under cursor backward']
let g:which_key_g['*'] = ['call feedkeys("\<Plug>(incsearch-nohl-g*)")', 'search under cursor forward']
let g:which_key_g['/'] = ['call feedkeys("\<Plug>(incsearch-stay)")', 'stay incsearch']
let g:which_key_g['$'] = ['call feedkeys("g$", "n")', 'go to rightmost character']
nnoremap g$ g$
let g:which_key_g['<End>'] = ['call feedkeys("g$", "n")', 'go to rightmost character']
nnoremap g<End> g<End>
let g:which_key_g['0'] = ['call feedkeys("g0", "n")', 'go to leftmost character']
nnoremap g0 g0
let g:which_key_g['<Home>'] = ['call feedkeys("g0", "n")', 'go to leftmost character']
nnoremap g<Home> g<Home>
let g:which_key_g['e'] = ['call feedkeys("ge", "n")', 'go to end of previous word']
nnoremap ge ge
let g:which_key_g['<'] = ['call feedkeys("g<", "n")', 'last page of previous command output']
nnoremap g< g<
let g:which_key_g['f'] = ['call feedkeys("gf", "n")', 'edit file under cursor']
nnoremap gf gf
let g:which_key_g['F'] = ['call feedkeys("gF", "n")', 'edit file under cursor(jump to line after name)']
nnoremap gF gF
let g:which_key_g['j'] = ['call feedkeys("gj", "n")', 'move cursor down screen line']
nnoremap gj gj
let g:which_key_g['k'] = ['call feedkeys("gk", "n")', 'move cursor up screen line']
nnoremap gk gk
let g:which_key_g['u'] = ['call feedkeys("gu", "n")', 'make motion text lowercase']
nnoremap gu gu
let g:which_key_g['E'] = ['call feedkeys("gE", "n")', 'end of previous word']
nnoremap gE gE
let g:which_key_g['U'] = ['call feedkeys("gU", "n")', 'make motion text uppercase']
nnoremap gU gU
let g:which_key_g['H'] = ['call feedkeys("gH", "n")', 'select line mode']
nnoremap gH gH
let g:which_key_g['h'] = ['call feedkeys("gh", "n")', 'select mode']
nnoremap gh gh
let g:which_key_g['I'] = ['call feedkeys("gI", "n")', 'insert text in column 1']
nnoremap gI gI
let g:which_key_g['i'] = ['call feedkeys("gi", "n")', "insert text after '^ mark"]
nnoremap gi gi
let g:which_key_g['J'] = ['call feedkeys("gJ", "n")', 'join lines without space']
nnoremap gJ gJ
let g:which_key_g['N'] = ['call feedkeys("gN", "n")', 'visually select previous match']
nnoremap gN gN
let g:which_key_g['n'] = ['call feedkeys("gn", "n")', 'visually select next match']
nnoremap gn gn
let g:which_key_g['Q'] = ['call feedkeys("gQ", "n")', 'switch to Ex mode']
nnoremap gQ gQ
let g:which_key_g['q'] = ['call feedkeys("gq", "n")', 'format Nmove text']
nnoremap gq gq
let g:which_key_g['R'] = ['call feedkeys("gR", "n")', 'enter VREPLACE mode']
nnoremap gR gR
let g:which_key_g['T'] = ['call feedkeys("gT", "n")', 'previous tag page']
nnoremap gT gT
let g:which_key_g['t'] = ['call feedkeys("gt", "n")', 'next tag page']
nnoremap gt gt
let g:which_key_g[']'] = ['call feedkeys("g]", "n")', 'tselect cursor tag']
nnoremap g] g]
let g:which_key_g['^'] = ['call feedkeys("g^", "n")', 'go to leftmost no-white character']
nnoremap g^ g^
let g:which_key_g['_'] = ['call feedkeys("g_", "n")', 'go to last char']
nnoremap g_ g_
let g:which_key_g['~'] = ['call feedkeys("g~", "n")', 'swap case for Nmove text']
nnoremap g~ g~
let g:which_key_g['a'] = ['call feedkeys("ga", "n")', 'print ascii value of cursor character']
nnoremap ga ga
let g:which_key_g['g'] = ['call feedkeys("gg", "n")', 'go to line N']
nnoremap gg gg
let g:which_key_g['m'] = ['call feedkeys("gm", "n")', 'go to middle of screenline']
nnoremap gm gm
let g:which_key_g['o'] = ['call feedkeys("go", "n")', 'goto byte N in the buffer']
nnoremap go go
let g:which_key_g.s = ['call feedkeys("gs", "n")', 'sleep N seconds']
nnoremap gs gs
let g:which_key_g['v'] = ['call feedkeys("gv", "n")', 'reselect the previous Visual area']
nnoremap gv gv
let g:which_key_g['<C-]>'] = ['call feedkeys("g<c-]>", "n")', 'jump to tag under cursor']
nnoremap g<c-]> g<c-]>
" let g:which_key_g['d'] = ['call SpaceVim#mapping#gd()', 'goto definition']
" call SpaceVim#mapping#def('nnoremap <silent>', 'gd', ':call SpaceVim#mapping#gd()<CR>', 'Goto declaration', '')
call which_key#register('g', "g:which_key_g")
"}}
"z{{
nnoremap <silent><nowait> [Z] :<c-u>WhichKey "z"<CR>
nmap z [Z]
let g:which_key_z = {}
let g:which_key_z['<CR>'] = ['call feedkeys("z\<CR>", "n")', 'cursor line to top']
nnoremap z<CR> z<CR>
let g:which_key_z['+'] = ['call feedkeys("z+", "n")', 'cursor to screen top line N']
nnoremap z+ z+
let g:which_key_z['-'] = ['call feedkeys("z-", "n")', 'cursor to screen bottom line N']
nnoremap z- z-
let g:which_key_z['^'] = ['call feedkeys("z^", "n")', 'cursor to screen bottom line N']
nnoremap z^ z^
let g:which_key_z['.'] = ['call feedkeys("z.", "n")', 'cursor line to center']
nnoremap z. z.
let g:which_key_z['='] = ['call feedkeys("z=", "n")', 'spelling suggestions']
nnoremap z= z=
let g:which_key_z['A'] = ['call feedkeys("zA", "n")', 'toggle folds recursively']
nnoremap zA zA
let g:which_key_z['C'] = ['call feedkeys("zC", "n")', 'close folds recursively']
nnoremap zC zC
let g:which_key_z['D'] = ['call feedkeys("zD", "n")', 'delete folds recursively']
nnoremap zD zD
let g:which_key_z['E'] = ['call feedkeys("zE", "n")', 'eliminate all folds']
nnoremap zE zE
let g:which_key_z['F'] = ['call feedkeys("zF", "n")', 'create a fold for N lines']
nnoremap zF zF
let g:which_key_z['G'] = ['call feedkeys("zG", "n")', 'mark good spelled(update internal-wordlist)']
nnoremap zG zG
let g:which_key_z['H'] = ['call feedkeys("zH", "n")', 'scroll half a screenwidth to the right']
nnoremap zH zH
let g:which_key_z['L'] = ['call feedkeys("zL", "n")', 'scroll half a screenwidth to the left']
nnoremap zL zL
let g:which_key_z['M'] = ['call feedkeys("zM", "n")', 'set `foldlevel` to zero']
nnoremap zM zM
let g:which_key_z['N'] = ['call feedkeys("zN", "n")', 'set `foldenable`']
nnoremap zN zN
let g:which_key_z['O'] = ['call feedkeys("zO", "n")', 'open folds recursively']
nnoremap zO zO
let g:which_key_z['R'] = ['call feedkeys("zR", "n")', 'set `foldlevel` to deepest fold']
nnoremap zR zR
let g:which_key_z['W'] = ['call feedkeys("zW", "n")', 'mark wrong spelled']
nnoremap zW zW
let g:which_key_z['X'] = ['call feedkeys("zX", "n")', 're-apply `foldleve`']
nnoremap zX zX
let g:which_key_z['a'] = ['call feedkeys("za", "n")', 'toggle a fold']
nnoremap za za
let g:which_key_z['b'] = ['call feedkeys("zb", "n")', 'redraw, cursor line at bottom']
nnoremap zb zb
let g:which_key_z['c'] = ['call feedkeys("zc", "n")', 'close a fold']
nnoremap zc zc
let g:which_key_z['d'] = ['call feedkeys("zd", "n")', 'delete a fold']
nnoremap zd zd
let g:which_key_z['e'] = ['call feedkeys("ze", "n")', 'right scroll horizontally to cursor position']
nnoremap ze ze
let g:which_key_z['f'] = ['call feedkeys("zf", "n")', 'create a fold for motion']
nnoremap zf zf
let g:which_key_z['g'] = ['call feedkeys("zg", "n")', 'mark good spelled']
nnoremap zg zg
let g:which_key_z['h'] = ['call feedkeys("zh", "n")', 'scroll screen N characters to right']
nnoremap zh zh
let g:which_key_z['<Left>'] = ['call feedkeys("zh", "n")', 'scroll screen N characters to right']
nnoremap z<Left> zh
let g:which_key_z['i'] = ['call feedkeys("zi", "n")', 'toggle foldenable']
nnoremap zi zi
let g:which_key_z['j'] = ['call feedkeys("zj", "n")', 'move to start of next fold']
nnoremap zj zj
let g:which_key_z['J'] = ['call feedkeys("zjzx", "n")', 'move to and open next fold']
nnoremap zJ zjzx
let g:which_key_z['k'] = ['call feedkeys("zk", "n")', 'move to end of previous fold']
nnoremap zk zk
let g:which_key_z['K'] = ['call feedkeys("zkzx", "n")', 'move to and open previous fold']
nnoremap zK zkzx
let g:which_key_z['l'] = ['call feedkeys("zl", "n")', 'scroll screen N characters to left']
nnoremap zl zl
let g:which_key_z['<Right>'] = ['call feedkeys("zl", "n")', 'scroll screen N characters to left']
nnoremap z<Right> zl
let g:which_key_z['m'] = ['call feedkeys("zm", "n")', 'subtract one from `foldlevel`']
nnoremap zm zm
let g:which_key_z['n'] = ['call feedkeys("zn", "n")', 'reset `foldenable`']
nnoremap zn zn
let g:which_key_z['o'] = ['call feedkeys("zo", "n")', 'open fold']
nnoremap zo zo
let g:which_key_z['r'] = ['call feedkeys("zr", "n")', 'add one to `foldlevel`']
nnoremap zr zr
let g:which_key_z.s = ['call feedkeys("zs", "n")', 'left scroll horizontally to cursor position']
nnoremap zs zs
let g:which_key_z['t'] = ['call feedkeys("zt", "n")', 'cursor line at top of window']
nnoremap zt zt
let g:which_key_z['v'] = ['call feedkeys("zv", "n")', 'open enough folds to view cursor line']
nnoremap zv zv
let g:which_key_z['x'] = ['call feedkeys("zx", "n")', 're-apply foldlevel and do "zV"']
nnoremap zx zx
" smart scroll
let g:which_key_z['z'] = ['call feedkeys("zz", "n")', 'smart scroll']
nnoremap zz zz
call which_key#register('z', "g:which_key_z")
"}}
It should be done by extracting :h index
and parsing it.
Here is all what could be awesome in future :
I_CTRL (for ctrl-x completions mapping discovery for example::)
CTRL (ctrl-w and ctrl-g have quite a lot of usually unused stuff)
" (To show all what can be done with the registers btw that make me think that I use [peekaboo]https://github.com/junegunn/vim-peekaboo))
text objects
[
{
c_CTRL for Command line editing mode
I am pretty convinced that this kind of tooltips would greatly improve vim onboarding and features discoveries. This is what has been done partialy for kakoune (try it)
What do you think ?
Well, I think the function is good, especially for the text objects part, but I'm not fond of the way of implementation. Currently I'm working on vim-clap in my most free time, I'll definitely look into this and see if there is a better solution when I get another free time. P.S. registers with preview will also be supported in vim-clap :(.
I dont really like how its implemented either. I tryed to fiddle around for [ { commands but didnt found a way to make them work. I just added vim-clap and vista this sunday and I was really amazed. I really appreciate that you took time to do fzf and coc.nvim integration.
Is it now possible to set whichkey for the some default key-bindings in vim?