What I want to do:
Given: I'm using the colorsupport.vim plugin to make my 'gui' colorscheme work in terminal.
And: colorsupport.vim has a command 'ColorSupportSave' that let's me save the 'converted' colorscheme.
Then: On startup, I want to use the 'converted' colorscheme if present, else create it
I would think, that after checking the 'ColorSupport' exists and the converted colorscheme does not, that I could just
execute 'colorscheme benjamin'
" then either
execute 'ColorSchemeSave benjamin-colorsupport'
" or lower-level
call s:colorscheme_save("benjamin-colorsupport")
but with the former I get 492: Not an editor command: ColorSchemeSave benjamin-colorsupport
and with the latter I get E117: Unknown function: <SNR>19_colorscheme_save
clearly I don't understand how these functions/commands are different from others I'm successfully scripting. (I'm new at this. I've read docs and other questions, but haven't quite figured it out)
Here's how the colorsupport.vim function and commands are defined, in brief
function! s:colorscheme_save(...)
" snip
endfunction
command! -nargs=? ColorSchemeSave :call s:colorscheme_save(<f-args>)
Here are, with more context, the relevant parts of my vimrc
set nocompatible " be iMproved
filetype off " required!
set runtimepath+=~/.vim/bundle/vundle/
call vundle#begin()
Plugin 'gmarik/vundle'
Plugin 'vim-scripts/colorsupport.vim'
call vundle#end() " required
filetype plugin indent on " required
if has("gui_running")
" stuff
else
if &term != 'cygwin'
silent !echo "setting 256 color term"
set t_Co=256
endif
let mycolorscheme = 'benjamin'
" wrap color scheme in gui->term plugins
if exists('##ColorScheme')
if filereadable(expand("$HOME/.vim/colors/".mycolorscheme."-colorsupport.vim")) ||
\ filereadable(expand("$HOME/vimfiles/colors/".mycolorscheme."- colorsupport.vim"))
silent !echo "using colorsupport.vim with ".mycolorscheme."-colorsupport"
execute 'colorscheme '.mycolorscheme.'-colorsupport'
else
silent !echo "using colorsupport.vim with ".mycolorscheme
execute 'colorscheme '.mycolorscheme
" can't figure out how to get this working in the script
" silent !echo "using colorsupport.vim with ".mycolorscheme."-colorsupport"
" execute 'ColorSchemeSave '.mycolorscheme.'-colorsupport'
" or lower-level
" call s:colorscheme_save("'.mycolorscheme.'-colorsupport")
endif
endif
endif
Answers culled from the responses:
refs:
- https://stackoverflow.com/a/26739615/879854
- https://stackoverflow.com/a/17688716/879854
- https://twitter.com/garybernhardt/status/529664734040432640
vimrc is loaded before plugins.
If you look at :h initialization you will find that step 3 is load vimrc and step 4 is load plugins.
You can also see that vimrc is loaded before plugins by looking at the output of :scriptnames. scriptnames lists all sourced scripts in the order they were sourced and vimrc is the first thing sourced. (Take a look at :h :scriptnames).
So create the file .vim/after/plugin/colorsupport.vim
it is also possible to achieve the same goal utilizing the autocmd event VimEnter. Because Event VimEnter is performed after all other startup stuff, commands called with this autocmd will take place after the loading of all plugins. The procedure is as following:
First create a function including all the plugin specific scripts in it.
function! g:LoadPluginScript () " ColorSupport {{{ if exists(":ColorSchemeSave") " stuff endif " }}} endfunction augroup plugin_initialize autocmd! autocmd VimEnter * call LoadPluginScript() augroup