Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a vim command from the shell command-line?

Tags:

bash

shell

vim

zsh

There are many stackoverflow questions about running shell programs from within vim. Is it is possible to do the reverse, i.e.,

$ vim :BundleInstall 

to allow me to run BundleInstall as part of a shell script, rather than having to open vim and run it manually?

like image 877
jvc26 Avatar asked Oct 11 '12 07:10

jvc26


People also ask

How do I run a Vim command in terminal?

To start using vim, just run the "vim" command on the Linux shell followed by the path of the file that you want to edit. [enter] means to press the return or enter key on your keyboard.

How do I access Vim in CMD?

After its installation, you can use it by opening the command prompt (cmd) then typing “vim”. This will open the vim application. There are two modes available in this editor, one is the insert mode where you can insert anything you like then there is a command mode which is used to perform different functions.


2 Answers

Note, now the syntax has changed, and the line should read (As per @sheharyar):

vim +PluginInstall +qall 

For posterity, previously, the correct line was:

vim +BundleInstall +qall 

Should anyone other than me be looking! Note: this is in the Github README for vundle.

like image 73
jvc26 Avatar answered Sep 30 '22 21:09

jvc26


Per the vim man page (man vim):

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

or:

--cmd {command}     Like using "-c", but the command is  executed  just  before     processing  any  vimrc file.  You can use up to 10 of these     commands, independently from "-c" commands. 

It really depends on what you want to do. Also, as described at the vundle readme file, if you launch vim like this:

    vim +BundleInstall +qall 

This will install all bundle options without opening vim. And just for clarification, from the vim documentation:

:qall      This stands for "quit all".  If any of the windows contain changes, Vim will     not exit.  The cursor will automatically be positioned in a window with     changes.  You can then either use ":write" to save the changes, or ":quit!" to     throw them away. 
like image 39
Daniel Noguchi Avatar answered Sep 30 '22 20:09

Daniel Noguchi