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

Re: Syntax highlighting: "operator keywords"

Expand Messages
  • A.Politz
    ... You can make your own with the @
    Message 1 of 2 , Jan 30, 2008
    • 0 Attachment
      Szabolcs wrote:

      >With syntax highlighting, \< and \> are very useful for isolating
      >keywords. What a simple way of doing the same thing for operators
      >that are made up of a certain set of characters?
      >
      >For example, suppose that operators can be made up of these three
      >chars: ./+
      >
      >I would like to highlight all of the following: . + / ++ /. .. ...
      >But none of the following (or other combinations): .+ +++ ./ +/ ./+
      >etc.
      >
      >What is the simplest solution for this?
      >
      >To complicate matters further: an operator can be surrounded by non-
      >operator chars such as whitespace, digits, letters, (, ), etc.
      >
      >However, when a dot (.) is next to a number, it should always be
      >grouped with that number as a decimal point: e.g. /.2 is grouped as /
      >(.2) and not (/.)2
      >Similarly 2..a is (2.)(.)(a) and not (2)(..)(a)
      >
      >Any suggestions for solving these problems would be most welcome!
      >
      >
      >
      You can make your own '\<,\>' with the @<= ,@<! and @= operators.
      Here are some hints, you can read more at ':h pattern'. '\v' stands
      for verymagic, which spares a lot of backslashes. Most parens are
      just for clarity.

      Match a 'b', but not after/before an 'a'.
      \v(a)@<!(b)([^a]|$)@=

      The same using '@<='.
      \v(^|[^a])@<=(b)([^a]|$)@=

      The same using '@<=' and '&'.
      \v(^|[^a])@<=(b([^a]|$)&.)

      Match 1-3 adjacent 'b's.
      \v(b)@<!(b{1,3})([^b]|$)@=

      Match 1-3 adjacent 'b's, not after/before a digit.
      \v(b|\d)@<!(b{1,3})([^b]&\D|$)@=

      > Similarly 2..a is (2.)(.)(a) and not (2)(..)(a)

      \v(^|\d\.|[^.]&\D)@<=\.{1,3}($|\.\d|[^.]&\D)@=

      This matches 1-3 dots after start of line, a digit and a dot or
      something that is neither a dot nor a digit, and is followed by
      the end of line, a dot and a digit or neither one of them.

      -ap



      --
      Ich hab geträumt, der Krieg wär vorbei.


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.