smalinux
smalinux

Reputation: 1150

Executing Vim commands from a shell script

I am writing a Bash script that should open ls man page then expand the page.

what I did:
bash$ vim +Man\ ls -c Wo
What I exbect to happen that the bash open ls manpage then execute keybind <C-w>o to expand
this part -c Wo is wrong

Is there a practical way to execute Vim commands from the shell script?

Upvotes: 2

Views: 527

Answers (1)

romainl
romainl

Reputation: 196856

-c and + expect a command-line mode command (AKA "Ex command", the commands that start with :) but <C-w>o is a normal mode command so it can't be used directly, here.

One way to get around this problem would be to use :help :normal and your shell's ability to insert control characters via <C-v>:

$ vim +Man\ ls +normal\ ^Wo

with ^W being a literal <C-w> character obtained by pressing <C-v> followed by <C-w>.

But using the command-line mode equivalent of <C-w>o seems like a better idea:

$ vim +Man\ ls +wincmd\ o

See :help :wincmd.

Upvotes: 3

Related Questions