Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

:) In my never-ending effort to get lazier, I am looking for a way to improve my "Open Grep/Ack-results in Vim"-snippet. What I'm currently using to open found files is:

vim $(ack -il "pattern")

Using it is a blaze, but it involves one catch - Vim will open regardless if the number of files found is 0 (in other words, Vim opens with nothing loaded into the buffer). Is there any elegant way to avoid this completely insignificant problem?

Thanks in advance

share|improve this question
up vote 2 down vote accepted

How about this?

files=$(ack -il "pattern") && vim $files

(Tested with grep since I don't have ack.) Note that that won't work if ack returns files with spaces in their names.

share|improve this answer
    
Both solutions provided are fine options, setting this one as the accepted one as it is shorter :) Thanks both! – krystah Sep 22 '13 at 17:37

How about immediately quitting Vim when no arguments have been passed:

vim -c 'if !argc()|quit|endif' $(ack -il "pattern")
share|improve this answer

You must log in to answer this question.

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