How can I check whether Vim has the -p (tabs) option or not?

0

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 ...

0xC0000022L

Posted 2012-02-06T15:21:54.873

Reputation: 5 091

Answers

1

$ 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

Dan D.

Posted 2012-02-06T15:21:54.873

Reputation: 5 138

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 – 2012-02-06T15:38:31.147

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 – 2012-02-06T18:44:35.887