Skip to content

Commit

Permalink
Implement request in issue #3 (option to override :colorscheme command)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jun 20, 2014
1 parent 9c52c02 commit 25265ac
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -51,6 +51,10 @@ A list with names of color schemes to be ignored by the plug-in. By default the

:let g:colorscheme_switcher_exclude = ['default', 'test']

### The `g:colorscheme_switcher_command` option

This option is a string specifying the Vim command used to switch between color schemes. It defaults to the [:colorscheme] [cs] command. You can set this option to integrate the vim-colorscheme-switcher plug-in with other plug-ins like [colorsupport.vim](https://github.com/vim-scripts/colorsupport.vim) and [guicolorscheme.vim](https://github.com/vim-scripts/guicolorscheme.vim).

## Known problems

The way Vim color schemes are written isn't really compatible with the idea of quickly switching between lots of color schemes. In my opinion this is an ugly implementation detail of how Vim works internally, in other words I think it's a bug that should be fixed... Here are some references that explain the problem in some detail:
Expand Down
10 changes: 6 additions & 4 deletions autoload/xolox/colorscheme_switcher.vim
@@ -1,9 +1,9 @@
" Vim plug-in
" Maintainer: Peter Odding <peter@peterodding.com>
" Last Change: June 19, 2014
" Last Change: June 20, 2014
" URL: http://peterodding.com/code/vim/colorscheme-switcher

let g:xolox#colorscheme_switcher#version = '0.3'
let g:xolox#colorscheme_switcher#version = '0.4'

" Dictionary with previously seen links between highlighting groups.
if !exists('s:known_links')
Expand Down Expand Up @@ -120,13 +120,15 @@ endfunction
function! xolox#colorscheme_switcher#switch_to(name) " {{{1
" Switch to the given color scheme.
call xolox#colorscheme_switcher#find_links()
execute 'colorscheme' fnameescape(a:name)
call xolox#colorscheme_switcher#restore_links()
execute g:colorscheme_switcher_command fnameescape(a:name)
" Set the global colors_name variable because some color scheme scripts fail
" to do so or use the wrong name (for example rainbow_autumn uses autumn).
let g:colors_name = a:name
" Enable the user to customize the loaded color scheme.
silent execute 'doautocmd ColorScheme' fnameescape(a:name)
" Restore syntax group links as the last step to make sure the syntax group
" links are not clobbered by user defined automatic commands.
call xolox#colorscheme_switcher#restore_links()
endfunction

function! xolox#colorscheme_switcher#random_number(limit) " {{{1
Expand Down
27 changes: 19 additions & 8 deletions doc/colorscheme-switcher.txt
Expand Up @@ -13,6 +13,7 @@ Contents ~
1. The |g:colorscheme_switcher_define_mappings| option
2. The |g:colorscheme_switcher_keep_background| option
3. The |g:colorscheme_switcher_exclude| option
4. The |g:colorscheme_switcher_command| option
5. Known problems |colorscheme-switcher-known-problems|
6. Contact |colorscheme-switcher-contact|
7. License |colorscheme-switcher-license|
Expand Down Expand Up @@ -110,6 +111,14 @@ list is empty. Here's an example of how you can set this:
>
:let g:colorscheme_switcher_exclude = ['default', 'test']
<
-------------------------------------------------------------------------------
The *g:colorscheme_switcher_command* option

This option is a string specifying the Vim command used to switch between color
schemes. It defaults to the |:colorscheme| command. You can set this option to
integrate the vim-colorscheme-switcher plug-in with other plug-ins like
colorsupport.vim [7] and guicolorscheme.vim [8].

===============================================================================
*colorscheme-switcher-known-problems*
Known problems ~
Expand All @@ -120,8 +129,8 @@ implementation detail of how Vim works internally, in other words I think it's
a bug that should be fixed... Here are some references that explain the problem
in some detail:

- Vim colorscheme leaves a wake of destruction when switching away [7]
- gVim: remove syntax highlighting groups [8]
- Vim colorscheme leaves a wake of destruction when switching away [9]
- gVim: remove syntax highlighting groups [10]

Since this behavior hinders cycling through color schemes, the colorscheme
switcher plug-in includes a workaround that should hide the problem:
Expand Down Expand Up @@ -155,13 +164,13 @@ If you have questions, bug reports, suggestions, etc. the author can be
contacted at peter@peterodding.com. The latest version is available at
http://peterodding.com/code/vim/colorscheme-switcher/ and
http://github.com/xolox/vim-colorscheme-switcher. If you like this plug-in
please vote for it on Vim Online [9].
please vote for it on Vim Online [11].

===============================================================================
*colorscheme-switcher-license*
License ~

This software is licensed under the MIT license [10]. Š 2014 Peter Odding
This software is licensed under the MIT license [12]. Š 2014 Peter Odding
<peter@peterodding.com>.

===============================================================================
Expand All @@ -174,9 +183,11 @@ References ~
[4] https://github.com/gmarik/vundle
[5] http://github.com/xolox/vim-colorscheme-switcher
[6] http://github.com/xolox/vim-misc
[7] https://github.com/altercation/solarized/issues/102
[8] http://stackoverflow.com/questions/12915797/gvim-remove-syntax-highlighting-groups
[9] http://www.vim.org/scripts/script.php?script_id=4586
[10] http://en.wikipedia.org/wiki/MIT_License
[7] https://github.com/vim-scripts/colorsupport.vim
[8] https://github.com/vim-scripts/guicolorscheme.vim
[9] https://github.com/altercation/solarized/issues/102
[10] http://stackoverflow.com/questions/12915797/gvim-remove-syntax-highlighting-groups
[11] http://www.vim.org/scripts/script.php?script_id=4586
[12] http://en.wikipedia.org/wiki/MIT_License

vim: ft=help
7 changes: 6 additions & 1 deletion plugin/colorscheme-switcher.vim
@@ -1,6 +1,6 @@
" Vim plug-in
" Maintainer: Peter Odding <peter@peterodding.com>
" Last Change: June 19, 2014
" Last Change: June 20, 2014
" URL: http://peterodding.com/code/vim/colorscheme-switcher

" This Vim plug-in defines two commands and four key mappings to quickly
Expand Down Expand Up @@ -43,6 +43,11 @@ if !exists('g:colorscheme_switcher_exclude')
let g:colorscheme_switcher_exclude = []
endif

" Change this variable to set the Vim command used to activate color schemes.
if !exists('g:colorscheme_switcher_command')
let g:colorscheme_switcher_command = 'colorscheme'
endif

if g:colorscheme_switcher_define_mappings
inoremap <silent> <F8> <C-O>:NextColorScheme<CR>
nnoremap <silent> <F8> :NextColorScheme<CR>
Expand Down

0 comments on commit 25265ac

Please sign in to comment.