【发布时间】:2014-11-05 00:29:05
【问题描述】:
我想做的事:
Given:我正在使用colorsupport.vim 插件使我的“gui”颜色方案在终端中工作。
而且:colorsupport.vim 有一个命令'ColorSupportSave',让我保存'转换'的颜色方案。
然后:在启动时,我想使用“转换后的”颜色方案(如果存在),否则创建它
我认为,在检查“ColorSupport”存在并且转换后的颜色方案不存在之后,我可以这样做
execute 'colorscheme benjamin'
" then either
execute 'ColorSchemeSave benjamin-colorsupport'
" or lower-level
call s:colorscheme_save("benjamin-colorsupport")
但是对于前者我得到492: Not an editor command: ColorSchemeSave benjamin-colorsupport
后者我得到E117: Unknown function: <SNR>19_colorscheme_save
很明显,我不明白这些函数/命令与我成功编写脚本的其他函数/命令有何不同。 (我是新手。我已经阅读了文档和其他问题,但还没有完全弄清楚)
以下是colorsupport.vim 函数和命令的定义方式,简要
function! s:colorscheme_save(...)
" snip
endfunction
command! -nargs=? ColorSchemeSave :call s:colorscheme_save(<f-args>)
这里有更多上下文,我的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
从回复中挑选出的答案:
参考:
- https://stackoverflow.com/a/26739615/879854
- https://stackoverflow.com/a/17688716/879854
- https://twitter.com/garybernhardt/status/529664734040432640
vimrc 在插件之前加载。
如果您查看 :h 初始化,您会发现第 3 步已加载 vimrc 和第 4 步是加载插件。
您还可以通过查看 :scriptnames 的输出。 scriptnames 列出了 它们是采购的顺序,vimrc 是第一件采购的东西。 (取一个 看看 :h :scriptnames)。
所以创建文件 .vim/after/plugin/colorsupport.vim
也可以使用 autocmd 实现相同的目标 事件 VimEnter。因为事件 VimEnter 是在所有其他事件之后执行的 启动的东西,用这个自动命令调用的命令将在之后发生 所有插件的加载。流程如下:
首先创建一个包含所有插件特定脚本的函数 它。
function! g:LoadPluginScript () " ColorSupport {{{ if exists(":ColorSchemeSave") " stuff endif " }}} endfunction augroup plugin_initialize autocmd! autocmd VimEnter * call LoadPluginScript() augroup
【问题讨论】:
标签: vim