From 7fb6107237376c63de62943619b749d35d8fc853 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 6 Jun 2019 15:00:41 +1200 Subject: Factor out plugin availability checks to function --- vim/autoload/vimrc.vim | 6 ++++++ vim/vimrc | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim index 356861c6..de73720b 100644 --- a/vim/autoload/vimrc.vim +++ b/vim/autoload/vimrc.vim @@ -3,6 +3,12 @@ function! vimrc#EscapeSet(string) abort return escape(a:string, '\ ,') endfunction +" Check that we have a plugin available, and will be loading it +function! vimrc#PluginReady(filename) abort + return globpath(&runtimepath, 'plugin/'.a:filename.'.vim') !=# '' + \ && &loadplugins +endfunction + " Split a string with a split character that can be escaped with another, " e.g. &runtimepath with commas and backslashes respectively function! vimrc#SplitEscaped(str, ...) abort diff --git a/vim/vimrc b/vim/vimrc index b32b7ca6..6c5552d4 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -216,15 +216,16 @@ catch set nocursorline endtry -" Space bar scrolls down a page, :next if plugin available -if &loadplugins +" Space bar scrolls down a page, :next at buffer's end if plugin available +if vimrc#PluginReady('scroll_next') nmap (ScrollNext) else nnoremap endif -" Remap insert Ctrl-C to undo the escaped insert operation -if &loadplugins " Don't break the key if we won't be loading the plugin +" Remap insert Ctrl-C to undo the escaped insert operation, but don't break +" the key if the plugin isn't there +if vimrc#PluginReady('insert_cancel') imap (InsertCancel) endif -- cgit v1.2.3