aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-03 22:24:37 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-03 22:24:37 +1200
commit8ca01a93dc1e9139f7dc74036b3b40586b06ae15 (patch)
tree1cc8ce96019d424f2fa515ce5a5054ae5cc4c3fa /vim/autoload
parentUse autoloaded and correct function for &rtp split (diff)
downloaddotfiles-8ca01a93dc1e9139f7dc74036b3b40586b06ae15.tar.gz
dotfiles-8ca01a93dc1e9139f7dc74036b3b40586b06ae15.zip
Factor out Vim version checks into autoload func
Diffstat (limited to 'vim/autoload')
-rw-r--r--vim/autoload/vimrc.vim27
1 files changed, 27 insertions, 0 deletions
diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim
index 71b29d61..bfbae263 100644
--- a/vim/autoload/vimrc.vim
+++ b/vim/autoload/vimrc.vim
@@ -45,3 +45,30 @@ function! vimrc#SplitEscaped(str, ...) abort
return list
endfunction
+
+" Convenience version function check that should work with 7.0 or newer;
+" takes strings like 7.3.251
+function! vimrc#Version(verstr) abort
+
+ " Throw toys if the string doesn't match the expected format
+ if a:verstr !~# '^\d\+\.\d\+.\d\+$'
+ echoerr 'Invalid version string: '.a:verstr
+ endif
+
+ " Split version string into major, minor, and patch level integers
+ let [major, minor, patch] = split(a:verstr, '\.')
+
+ " Create a string like 801 from a version number 8.1 to compare it to
+ " the v:version integer
+ let ver = major * 100 + minor
+
+ " Compare versions
+ if v:version > ver
+ return 1 " Current Vim is newer than the wanted one
+ elseif ver < v:version
+ return 0 " Current Vim is older than the wanted one
+ else
+ return has('patch'.patch) " Versions equal, return patch presence
+ endif
+
+endfunction