1

I want to run an external command by typing :runMyCommand (just run a shellcommand). I thought I'd put the shell command execution into a function, so I can call it with :call runMyCommand, but I want to get rid of the :call.

Is this possible and if yes, how? (I guess something like this was already asked, but in my opinion this issue is really hard to search for)

4

:h :command will put you on the right track.

It can be as simple as

command! RunMyCommand call RunMyCommand()

Or much more complex if you want to support arguments, range...

2
  • This is exactly what I was searching for (but not knowing how this is called in vim) :+1:
    – atticus
    Jun 12 '20 at 15:05
  • @D.BenKnoble You're right. I've copy-pasted OP's code and I forgot along the way about command restrictions. I fix my answer. Jun 12 '20 at 16:59

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.