3

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.)

Community
  • 1
  • 1
Brady Trainor
  • 2,026
  • 20
  • 18
  • What is ` ` supposed to do? – merlin2011 Jul 25 '14 at 23:36
  • @merlin2011, simply, it makes the `wildmenu`/`wildmode` kick in. `wildcharm` assigns `` to `` for including in macros. So `` makes the tab completion options appear, but also enters the first item in the tab completion list in the command line. Then, `` reverses that, so that tab completion list still appears, but you can type from where you left off to limit completion candidates. – Brady Trainor Jul 25 '14 at 23:57
  • @merlin2011 Oh, I just realized, the behavior of `Tab` may have some dependence on what I have `wildmenu` and `wildmode` are set to (how many items in `wildmode`, as a comma separated list?). I will add these. – Brady Trainor Jul 26 '14 at 00:00
  • Well, it's easy enough to use `,c` to see the colorscheme. Now I have similar for `,a` is `AirlineTheme`. – Brady Trainor Jul 26 '14 at 04:44

1 Answers1

2

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()

FDinoff
  • 30,689
  • 5
  • 75
  • 96