Skip to content

Instantly share code, notes, and snippets.

@slimane
Last active December 22, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slimane/6490921 to your computer and use it in GitHub Desktop.
Save slimane/6490921 to your computer and use it in GitHub Desktop.
colorschmeを選択するcommand書いた
command! -nargs=1 -bar -complete=customlist,Favorite_Color FavoriteColor call Set_Favorite_Color(<q-args>)
" colorschemeとそれに関連するGui情報を格納したobject
function! s:color_dict_object(colorscheme, transparency, ...)
let l:color_dict = {}
let l:color_dict.colorscheme = a:colorscheme
let l:color_dict.background = get(a:, '1', '')
let l:color_dict.transparency = a:transparency
return l:color_dict
endfunction
" colorscheme情報格納リスト
let s:colorschmes = []
" 設定したいcolorschemeを追加
call add(s:colorschmes, s:color_dict_object('solarized', 0, 'light'))
call add(s:colorschmes, s:color_dict_object('molokai', 220))
" colorscheme選択のためのcomplete function
function! Favorite_Color(A, P, S)
return map(filter(deepcopy(s:colorschmes), 'v:val.colorscheme =~ a:A'), 'v:val.colorscheme')
endfunction
" colorscheme, background, transparency設定function
function! Set_Favorite_Color(color_name)
let l:color_dicts = filter(deepcopy(s:colorschmes), 'v:val.colorscheme ==# a:color_name')
if len(l:color_dicts) < 1
echomsg a:color_name . ' is not defined'
return
else
let l:color_dict = l:color_dicts[0]
endif
execute 'colorscheme ' . l:color_dict.colorscheme
let &transparency = l:color_dict.transparency
if !empty(l:color_dict.background)
let &background = l:color_dict.background
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment