Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>"

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

share|improve this question

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>"
share|improve this answer
its not DRY .... – majkinetor Jan 5 '14 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 '14 at 2:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .