vim-which-key icon indicating copy to clipboard operation
vim-which-key copied to clipboard

Mapping Out Of The Box (OOTB) Modifiers

Open ca-mantis-shrimp opened this issue 4 years ago • 2 comments

Hi All,

This is less of a bug as a questions.

I've gotten the basics down of using which-key to show whatever leader keys I define.

However, instead of re-mapping certain functions I want (think the <CTRL+W> commands).

  • I'm assuming this has something to do with loading the dictionary of the OOTB mappings, but is that easily accessible for configuration?
    • or will I have to re-build the functions in a mapping for which-key in order to use these functions with which-key support?

thanks for your time and expertise.

ca-mantis-shrimp avatar Sep 30 '20 01:09 ca-mantis-shrimp

I'm trying to do similar; for instance, I'm building a mapping for the g-prefixed mappings (see :help g).

At the moment, the only work-around I've found is to explicitly remap-onto-itself every single prefixed mapping — they actually stop working if they're not remaped.

As an example, the following breaks the built-in gg command to jump to the top of the window:

if !exists('g:goto_key_map') | let g:goto_key_map = {} | endif

" ...

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

Attempting to gg with the above yields [which-key] g + is undefined.

Even if I give it a definition,

if !exists('g:goto_key_map') | let g:goto_key_map = {} | endif

let g:goto_key_map.g = 'goto-top'

... I still get [which-key] Fail to execute, no such mapping. Sadly, the only way I found to do this, is to enumerate every built-in mapping, manually, such that WhichKey is aware of them; something like ...

if !exists('g:goto_key_map') | let g:goto_key_map = {} | endif

" Need to duplicate built-in mappings so WhichKey can be aware of them
nnoremap <silent> g<C-G> g<C-G>
let g:goto_key_map['<C-G>'] = 'show-cursor-pos'
nnoremap <silent> gg gg
let g:goto_key_map.g = 'goto-top'
nnoremap <silent> g8 g8
let g:goto_key_map['8'] = 'print-char-as-hex'
nnoremap <silent> g' g'
let g:goto_key_map["'"] = 'mark-without-jumplist'
nnoremap <silent> g` g`
let g:goto_key_map["`"] = 'mark-without-jumplist'
nnoremap <silent> g+ g+
let g:goto_key_map["+"] = 'undo-chrono-forward'
nnoremap <silent> g- g-
let g:goto_key_map["-"] = 'undo-chrono-backwards'
" ... and so on.

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

For the moment, I'm just gonna give up on this, until someone feels like patching WhichKey; it's way, way too much to duplicate-and-maintain this entire list:

Screen Shot 2021-01-30 at 21 36 00

ELLIOTTCABLE avatar Jan 31 '21 03:01 ELLIOTTCABLE

@ELLIOTTCABLE you can specify let g:which_key_fallback_to_native_key = 1 so that default commands don't fail when there is no mapping defined.

acdifran avatar Feb 11 '21 23:02 acdifran