Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Vim commands from Terminal

My questions is one that I haven't seen answered, the usual question is how to run certain commands to a file.

My question is how to run Vim commands or functions, from outside Vim (i.e. Terminal), these wouldn't affect any file, just Vim itself. Is this is even possible? If so, how?

If this is not possible like this, is there a way to go into Vim, run a command automatically, and then exit when that ends? Or run another command and then exit?

Thanks for your help!

like image 860
greduan Avatar asked Nov 23 '12 03:11

greduan


People also ask

How do I run a vim program in terminal?

You simply type vim into the terminal to open it and start a new file. You can pass a filename as an option and it will open that file, e.g. vim main. c . You can open multiple files by passing multiple file arguments.

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.

How do I run a command in vi editor?

The vi has the capability to run commands from within the editor. To run a command, you only need to go to the command mode and type :! command.


1 Answers

Use

vim --cmd 'Command launched before vimrc' \
     -c 'Command launched after vimrc' \
     -c 'qa!' # Quit vim

. For running a command in an existing vim session you have to use +clientserver feature: run one vim with

vim --servername vim

and others with

vim --remote-send '<C-\><C-n>:Command<CR>'
like image 157
ZyX Avatar answered Oct 12 '22 22:10

ZyX