4

I want to write a function that can map a key to another function.

But I failed to insert the variables into map command:

map a:key :! a:action (in which a:key may be <F9>, <C-F9> and so on)

How to achieve this in vim command-like sentences?

2
  • Just for checking whether there is another way to go about this, what are you trying to achieve with this? Commented Mar 10, 2012 at 16:28
  • I want to write a function to map shortcut keys according to the file type. And I think it's better to make a function to avoid same code lines. Commented Mar 11, 2012 at 10:11

1 Answer 1

5

If I understand your question correctly, you're looking for execute.

:execute "map " . a:key . " :!" . a:action

See :help :execute for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.