11

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
  • 51,086
  • 7
  • 70
  • 105
bodacydo
  • 75,521
  • 93
  • 229
  • 319

2 Answers2

16

| 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
  • 7,475
  • 12
  • 47
  • 83
  • How does the first command transfer its data to second command? – bodacydo Oct 05 '15 at 13:20
  • 7
    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
  • What's the help page for this? – theonlygusti Apr 03 '23 at 01:07
6

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
  • 51,086
  • 7
  • 70
  • 105
  • 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