10

What does pipe character do in vim command mode?

For example, :vimgrep /pattern/ file | copen

Does it act like a pipe in Linux Command Line? Contents of vimgrep gets piped to copen?

Or does it separate commands like ; in Command Line?

Thomas Dickey
  • 47,166
  • 7
  • 60
  • 95
bodacydo
  • 69,885
  • 86
  • 222
  • 312

2 Answers2

13

| is used to execute more than one command at a time.

In your example:

:vimgrep /pattern/ file | copen

This finds for the pattern in the specified file and then opens a window to show current list of occurrence of pattern.

The second command (and subsequent commands) are only executed if the prior command succeeds.

Sagar Jain
  • 6,909
  • 11
  • 43
  • 75
  • How does the first command transfer its data to second command? – bodacydo Oct 05 '15 at 13:20
  • 5
    It doesn't, that's not the point - it's not like the unix pipe, it's just running multiple commands on a single line. `vimgrep` does what it does and stores the result in the quickfix list. `copen` simply opens a window to show you the quickfix list. There is no transfer occurring in this command at all. – Dan Lowe Oct 05 '15 at 14:21
5

To OP's question: the latter.

This is actually a vi feature, not vim-specific, used to separate multiple commands. It was answered before here:

Community
  • 1
  • 1
Thomas Dickey
  • 47,166
  • 7
  • 60
  • 95
  • Is `|` an Ex command? How does the first command transfer its data to second command if those are independent commands? – bodacydo Oct 05 '15 at 13:20
  • As [@Dan Lowe](http://stackoverflow.com/users/2449905/dan-lowe) pointed out, there is no transfer ("|" can mean different things, e.g., in regular expressions). – Thomas Dickey Oct 05 '15 at 21:49