1

I want to quickly see all colorschemes available in Vim, without having to click many places or run a lot of manual commands. Is there an automated way to do that?

1 Answer 1

1

animation showing testing different colorschemes

for c in globpath(&rtp, 'colors/*.vim', 0, 1)->map({_, val -> fnamemodify(val, ':t:r')})->sort('i')->uniq('i')
  try
    exec 'colorscheme ' .. c
    redraw
    echo c
  catch
    echo 'ERROR loading colorscheme ' .. c
  finally
    sleep 2
  endtry
endfor
colorscheme default
redraw
echo 'finished. back to default'

Save the file and run it with :so %

(thanks @romainl and @Jürgen Krämer for the improvements suggestions!)

5
  • You are missing all the user's colorschemes with your script.
    – romainl
    Commented Mar 21 at 17:35
  • You don't need an external file. Replace the for c in loop with for c in uniq(sort(map(globpath(&rtp, 'colors/*.vim', 0, 1), {key, val -> fnamemodify(val, ':t:r')}), 'i'), 'i') and Vim will give you a list of all available colorschemes, including the ones from the user themself and from 3rd party packages. Commented Mar 22 at 9:00
  • Great, thanks! Successfully tested on Linux and Windows, GVim and terminal Vim. Updated the code. I changed the chained function calls to become methods.
    – awvalenti
    Commented Mar 22 at 23:38
  • I found a plugin to switch between colorschemes. Haven't tested it, though. vimawesome.com/plugin/vim-colorscheme-switcher
    – awvalenti
    Commented Mar 23 at 11:16
  • I don't know why, it's very slow on Linux GVim. Tried replacing redraw with redraw!, but it didn't work.
    – awvalenti
    Commented Mar 27 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.