How to execute Vim commands from shell? For ex I want to see man pages of grep command in vim typing command from shell(bash,zsh) command something like:

vim ':Man grep'

Is it possible?

1 Answer 1


From vim manpage:

  -c {command}
               {command} will be executed after the first file has been read.  {command} is  interpreted  as  an  Ex
               command.   If the {command} contains spaces it must be enclosed in double quotes (this depends on the
               shell that is used).  Example: Vim "+set si" main.c
               Note: You can use up to 10 "+" or "-c" commands.

From vim help:

To start using the ":Man" command before any manual page was loaded, source     
this script from your startup vimrc file:                                       

    runtime ftplugin/man.vim

Assuming you don't have man.vim sourced in vimrc, the following should work:

vim -c 'runtime ftplugin/man.vim' -c 'Man grep'

If you do have man.vim already sourcerd in vimrc, you can skip the explicit sourcing command argument to vim

And you'll probably want a shell script wrapper that will accept an argument so you'll be able to do something like

$ m ls

with content of m script being


vim -c 'runtime ftplugin/man.vim' -c "Man $1"

Notice the usage of double quotes so $1 gets understood properly by bash as the passed argument.

Of course you can always hit K on current word in vim to open the manpage for that word, but since you're explicitly telling that you want to do it from shell, I assume you know about this.

  • Thank You for great answer :) 1. This command vim -c 'Man grep' works fine under linux, but under Windows there is only empty file under vim. 2. Is it possible to create alias instead script file for this command : vim -c 'runtime ftplugin/man.vim' -c "Man $1" so m ls would work as alias?
    – lluke
    Dec 2, 2018 at 17:21
  • I'm afraid I can't say anything about Windows, because I'm not using it at all. For better visibility I suggest editing the question and requiring a solution that covers the Windows use case as well. I went for a script rather than an alias so I could pass the command name as argument. I'm not sure it's possible to do that with an alias. Dec 2, 2018 at 17:28

Your Answer

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

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