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

1 Answer 1

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
2
  • 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). Feb 6, 2012 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, 2012 at 18:44

You must log in to answer this question.

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