0

This might be quite challenging, but I would like to achieve the following behavior. Imagine that I have two mappings that overlap:

  • dcb := delete comment block := delete comment block (all adjacent comment lines)
  • dcl := delete comment line := delete comment line

if I type in normal mode 'dc' and the timeout expires, I would like to provide help showing the different options. I have all the mappings documented so it would be easy to write a program that filters out what the verb is and what the text object is, but as I'm not very experienced with vimscript the challenging part for me is:

  • Triggering the function when timeoutlen expires
  • Retrieving the input command:
    • If I could get that the user input was 'dc' then I easy parse my documentation and provide the information.

Less challenging (still challenging for me but definitely possible as this is very common in many plugins:

  • Presenting the different options to the user and letting them choose
  • Executing the final command

Any ideas or guidance on how to achieve this would be very much appreciated.

1

Create map for dc, if you type in only dc, it will be triggered after timeoutlen ms.

nnoremap dcb :echo "dcb"<cr>
nnoremap dcl :echo "dcl"<cr>
nnoremap dc :call <sid>suggest('dc')<cr>

function! s:suggest(cmd)
  " get second column of `map dc`
  let l = map(split(execute('map ' . a:cmd), "\n"), {i,v->split(v)[1]})
  echo 'possible commands : ' . join(l[1:], " ")
endfunction
  • This is very specific, it would only work with 'dc'. I'm looking for a solution that works for all my mapings – Blasco Oct 10 at 11:46
  • 1
    suggest accept a command prefix, you can use other prefix for other commands. e.g. nnoremap dx :call <sid>suggest('dx')<cr> suggest for all commands starts with dx. – dedowsdi Oct 10 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.