Reputation: 2076
I found a post where one asks how to show the current colorscheme
. I'd like to combine this with the prompt. That is, separately, :colorscheme>CR>
and :colorscheme <C-z><S-Tab>
work, as showing and prompting for colorscheme
respectively. I'm not sure how to combine these into one command. Here are my attempts,
nnoremap <leader>c :echo g:colors_name \n<CR>
function! Colors()
:colorscheme<cr>
:colorscheme <C-z><S-Tab>
endfunction
nnoremap <leader>c :exec Colors()
nnoremap <leader>c :colorscheme<cr>:colorscheme <C-z><S-Tab>
nnoremap <leader>c :echo g:colors_name<cr><bar>:colorscheme <C-z><S-Tab>
Separately, these two work:
nnoremap <leader>s :colorscheme<CR>
nnoremap <leader>c :colorscheme <C-z><S-Tab>
(By the way, I use set wildcharm=<C-z>
and set wildmenu wildmode=list:full
.)
Upvotes: 3
Views: 1294
Reputation: 31429
I'm not sure if you can combine them into one command. I wrote a function to find all color schemes print the current and prompt you for a list. The current color scheme name is contained in g:colors_name
.
function! PromptList(prompt, list)
let l:copy = copy(a:list)
for i in range(len(l:copy))
let l:copy[i] = (i + 1) . '. ' . l:copy[i]
endfor
let l:ret = inputlist([a:prompt] + l:copy)
if l:ret > 0 && l:ret < len(a:list)
return a:list[l:ret - 1]
else
return ''
endif
endfunction
function! ChangeColorscheme()
" Get a sorted list with the available color schemes.
let l:list = sort(map(
\ split(globpath(&runtimepath, 'colors/*.vim'), '\n'),
\ 'fnamemodify(v:val, ":t:r")'))
let l:prompt = 'Current color scheme is ' . g:colors_name
let l:color = PromptList(l:prompt, l:list)
if l:color != ''
exec 'colorscheme' l:color
endif
endfunction
To use it type :call ChangeColorscheme()
Upvotes: 2