I'm trying to build a very simple plugin that allows for pressing a keymapping
<Leader>, to call a function that prompts for a single keypress:
function! ControlKey() echo "Key → <C-Key> » " let l:key = getchar() let l:key = ((l:key >= 97 && l:key <= 122) ? l:key - 32 : l:key) - 64 if l:key < 0 || l:key > 31 echoerr "Invalid Key Conbination! " endif call feedkeys(nr2char(l:key), 't') | return '' endfunction cnoremap <Leader>, <C-r>=ControlKey()<Cr> inoremap <Leader>, <C-r>=ControlKey()<Cr> nnoremap <Leader>, :call ControlKey()<Cr>
The function takes this keypress (for example,
a) and then uses feedkeys to send
<C-a> (essentially behaving as a sticky control key). This works fine in normal mode, as well as in insert and command (by (ab)using the expression register to make the requisite function call). I run into issues when wanting to use this function in operator pending mode, because I can't see a way to make make a call to the function that won't clobber the operator (
y, etc) expecting a range or motion. Is there a way to achieve this or am I trying to stretch vim too far?