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

129419Re: Alternating lines' color

Expand Messages
  • Ben Fritz
    Mar 5, 2012
      On Mar 3, 3:33 pm, Tarlika Elisabeth Schmitz
      <v...@...> wrote:
      > On Fri, 2 Mar 2012 11:39:02 -0600
      >
      > Benjamin Fritz <fritzophre...@...> wrote:
      > >Script attached to make odd and even lines have a different background
      > >color. Simply source this script in your .vimrc and define a highlight
      > >for EvenLbg to use.
      >
      > It would drive me nuts if applied to all buffers but dead useful if the
      > alternate line display could be toggled on/off for a particular buffer
      > or just a range.
      >

      That should be doable; if I remember correctly, for speed's sake I
      actually have a range built into the script based on some number of
      lines relative to the current line. This should be adaptable to
      specify a range.

      > Presumably, this could be turned into a plugin and dropped
      > in .vim/plugins.
      >

      It certainly could, and I considered it. But I don't actually use this
      script anymore so I'm not sure if I want to plugin-ify it and put it
      on vim.org, since I won't be able to actively maintain it very well.
      If I remember, the reason I stopped using it was that the lines
      colored by the script made the special characters shown with my 'list'
      and 'listchars' setting look like normal text instead of the
      highlighting normally applied.

      > Daft question re vim syntax:
      >
      > func! s:ColorAltLines()
      >   if exists('b:ALTLINES_disable') || exists('g:ALTLINES_disable')
      >
      > What is the sifnificance of s:, b: and g: ? Could you point me to the
      > relevant manual page?

      Tim gave you a good answer in general, it's a scope specifier.

      In this particular case, the s: for the function makes sure the
      function is only defined for the script (and won't have any naming
      conflicts with other scripts). The g:ALTLINES_disable lets you
      (temporarily or permanently) disable the line coloring for all
      buffers. The b:ALTLINES_disable lets you disable it on a per-buffer
      basis.

      I actually forgot I had this in there. So actually, your initial
      question of toggling it on/off for a particular buffer could be as
      simple as a BufRead,BufNewFile autocmd which does a :let
      b:ALTLINES_disable=1, and a mapping to unlet b:ALTLINES_disable and
      either call the function which does the highlighting, or runs an
      appropriate doautocmd command.

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Show all 12 messages in this topic