Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there any way to find the last key used in vim so I could use the same function for multiple things depending on the key pressed.

For instance:

nn <F1> :call Fhandler()
nn <F2> :call Fhandler()

fu Fhandler()
  if v:triggerKey == "<F1>"
  elseif v:triggerKey == "<F2>"
  ...
endf

For instance, in AutoHotKey I have A_ThisHotkey which could be used to setup mentioned proxy function.

share|improve this question

1 Answer 1

Unless we are dealing with an XY problem with your question, why not just do this:

nn <F1> :call Fhandler('<F1>')
nn <F2> :call Fhandler('<F2>')

fu Fhandler(key)
  if a:key == "<F1>"
  elseif a:key == "<F2>"
  ...
endf
share|improve this answer
    
its not DRY .... –  majkinetor Jan 5 at 21:00
    
Isn't the "don't repeat yourself" idea meant for when it's avoidable? In this case you're probably stuck with it. –  Heptite Jan 6 at 2:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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