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 Answer 1
-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
.
-
The second solution
wincmd
work fine, but the first not work with me, also I triedC-v
follow by `, buts me in V-block mode, so this not work as we expected here. Thanks alot.smalinux– smalinux2021年02月17日 09:49:06 +00:00Commented Feb 17, 2021 at 9:49 -
2You need to be in insert mode for that.romainl– romainl2021年02月17日 11:16:49 +00:00Commented Feb 17, 2021 at 11:16
-
2I ran second command, it gave
E492: Not an editor command: Man ls
Philippe– Philippe2021年02月17日 12:03:59 +00:00Commented Feb 17, 2021 at 12:03 -
2@Philippe,
:Man
has to be enabled manually, which OP already did. See:help :Man
.romainl– romainl2021年02月17日 12:21:46 +00:00Commented Feb 17, 2021 at 12:21
:Man
because:Man
has colored, andman ls | vim -
not