Reputation: 110572
I have the following attempt at a vim script to check to see if it is installed and if its version is recent (8+):
# Check if we have vim version 8.1+ installed
VIM_PATH=$(which vim)
VIM_VERSION=$(vim --version |grep '8.[123]')
if [ -z "$VIM_PATH" || -z "$VIM_VERSION" ]
then
...
fi
Is the above a valid script? What might be a better way to grab the version and check if
Upvotes: 1
Views: 1272
Reputation: 240769
Since vim --version
isn't very machine-readable, I would be tempted to try
if vim --cmd 'if v:version >= 801 | q | else | cq | fi' ; then
# vim at least 8.1
fi
which uses a snippet of vim script to do the comparison. --cmd
runs a command before opening any files or running .vimrc
; the cq
command exits with an error status, and q
exits with a success status (necessary because otherwise vim would want to edit a blank file!). |
allows placing multiple vim commands on a single line, like ;
in shell.
Upvotes: 7