Created
June 20, 2017 15:05
-
-
Save Raimondi/14650ef050996704df2498321961e2df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Raimondi @ Freenode | |
" | |
" - Next | |
" - Previous | |
" - Jump to start | |
" - Jump to end | |
" - Jump to N | |
" - Jump by N | |
" - List color schemes | |
" - Refresh color scheme list | |
" - Print current's name | |
" - Handle favorites | |
function! s:setup() | |
if exists('s:setup') | |
return | |
endif | |
let s:setup = 1 | |
let s:favorites = [] | |
let s:name = get(g:, 'colors_name', 'default') | |
let s:original = s:name | |
call s:refresh() | |
endfunction | |
function! s:jump2color(dest) | |
if !get(s:, 'setup', 0) | |
call s:setup() | |
endif | |
let s:index = a:dest % (s:last + 1) | |
let s:name = s:colors[s:index] | |
execute 'colorscheme ' . fnameescape(s:name) | |
redraw | |
call s:print_info() | |
endfunction | |
function! s:restore() | |
execute 'colorscheme ' . fnameescape(s:original) | |
call s:print_info() | |
endfunction | |
function! s:refresh() | |
let s:colors = globpath(&rtp, 'colors/*.vim', 0, 1) | |
call map(s:colors, 'fnamemodify(v:val, ":t:r")') | |
call sort(s:colors) | |
call uniq(s:colors) | |
let s:index = index(s:colors, s:name) | |
let s:last = len(s:colors) - 1 | |
endfunction | |
function! s:print_info() | |
let index = index(s:colors, g:colors_name) + 1 | |
let last = s:last + 1 | |
echo printf('Color scheme %d/%d: %s', index, last, g:colors_name) | |
endfunction | |
function! s:print_list(list) | |
let padding = float2nr(log10(len(a:list))) + 1 | |
for item in a:list | |
let index = index(s:colors, item) | |
echo printf('%' . padding . 'd %s', index + 1, item) | |
endfor | |
endfunction | |
function! s:add_favorite() | |
call add(s:favorites, s:name) | |
call sort(s:favorites) | |
call uniq(s:favorites) | |
endfunction | |
function! s:remove_favorite() | |
let idx = index(s:favorites, s:name) | |
if idx < 0 | |
return | |
endif | |
call remove(s:favorites, idx) | |
endfunction | |
function! s:random() | |
return str2nr(matchstr(reltimestr(reltime()), '\d\+$')[1:]) | |
endfunction | |
command! -count=1 CSNext call s:setup() | |
\ | call s:jump2color(s:index + 1 * <count>) | |
command! -count=1 CSPrevious call s:setup() | |
\ | call s:jump2color(s:index - 1 * <count>) | |
command! -count=1 CSGoTo call s:setup() | call s:jump2color(<count> - 1) | |
command! CSRestore call s:setup() | call s:restore() | |
command! CSInfo call s:setup() | call s:print_info() | |
command! CSNames call s:setup() | call s:print_list(s:colors) | |
command! CSAddFavorite call s:setup() | call s:add_favorite() | |
command! CSRemoveFavorite call s:setup() | call s:remove_favorite() | |
command! CSFavorites call s:setup() | call s:print_list(s:favorites) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment