2

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?

1
  • This opens man page, not like :Man because :Man has colored, and man ls | vim - not Commented Feb 17, 2021 at 6:23

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

4 Comments

The second solution wincmd work fine, but the first not work with me, also I tried C-v follow by `, buts me in V-block mode, so this not work as we expected here. Thanks alot.
You need to be in insert mode for that.
I ran second command, it gave E492: Not an editor command: Man ls
@Philippe, :Man has to be enabled manually, which OP already did. See :help :Man.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.