2

I've got a weird problem where if i do something like this in a gnu screen window, that window starts responding in weird ways

ls *.cpp | xargs vim

After I exit from vim, the screen window doesn't echo any command. It even does not echo CR.

Any suggestions?

Alessandro Vendruscolo
  • 14,493
  • 4
  • 32
  • 41
puneet agrawal
  • 343
  • 2
  • 4
  • 13
  • 2
    are you expecting VIM to open all the **cpp** file for you. I would suggest you do this sort thing in **VIM** ,not in this way. – zinking Jun 25 '12 at 10:44
  • 1
    why don't use vim directly `vim *.cpp` – Dzung Nguyen Jun 25 '12 at 10:52
  • 1
    what would be wrong with `vim *.cpp` ?? – epsilonhalbe Jun 25 '12 at 10:53
  • possible duplicate of [Why does "locate filename | xargs vim" cause strange terminal behaviour?](http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour) – sehe Jun 25 '12 at 14:19

3 Answers3

3

Piping changes vim's stdin and causes problems. Try this instead (for bash, zsh, etc.):

vim $(find . -name "*.cpp")
PonyEars
  • 2,144
  • 4
  • 25
  • 30
2

How about vim *.cpp?

Maybe for file in *.cpp; do vim "$file"; done could work too. Edit each file and exit.

Or start vim and add all cpp files with following command: :argadd *.cpp

Birei
  • 35,723
  • 2
  • 77
  • 82
2

When using Vim in a pipe like this, you'll probably notice the following warning:

Vim: Warning: Input is not from a terminal

That's Vim telling you that it cannot function as it's supposed to be (i.e. in interactive mode; you can still use it in "batch mode" by feeding it Ex commands to process). That explains the weirdness you experience after Vim quits.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324