Closed bzp99 closed 2 years ago
In the meantime, I found the following solution:
function! IsPluginLoaded(name)
return !empty(globpath(&rtp, '**' . a:name . '*'))
endfunction
if IsPluginLoaded('gruvbox')
colorscheme gruvbox
endif
I wish there was a cleaner solution, but I am closing this. Sorry for the noise.
I take it back. What I actually wanted to write as the pattern is '**/*' . a:name . '*'
but this causes Neovim to hang on startup. I assume it’s too inefficient to go through all the files like this.
@bzp99 Normally you should add your colorschemes under opt/
subtree, so they never get into runtimepath (keeping it as short as possible). Then just try to load it and see if it works
function! SetColors(name) abort
execute 'silent! colorscheme' a:name
return exists('g:colors_name') && g:colors_name is# a:name
endfunction
...
eval SetColors('gruvbox') || SetColors('peachpuff')
@matveyt thank you, that is good to know. But what about more generic cases? For example, setting mappings if a plugin is loaded. For example, I currently have
if IsPluginLoaded('cosco')
nmap <silent> <leader>; <plug>(cosco-commaOrSemicolon)
endif
Is there a better or more efficient way to do this or to implement IsPluginLoaded
better? Or would you consider this a good solution?
@bzp99 Plugins are normally loaded after vimrc, so it is a bit harder than you probably think. Especially, for a totally generic recommendation.
Speaking of mappings, I suggest not to check anything at all. If you won't have the plugin then the mapping will not do anything, so why bother?
I see, thank you. I realized there is really no need for the checks I had sought. In all cases, I could either skip the whole check and in some others, I switched to autocmd
s based on filetype.
I have been using constructs like
But this suddenly stopped working since I just updated
neovim
andminpac
. I see that&rtp
looks like this:So I guess this method is no longer suitable. Is there a recommended way to do this?