3

I want to execute two shell command at the same time in vim. So i use | like below

   :!ls|!pwd

Its Returns the following error

E34: No previous command

But what happen ls output is forward to second command, because of the piping. What this is the solution to solve this problem, How to execute two shell commands like this, to execute inside of vim

4

Quoting from the help (:h E34)

Any '!' in {cmd} is replaced with the previous external command

And further in the help (:h :bar)

These commands see the '|' as their argument, and can therefore not be followed by another Vim command:

[various other]

:[range]!

[...]

To be able to use another command anyway, use the ":execute" command.

So if you want to execute 2 shell commands in a row, you need to do this:

:exe "!ls" | exe "!pwd"
  • But what about other commands start with !. Like !shell . You said Any '!' in {cmd} is replaced with the previous external command. If i put '!shell' in ex -mode it will open terminal, How its replaced with external commands – SuperKrish Nov 4 '16 at 10:12
  • In :[range]! cmd ! is not part of the command. so it only applies, if the ! comes later in the commandline – Christian Brabandt Nov 4 '16 at 10:14
  • Great @Christian Brabandt . Nice explanations Thanks – SuperKrish Nov 4 '16 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.