This is the best place I found for my question.

Running vim | less from inside gitbash will cause it to do something that I can only describe as "breaking."
Usually I can get the less prompt back, sometimes the vim prompt, and rarely the shell prompt; only the shell prompt looks normal, but you can't type a command.
Also, are you normally limited to having to select entire lines? Oh, that's because I was testing on empty lines.

So back to my question:

Why does this happen, and how can you prevent it?

  • 2
    Side question: Why do you need to use vim with less?
    – Fanatique
    Aug 9, 2019 at 14:18

2 Answers 2


This is happening because you're running two different programs that want to control your terminal in parallel, and both of them have no reason to exit on their own.

When you run two commands through a pipe, bash will connect the standard output of the first to a pipe, that it will then connect to the standard input of the second. It will then run both programs, in parallel. In pipelines, all commands run in parallel, not in sequence.

So whatever is written by vim, in its standard output, will be available for less, in its standard input.

But vim doesn't really produce anything on standard output. Since it's a full screen program, it will try to find where your terminal (or tty) is connected to and will try to take control of that, draw its UI there and get keystrokes from there.

less is similar, in that it will find the terminal and use it to control the screen.

Vim doesn't produce ant standard output, but less can't tell and will stay connected to the pipe, waiting for any lines to come. Vim won't really close the pipe on standard output, so less will keep alive trying to read from it.

Which program you get to interact with, well, it's a race condition. Both are started in parallel and both want your terminal, so the one that gets it first wins (or last one wins? it might be that last one clobbers the first one?)

In any case, it won't be bash, since bash is waiting for the pipeline to finish, so it won't display another prompt until the programs running will terminate.

This should explain what is happening. I'm not sure what you intended with vim | less, but other than this theoretical discussion about pipes and ttys, that command really doesn't serve any useful purpose... The best answer on "how to prevent this" is simply: Don't run that command!

If you were trying to accomplish something in particular with vim | less, then please describe what you are trying to do with these commands (perhaps in a separate question) and you should get a better answer on how to accomplish what you're trying to do.

  • 1
    I was experimenting. Looks like #less exists now, and I rethought #bug, so I'll accept this answer. Aug 9, 2019 at 17:02

Why not just use less? Assuming you have vim as your default editor, you can press 'v' inside less to view the file in vim. (The only potential gotcha is that when you quit vim, it dumps you back into less.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .