简体   繁体   中英

Run vim plugin from vimrc

I'm trying to convert guibg/guifg to ctermbg/ctermfg (gui can use hex while cterm uses named-colors), and I was successful with this github vim script: https://github.com/vim-scripts/guicolorscheme.vim

However, the only way I know how to run this script is in the directions that it gives: :GuiColorScheme <color scheme name>

The problem with this is, every time I open a file with vim, I have to use this command to set the colorscheme. There must be some easier way to use this in your .vimrc file, but I can't seem to get it to work. It doesn't seem to be able to find the script whenever I try and call it.

Some random ways I've tried: call GuiColorScheme("blah") , GuiColorScheme("blah") . I've also looked at autocmd, but have no idea if that's even on the right track

Any ideas?

As an alternative, you could try CSApprox which allows you to save the resulting colorscheme:

:CSApproxSnapshot ~/.vim/colors/foobar.vim

and, ultimately, remove the plugin afterwards.

However, the documentation further says:

NOTE: The generated colorscheme will only work in 88- and 256-color terminals,
      and in GVim. It will not work at all in a terminal with 16 or fewer
      colors. There's just no reliable way to approximate down from
      16,777,216 colors to 16 colors, especially without there being any
      standard for what those 16 colors look like other than 'orange-ish',
      'red-ish', etc.

Since you didn't say if you wanted 256-color-ready values or 16-colors-ready values it's hard to say if that plugin is exactly what you need. While it is possibly feasible to convert programmatically a green-ish hexadecimal value to the word "green" or "lightgreen" you… might not like the result.

The following autocmd should work.

autocmd VimEnter * GuiColorScheme <color scheme name>

It call GuiColorScheme during VimEnter which happens after all normal startup occurs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM