greduan
greduan

Reputation: 4938

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!

Upvotes: 17

Views: 10459

Answers (1)

ZyX
ZyX

Reputation: 53674

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

Upvotes: 28

Related Questions