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?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityFrom 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
#!/bin/sh
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.
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?