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?

asked Feb 17, 2021 at 6:05
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.

answered Feb 17, 2021 at 8:33
4
  • 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. Commented Feb 17, 2021 at 9:49
  • 2
    You need to be in insert mode for that. Commented Feb 17, 2021 at 11:16
  • 2
    I ran second command, it gave E492: Not an editor command: Man ls Commented Feb 17, 2021 at 12:03
  • 2
    @Philippe, :Man has to be enabled manually, which OP already did. See :help :Man. Commented Feb 17, 2021 at 12:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.