Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to figure out in my .bashrc (or one of the files it sources) whether Vim has the -p option available and if so create an alias.

Now, that same .bashrc is used on numerous systems including some ancient ones where Vim still doesn't know the -p option.

What I need is a way to check for the availability of the option without actually starting up Vim ...

vim -p || echo "Not available"

... where instead of the echo I do something else came to mind, but unfortunately that only works when the -p option is not available. When it is available, this will actually start up Vim, which is what I want to avoid.

I've experimented with opening /dev/null and /dev/zero to no avail ...

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted
$ vim --help | grep "\-p"
   -p[N]        Open N tab pages (default: one for each file)

So why not use:

if [ -n "$(vim --help | grep "\-p")" ]; then 
    echo "set your option here";
fi
share|improve this answer
    
Well, because sometimes one is blind to such simple solutions ;) ... thanks a lot. Using basically: vim --help|grep -q '[:space:]*-p' || echo test now ... that seems to work (of course I am using something other than echo there). –  0xC0000022L Feb 6 '12 at 15:38
    
In your example you need to use [[:space:]] and probably \+ instead of *. An alternate example: vim --help | grep -q '[[:space:]]\+-p' && echo 'yes' || echo 'no' –  Heptite Feb 6 '12 at 18:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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