I would like to find multiple files and open them all in tabs within the same vim instance.


2 Answers 2

vim -p `find . -name '*.txt'` 

Putting the find command between backticks executes find before running the full command and the results replace what's between the backticks. So before running the full command it will have this form vim -p result1 result2 ... resultN .

  • This seems to fail if the filenames contain spaces. Sep 2, 2021 at 9:40
find "$PWD" -name '*.txt' -exec vim -p {} +
  • 2
    vim -p `find . -name '*.txt'` Oct 8, 2015 at 14:41
  • I like that more. If you post it as an answer I'll accept it.
    – andorov
    Oct 8, 2015 at 14:59
  • Ok, will do that. Oct 8, 2015 at 15:10
  • This is the better way. The other way is easily broken if filenames have spaces, or special characters in them.
    – muru
    Apr 24, 2016 at 18:00
  • This approach (using the -exec switch) seems to work also when files contain spaces. Sep 2, 2021 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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