Loading ...
Sorry, an error occurred while loading the content.

Re: color scheme switcher

Expand Messages
  • David Rennalls
    ... It s not exactly what you had in mind, but this might interest you.. Colors Sampler Pack : [full update] All the color schemes on vim.sf.net (now with
    Message 1 of 13 , Jul 5, 2005
    View Source
    • 0 Attachment
      On 7/5/05, Steve Felt <steve@...> wrote:
      > Could a button be mapped to rotate through installed color schemes? Is
      > vim aware of the files in ~/.vim, ~/.vim/colors etc?
      >
      > If so, I guess it would be trivial (for someone more capable in vim
      > scripting than I am) to create a function which changes the colorscheme
      > to the next colorscheme and wraps at the end?
      >
      > My-oh-my, this would be neeeato. As I'm learning scripting, I'd be
      > thrilled with examples/suggestions that might help me to write this
      > script... if it hasn't been written already.
      >
      > --
      >
      > -steve

      It's not exactly what you had in mind, but this might interest you..

      Colors Sampler Pack : [full update] All the color schemes on
      vim.sf.net (now with organized menu)
      http://www.vim.org/scripts/script.php?script_id=625

      - David
    • Steve Felt
      ... Is ... colorscheme ... Actually, this pack of 140 color schemes is the impetus for my question! ... -- Steve Felt CirclePix.com
      Message 2 of 13 , Jul 5, 2005
      View Source
      • 0 Attachment
        On Tue, 2005-07-05 at 11:25, David Rennalls wrote:
        > On 7/5/05, Steve Felt <steve@...> wrote:
        > > Could a button be mapped to rotate through installed color schemes?
        Is
        > > vim aware of the files in ~/.vim, ~/.vim/colors etc?
        > >
        > > If so, I guess it would be trivial (for someone more capable in vim
        > > scripting than I am) to create a function which changes the
        colorscheme
        > > to the next colorscheme and wraps at the end?
        > >
        > > My-oh-my, this would be neeeato. As I'm learning scripting, I'd be
        > > thrilled with examples/suggestions that might help me to write this
        > > script... if it hasn't been written already.
        > >
        > > --
        > >
        > > -steve
        >
        > It's not exactly what you had in mind, but this might interest you..
        >
        > Colors Sampler Pack : [full update] All the color schemes on
        > vim.sf.net (now with organized menu)
        > http://www.vim.org/scripts/script.php?script_id=625
        >
        > - David

        Actually, this pack of 140 color schemes is the impetus for my question!
        :-)

        --
        Steve Felt <steve@...>
        CirclePix.com
      • Halim, Salman
        I uploaded a script a while ago to allow different filetypes/buffers to have their own colorschemes. I have another one that sets a randomly chosen color
        Message 3 of 13 , Jul 5, 2005
        View Source
        • 0 Attachment
          I uploaded a script a while ago to allow different filetypes/buffers to
          have their own colorschemes. I have another one that sets a randomly
          chosen color scheme from the available list. I'm sure it would be
          pretty easy to read the entire list into a variable and rotate, though I
          prefer the unpredictability of the randomizer myself. (The randomizer
          uses Dr. Chip's Rndm plugin.)

          You can easily get the list of color schemes via globpath or some such;
          retrieve the current scheme name from a variable, find the one
          immediately after it in the globbed list and set it, storing this new
          scheme name in the variable. If you get to the every end (there is no
          'next' scheme), just pick the first one.

          Salman.

          > -----Original Message-----
          > From: Steve Felt [mailto:steve@...]
          > Sent: Tuesday, July 05, 2005 1:59 PM
          > To: David Rennalls
          > Cc: vim mailing list
          > Subject: Re: color scheme switcher
          >
          > On Tue, 2005-07-05 at 11:25, David Rennalls wrote:
          > > On 7/5/05, Steve Felt <steve@...> wrote:
          > > > Could a button be mapped to rotate through installed
          > color schemes?
          > Is
          > > > vim aware of the files in ~/.vim, ~/.vim/colors etc?
          > > >
          > > > If so, I guess it would be trivial (for someone more
          > capable in vim
          > > > scripting than I am) to create a function which changes the
          > colorscheme
          > > > to the next colorscheme and wraps at the end?
          > > >
          > > > My-oh-my, this would be neeeato. As I'm learning
          > scripting, I'd be
          > > > thrilled with examples/suggestions that might help me to
          > write this
          > > > script... if it hasn't been written already.
          > > >
          > > > --
          > > >
          > > > -steve
          > >
          > > It's not exactly what you had in mind, but this might interest you..
          > >
          > > Colors Sampler Pack : [full update] All the color schemes on
          > > vim.sf.net (now with organized menu)
          > > http://www.vim.org/scripts/script.php?script_id=625
          > >
          > > - David
          >
          > Actually, this pack of 140 color schemes is the impetus for
          > my question!
          > :-)
          >
          > --
          > Steve Felt <steve@...>
          > CirclePix.com
          >
        • Scott C
          ... steve: *if* you have a python enabled gvim, the following will cycle through the colorschemes saved in favs.txt (you ll have to fix the linebreaks): #
          Message 4 of 13 , Jul 5, 2005
          View Source
          • 0 Attachment
            --- Steve Felt <steve@...> wrote:

            > On Tue, 2005-07-05 at 11:25, David Rennalls wrote:
            > > On 7/5/05, Steve Felt <steve@...> wrote:
            > > > Could a button be mapped to rotate through
            > installed color schemes?
            > Is
            > > > vim aware of the files in ~/.vim, ~/.vim/colors
            > etc?
            > > >
            > > > If so, I guess it would be trivial (for someone
            > more capable in vim
            > > > scripting than I am) to create a function which
            > changes the
            > colorscheme
            > > > to the next colorscheme and wraps at the end?
            > > >
            > > > My-oh-my, this would be neeeato. As I'm learning
            > scripting, I'd be
            > > > thrilled with examples/suggestions that might
            > help me to write this
            > > > script... if it hasn't been written already.
            > > >
            > > > --
            > > >
            > > > -steve
            > >
            > > It's not exactly what you had in mind, but this
            > might interest you..
            > >
            > > Colors Sampler Pack : [full update] All the color
            > schemes on
            > > vim.sf.net (now with organized menu)
            > >
            > http://www.vim.org/scripts/script.php?script_id=625
            > >
            > > - David
            >
            > Actually, this pack of 140 color schemes is the
            > impetus for my question!
            > :-)
            >
            > --
            > Steve Felt <steve@...>
            > CirclePix.com
            >

            steve:

            *if* you have a python enabled gvim, the following
            will cycle through the colorschemes saved in
            "favs.txt" (you'll have to fix the linebreaks):

            # 30 Mar 2002
            # scott
            #
            # this script cycles through all colorschemes listed
            # (without the .vim extension) in a module specified
            on
            # line 22
            #
            import os
            import string
            import sys
            import vim

            cnt = 0 #
            counter
            c_list = [] # color
            list

            ############################################################
            ##
            ##
            ## note: the following open will need to be
            customized ##
            ## per installation
            ##
            ##
            ##
            ############################################################
            f = open("c:/vim/vimfiles/colors/favs.txt", "r")
            c_list = f.readlines()
            f.close()

            d_list = []
            for i in range(len(c_list)):
            d_list.append(string.rstrip(c_list[i]))

            # at this point we have an array of colorschemes in
            d_list
            cnt = len(d_list)

            if cnt < 1:
            print "there are no colorschemes installed"
            sys.exit(1) # this
            exit needs to be tested...

            try:
            curr_color = vim.eval("colors_name") #
            doesn't work when not defined
            except vim.error:
            curr_color = "none"

            # let's say we got here with a color - let's move to
            the next one

            n = 0
            for i in range(0, cnt):
            if curr_color == d_list[i]:
            n = i + 1
            break

            if n == cnt:
            n = 0

            vim.command("colorscheme %s" % d_list[n])

            <end paste>

            hth,

            scott




            ____________________________________________________
            Yahoo! Sports
            Rekindle the Rivalries. Sign up for Fantasy Football
            http://football.fantasysports.yahoo.com
          • Tim Chase
            ... Why, of course! This is vim :) nnoremap :exec colorscheme .substitute(expand($VIMRUNTIME. /colors/*.vim ),
            Message 5 of 13 , Jul 5, 2005
            View Source
            • 0 Attachment
              > Could a button be mapped to rotate through installed color
              > schemes? Is vim aware of the files in ~/.vim, ~/.vim/colors
              > etc?

              Why, of course! This is vim :)

              nnoremap <f4> :exec "colorscheme
              ".substitute(expand($VIMRUNTIME."/colors/*.vim"),
              '.*[/\\]'.colors_name.'\.vim\c[[:cntrl:]]*[^[:cntrl:]]*[/\\]\([^.]*\).*',
              '\1', 'g')<cr>

              Note 1: this is all one line.
              Note 2: though you may not be able to see it, there's a space
              after that last "<cr>" making it "<cr> " so that it dismisses the
              "press return to continue" sort of prompt that comes up.

              It doesn't wrap, and it doesn't do any initialization, so you'll
              have to prime it by setting your colorscheme to the first one in
              the list by doing

              :colorscheme <tab>

              where you actually hit <tab> there. This should snag the first
              one it finds. Once it hits the end of the list, it will just
              keep that one. Not very exciting.

              I did this on Win32 vim, which only has one color location.
              However, a little manipulation should be able to build a
              combination of multiple locations...changing the

              expand($VIMRUNTIME."/colors/*.vim")

              to be something like

              expand($VIMRUNTIME."/colors/*.vim")."\n".expand($OTHER_PATH...)

              If you need that monstrosity broken down, let me know and I'll
              try and shed a little light on it :)

              -tim
            • Scott LaBounty
              Tim, I just tried this out with Window XP and I get E185: Cannot find color scheme C:/Program Files/vim/vim63/colors/blue.vim . If I go ahead and just do a
              Message 6 of 13 , Jul 5, 2005
              View Source
              • 0 Attachment
                Tim,

                I just tried this out with Window XP and I get "E185: Cannot find color
                scheme C:/Program Files/vim/vim63/colors/blue.vim". If I go ahead and
                just do a "colorscheme blue then following that the switch will work.
                Any thoughts?

                Scott LaBounty
                Nexa Technologies, Inc.

                Tim Chase wrote:

                >> Could a button be mapped to rotate through installed color
                >> schemes? Is vim aware of the files in ~/.vim, ~/.vim/colors
                >> etc?
                >
                >
                > Why, of course! This is vim :)
                >
                > nnoremap <f4> :exec "colorscheme
                > ".substitute(expand($VIMRUNTIME."/colors/*.vim"),
                > '.*[/\\]'.colors_name.'\.vim\c[[:cntrl:]]*[^[:cntrl:]]*[/\\]\([^.]*\).*',
                > '\1', 'g')<cr>
                >
                > Note 1: this is all one line.
                > Note 2: though you may not be able to see it, there's a space after
                > that last "<cr>" making it "<cr> " so that it dismisses the "press
                > return to continue" sort of prompt that comes up.
                >
                > It doesn't wrap, and it doesn't do any initialization, so you'll have
                > to prime it by setting your colorscheme to the first one in the list
                > by doing
                >
                > :colorscheme <tab>
                >
                > where you actually hit <tab> there. This should snag the first one it
                > finds. Once it hits the end of the list, it will just keep that one.
                > Not very exciting.
                >
                > I did this on Win32 vim, which only has one color location. However, a
                > little manipulation should be able to build a combination of multiple
                > locations...changing the
                >
                > expand($VIMRUNTIME."/colors/*.vim")
                >
                > to be something like
                >
                > expand($VIMRUNTIME."/colors/*.vim")."\n".expand($OTHER_PATH...)
                >
                > If you need that monstrosity broken down, let me know and I'll try and
                > shed a little light on it :)
                >
                > -tim
                >
                >
                >
                >
                >
                >
                >
              • Tim Chase
                ... I did find that when it hit the last one in the list, I got this error back when there were no more to try. I think it may actually be trying to set the
                Message 7 of 13 , Jul 5, 2005
                View Source
                • 0 Attachment
                  > I just tried this out with Window XP and I get "E185: Cannot find color
                  > scheme C:/Program Files/vim/vim63/colors/blue.vim". If I go ahead and
                  > just do a "colorscheme blue then following that the switch will work.
                  > Any thoughts?

                  This may be an artifact of the caveat:

                  >> It doesn't wrap, and it doesn't do any initialization,

                  I did find that when it hit the last one in the list, I got this
                  error back when there were no more to try. I think it may
                  actually be trying to set the colorscheme to a multi-line string.
                  Haven't played with it that far. However, if you prime it the
                  first time (which usually ends up being "blue"), you should be
                  able to walk through all the colors pretty easily.

                  To fix it, you may be able to wrap the whole bloody substitute()
                  expression in yet another subsitute() expression, something to
                  the effect

                  substitute(substitute(...),'[^[:cntrl:]]*[/\\]\([^.]*\).vim\c.*','\1','')

                  making the whole lot:

                  nnoremap <f4> :exec "colorscheme
                  ".substitute(substitute(expand($VIMRUNTIME."/colors/*.vim"),
                  '.*[/\\]'.colors_name.'\.vim\c[[:cntrl:]]*[^[:cntrl:]]*[/\\]\([^.]*\).*',
                  '\1', 'g'), '[^[:cntrl:]]*[/\\]\([^.]*\).vim\c.*','\1','')<cr><cr>

                  which seemed to work for me to get rid of that and solve the
                  wrapping problem. I also found that I could change that
                  invisible trailing space to a 2nd <cr> and it was just as happy.

                  Anybody else having a rough day focusing on doing *real* work? :*)

                  -tim
                • Scott LaBounty
                  Tim, What? I m supposed to read the whole thing not just copy the important bits???? OK, the latest looks great! Scott P.S. Real work, what a concept. I may
                  Message 8 of 13 , Jul 5, 2005
                  View Source
                  • 0 Attachment
                    Tim,

                    What? I'm supposed to read the whole thing not just copy the important
                    bits???? OK, the latest looks great!

                    Scott

                    P.S. Real work, what a concept. I may have to try it later today or
                    tomorrow. Thursday at the latest.

                    Tim Chase wrote:

                    >> I just tried this out with Window XP and I get "E185: Cannot find
                    >> color scheme C:/Program Files/vim/vim63/colors/blue.vim". If I go
                    >> ahead and just do a "colorscheme blue then following that the switch
                    >> will work. Any thoughts?
                    >
                    >
                    > This may be an artifact of the caveat:
                    >
                    >>> It doesn't wrap, and it doesn't do any initialization,
                    >>
                    >
                    > I did find that when it hit the last one in the list, I got this error
                    > back when there were no more to try. I think it may actually be
                    > trying to set the colorscheme to a multi-line string. Haven't played
                    > with it that far. However, if you prime it the first time (which
                    > usually ends up being "blue"), you should be able to walk through all
                    > the colors pretty easily.
                    >
                    > To fix it, you may be able to wrap the whole bloody substitute()
                    > expression in yet another subsitute() expression, something to the effect
                    >
                    > substitute(substitute(...),'[^[:cntrl:]]*[/\\]\([^.]*\).vim\c.*','\1','')
                    >
                    > making the whole lot:
                    >
                    > nnoremap <f4> :exec "colorscheme
                    > ".substitute(substitute(expand($VIMRUNTIME."/colors/*.vim"),
                    > '.*[/\\]'.colors_name.'\.vim\c[[:cntrl:]]*[^[:cntrl:]]*[/\\]\([^.]*\).*',
                    > '\1', 'g'), '[^[:cntrl:]]*[/\\]\([^.]*\).vim\c.*','\1','')<cr><cr>
                    >
                    > which seemed to work for me to get rid of that and solve the wrapping
                    > problem. I also found that I could change that invisible trailing
                    > space to a 2nd <cr> and it was just as happy.
                    >
                    > Anybody else having a rough day focusing on doing *real* work? :*)
                    >
                    > -tim
                    >
                    >
                    >
                    >
                    >
                    >
                    >
                  • Tim Chase
                    ... I suppose great is in the eye of the beholder...it looks like a frightful mess to me :) Reminds me a lot of Perl code...not bad when I was writing it,
                    Message 9 of 13 , Jul 5, 2005
                    View Source
                    • 0 Attachment
                      > OK, the latest looks great!

                      I suppose "great" is in the eye of the beholder...it looks like a
                      frightful mess to me :) Reminds me a lot of Perl code...not bad
                      when I was writing it, but I'm not sure I'd like to try and
                      revisit it tomorrow and figure out what it's doing. :)

                      -tim
                    • tlink
                      ... Not exactly what you were asking for but ColorSchemeExplorer could be of some help here. Name Of File: csExplorer.vim Description: Color Scheme
                      Message 10 of 13 , Jul 6, 2005
                      View Source
                      • 0 Attachment
                        Steve Felt wrote:
                        > Could a button be mapped to rotate through installed color schemes? Is
                        > vim aware of the files in ~/.vim, ~/.vim/colors etc?

                        Not exactly what you were asking for but ColorSchemeExplorer could be of
                        some help here.

                        " Name Of File: csExplorer.vim
                        " Description: Color Scheme Explorer Vim Plugin
                        " Maintainer: Jeff Lanzarotta (delux256-vim at yahoo dot com)
                        " Last Changed: Thursday, 09 June 2005
                        " Version: 7.0.1
                        " Usage: Normally, this file should reside in the plugins
                        " directory and be automatically sourced. If not, you must
                        " manually source this file using ':source csExplorer.vim'.
                        "
                        " You may use the default command of
                        "
                        " ":ColorSchemeExplorer" - Opens ColorSchemeExplorer
                        "
                        " For more help see supplied documentation.
                        " History: See supplied documentation.

                        Cheers,
                        Thomas.
                      • Steve Felt
                        ... Wow -- that s one crazy line, but it works great! Anyone else including this in their .vimrc (or _vimrc, .gvimrc etc) make sure tim s color scheme
                        Message 11 of 13 , Jul 6, 2005
                        View Source
                        • 0 Attachment
                          On Tue, 2005-07-05 at 14:25, Tim Chase wrote:
                          > > I just tried this out with Window XP and I get "E185: Cannot find color
                          > > scheme C:/Program Files/vim/vim63/colors/blue.vim". If I go ahead and
                          > > just do a "colorscheme blue then following that the switch will work.
                          > > Any thoughts?
                          >
                          > This may be an artifact of the caveat:
                          >
                          > >> It doesn't wrap, and it doesn't do any initialization,
                          >
                          > I did find that when it hit the last one in the list, I got this
                          > error back when there were no more to try. I think it may
                          > actually be trying to set the colorscheme to a multi-line string.
                          > Haven't played with it that far. However, if you prime it the
                          > first time (which usually ends up being "blue"), you should be
                          > able to walk through all the colors pretty easily.
                          >
                          > To fix it, you may be able to wrap the whole bloody substitute()
                          > expression in yet another subsitute() expression, something to
                          > the effect
                          >
                          > substitute(substitute(...),'[^[:cntrl:]]*[/\\]\([^.]*\).vim\c.*','\1','')
                          >
                          > making the whole lot:
                          >
                          > nnoremap <f4> :exec "colorscheme
                          > ".substitute(substitute(expand($VIMRUNTIME."/colors/*.vim"),
                          > '.*[/\\]'.colors_name.'\.vim\c[[:cntrl:]]*[^[:cntrl:]]*[/\\]\([^.]*\).*',
                          > '\1', 'g'), '[^[:cntrl:]]*[/\\]\([^.]*\).vim\c.*','\1','')<cr><cr>
                          >
                          > which seemed to work for me to get rid of that and solve the
                          > wrapping problem. I also found that I could change that
                          > invisible trailing space to a 2nd <cr> and it was just as happy.
                          >
                          > Anybody else having a rough day focusing on doing *real* work? :*)
                          >
                          > -tim
                          >
                          >

                          Wow -- that's one crazy line, but it works great!

                          Anyone else including this in their .vimrc (or _vimrc, .gvimrc etc) make
                          sure tim's color scheme switch/switcher solution is all on one line.

                          Thanks!!

                          --
                          Steve Felt <steve@...>
                          CirclePix.com
                        • Tim Chase
                          ... Glad it solves what ails ya :) In case you want to tweak or understand it, I ll try and break it down into less cryptic pieces. The root of it is a mapping
                          Message 12 of 13 , Jul 6, 2005
                          View Source
                          • 0 Attachment
                            >>nnoremap <f4> :exec "colorscheme
                            >>".substitute(substitute(expand($VIMRUNTIME."/colors/*.vim"),
                            >>'.*[/\\]'.colors_name.'\.vim\c[[:cntrl:]]*[^[:cntrl:]]*[/\\]\([^.]*\).*',
                            >>'\1', 'g'), '[^[:cntrl:]]*[/\\]\([^.]*\).vim\c.*','\1','')<cr><cr>
                            >
                            > Wow -- that's one crazy line, but it works great!

                            Glad it solves what ails ya :)

                            In case you want to tweak or understand it, I'll try and break it
                            down into less cryptic pieces.

                            The root of it is a mapping which executes "colorscheme <stuff>"

                            The <stuff> is found by getting a list of the files; finding your
                            current colorscheme in that list; then finding the next one in
                            the list to pass back to the previous bit.

                            To get the list of files, the mapping uses the expand() function.
                            This is a simple version that simply hits one directory. Multiple
                            directories might be doable with a little tweaking by appending
                            multiple calls to the expand() function together, and placing
                            some delimiter (char 0x0A seems to be what expand() uses).

                            To get the *next* name, we look for the current name:

                            ...[/\\]'.colors_name.'\.vim\c'

                            which should take into account path separators (either forward or
                            back-slash), followed by the current color-scheme name, followed
                            by ".vim" (case-insensitive "\c").

                            Because the expand() call separates the lines with a control
                            character (0x0A, IIUC) we then slurp up those control characters,
                            and then all non-control-characters up to a forward/back-slash.
                            We then tag the stuff that follows, up to a period. We then slurp
                            up and discard the (case-insensitive) ".vim" and anything that
                            follows. We now have the next color-scheme name tagged, so we
                            replace the whole lot with the tagged stuff.

                            This is good. However, we then encounter the problem raised
                            earlier--that when you're on the last colorscheme, the whole
                            substitute() fails to find the "next" one because it's at the end
                            of the list, so it doesn't change anything. Thus, you get back
                            the original results of the expand() call. This chokes the
                            "colorscheme <stuff>" statement. So we simply strip off the path,
                            the ".vim" and anything that follows, leaving just the first
                            colorscheme in the list.

                            The first <cr> then runs the whole lot, and the second <cr>
                            dismisses the "Press <enter> to continue" message.

                            ...and Bob's your uncle :)

                            -tim
                          Your message has been successfully submitted and would be delivered to recipients shortly.