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

Re: Highlight non ASCII char

Expand Messages
  • Gary Johnson
    ... I don t understand just what s not working, or how it is not working, so it s hard to know what to suggest. I think your problem may be that vim already
    Message 1 of 16 , Feb 1, 2004
    • 0 Attachment
      On 2004-02-01, Hiroshi Iwatani <HGA03630@...> wrote:
      > Thanks but ...
      >
      > Tony's ?solution? doesn't work.
      > And Steve's function is not what I need.
      >
      > Then MY ?solution? also doesn't work:
      >
      > highlight EvilChars guibg=Magenta
      > match EvilChars /[00-1f80-ff]/ <-- input via Ctrl-V, confirmed on Hex mode
      >
      > Please help till I be helped!

      I don't understand just what's not working, or how it is not
      working, so it's hard to know what to suggest. I think your problem
      may be that vim already colors such characters specially and that
      vim's built-in rules seem to override the match rules. Try this and
      see if it gives you the results you want.

      hi SpecialKey NONE
      hi link SpecialKey EvilChars

      HTH,
      Gary

      --
      Gary Johnson | Agilent Technologies
      garyjohn@... | Wireless Division
      | Spokane, Washington, USA
    • Hiroshi Iwatani
      Wow! Major progress! ... By these two lines, 0x00 is displayed as ^@, 0x01 as ^A, 0x97 as ~W etc. But with no color! I want glaring colors! Besides, with no
      Message 2 of 16 , Feb 1, 2004
      • 0 Attachment
        Wow! Major progress!

        > hi SpecialKey NONE
        > hi link SpecialKey EvilChars

        By these two lines, 0x00 is displayed as ^@, 0x01 as ^A, 0x97 as
        ~W etc. But with no color! I want glaring colors! Besides, with no
        colors, 0x00 and real ^@ aren't discernable.

        Then God gave me a whim:

        hi SpecialKey guibg=Magenta

        Now background color of ^@, ^A etc is magenta!
        Sudden solution has come.

        I don't understand underlying logic though ;-)

        Thanks a lot, anyway.

        Gary Johnson wrote:
        > On 2004-02-01, Hiroshi Iwatani <HGA03630@...> wrote:
        >
        >>Thanks but ...
        >>
        >>Tony's ?solution? doesn't work.
        >>And Steve's function is not what I need.
        >>
        >>Then MY ?solution? also doesn't work:
        >>
        >>highlight EvilChars guibg=Magenta
        >>match EvilChars /[00-1f80-ff]/ <-- input via Ctrl-V, confirmed on Hex mode
        >>
        >>Please help till I be helped!
        >
        >
        > I don't understand just what's not working, or how it is not
        > working, so it's hard to know what to suggest. I think your problem
        > may be that vim already colors such characters specially and that
        > vim's built-in rules seem to override the match rules. Try this and
        > see if it gives you the results you want.
        >
        > hi SpecialKey NONE
        > hi link SpecialKey EvilChars
        >
        > HTH,
        > Gary
        >

        --
        Hiroshi Iwatani

        *stop cruelty* Annual number of institutionally euthanized cats and dogs
        including kittens and puppies: US 5 million, JP 500 thousand. How about your
        country? *for our better karma*
        ---------------------
      • Hiroshi Iwatani
        ... And panic has come. All the trailing spaces, spaces in blank lines, and TAB are glaringly magenta. I don t need those plenty of
        Message 3 of 16 , Feb 1, 2004
        • 0 Attachment
          <self-quote>
          > hi SpecialKey guibg=Magenta
          >
          > Now background color of ^@, ^A etc is magenta!
          > Sudden solution has come.
          </self-quote>

          And panic has come.
          All the trailing spaces, spaces in blank lines, and TAB
          are glaringly magenta.

          I don't need those plenty of magenta!
          How could I highlight 0x00-0x1f0x80-0xff only?

          --
          Hiroshi Iwatani

          *stop cruelty* Annual number of institutionally euthanized cats and dogs
          including kittens and puppies: US 5 million, JP 500 thousand. How about your
          country? *for our better karma*
          ---------------------
        • Yakov Lerner
          ... Indeed range [^Vx00-^Vx1f] didnt work for me. But this does work for me: highlight EvilChars guibg=Magenta match EvilChars /[^Vx00^Vx01-^Vx1f^Vx80-^Vxff]/
          Message 4 of 16 , Feb 1, 2004
          • 0 Attachment
            Hiroshi Iwatani wrote:
            > Thanks but ...
            >
            > Tony's ?solution? doesn't work.
            > And Steve's function is not what I need.
            >
            > Then MY ?solution? also doesn't work:
            >
            > highlight EvilChars guibg=Magenta
            > match EvilChars /[00-1f80-ff]/ <-- input via Ctrl-V,

            Indeed range [^Vx00-^Vx1f] didnt work for me.
            But this does work for me:

            highlight EvilChars guibg=Magenta
            match EvilChars /[^Vx00^Vx01-^Vx1f^Vx80-^Vxff]/

            I suspect is has to do with special treatment of ^@ (null char) in vim

            --
            Jacob Lerner
          • Yakov Lerner
            ... Some more about the [^Vx00-^Vx1f] range. Is doesn t work as expected. It actually works only as as [^Vx0b-^Vx1f] (probably because ^@ is internally
            Message 5 of 16 , Feb 1, 2004
            • 0 Attachment
              Yakov Lerner wrote:
              > Hiroshi Iwatani wrote:
              > > Then MY ?solution? also doesn't work:
              > > highlight EvilChars guibg=Magenta
              > > match EvilChars /[00-1f80-ff]/ <-- input via Ctrl-V,
              >
              > Indeed range [^Vx00-^Vx1f] didnt work for me.
              > But this does work for me:
              >
              > highlight EvilChars guibg=Magenta
              > match EvilChars /[^Vx00^Vx01-^Vx1f^Vx80-^Vxff]/
              > I suspect is has to do with special treatment of ^@ (null char) in vim


              Some more about the [^Vx00-^Vx1f] range. Is doesn't work as expected.
              It actually works only as as [^Vx0b-^Vx1f] (probably because
              ^@ is internally replaced by \n). The range [^Vx00^Vx01-^Vx1f]
              does work though.


              --
              Jacob Lerner
            • Antoine J. Mechelynck
              ... Apparently I gave a wrong highlight group. Try going back to a slightly modified version of what I gave set isprint=32-126 highlight SpecialChar
              Message 6 of 16 , Feb 1, 2004
              • 0 Attachment
                Hiroshi Iwatani <HGA03630@...> wrote:
                > <self-quote>
                > > hi SpecialKey guibg=Magenta
                > >
                > > Now background color of ^@, ^A etc is magenta!
                > > Sudden solution has come.
                > </self-quote>
                >
                > And panic has come.
                > All the trailing spaces, spaces in blank lines, and TAB
                > are glaringly magenta.
                >
                > I don't need those plenty of magenta!
                > How could I highlight 0x00-0x1f0x80-0xff only?
                >
                > --
                > Hiroshi Iwatani
                >
                > *stop cruelty* Annual number of institutionally euthanized cats and
                > dogs including kittens and puppies: US 5 million, JP 500 thousand.
                > How about your country? *for our better karma*
                > ---------------------

                Apparently I gave a wrong highlight group. Try going back to a slightly
                modified version of what I gave

                set isprint=32-126
                highlight SpecialChar guibg=Magenta

                AND READ THE F... MANUAL

                :halp 'highlight'
                :help :highlight

                and also what comes after those, and what they resend to.

                Good reading,
                Tony.
              • Hiroshi Iwatani
                ... Doesn t work. ... Doesn t work. Really does it work as a new group separate from SpecialKey on Yakov s machine? OK, I think I have finally stumbled accross
                Message 7 of 16 , Feb 1, 2004
                • 0 Attachment
                  Antoine J. Mechelynck wrote:
                  > set isprint=32-126
                  > highlight SpecialChar guibg=Magenta
                  Doesn't work.

                  Yakov Lerner wrote:
                  > But this does work for me:
                  >
                  > highlight EvilChars guibg=Magenta
                  > match EvilChars /[^Vx00^Vx01-^Vx1f^Vx80-^Vxff]/
                  Doesn't work. Really does it work as a new group separate from
                  SpecialKey on Yakov's machine?

                  OK, I think I have finally stumbled accross the real problem:

                  (0)The range 0x00-0x1f and 0x80-0xff are members of predefined SpecialKey
                  group.

                  (1)User can't redefine the SpecialKey group's member:
                  [can't do this]
                  hi SpecialKey guibg=Magenta
                  match SpecialKey /[0x00-0x1f0x80-0xff]/ <-- Ctrl-V input

                  (2)User can't create a new separate group whose member is SpecialKey
                  subset:
                  [can't do this]
                  hi EvilChars guibg=Maganta
                  match EvilChars /[0x00-0x1f0x80-0xff]/ <-- Ctrl-V input

                  * When you had a moment where above seemed work, it was really
                  the SpecialKey that's working.

                  The above new group is ineffective because, it seems, SpecialKey
                  overrides it.

                  So, my question 1 is:
                  How could I do the following or its equivalence via some workaround?:

                  highlight SpecialKey guifg=white guibg=NONE
                  highlight EvilChars guibg=Maganta
                  match EvilChars /[0x00-0x1f0x80-0xff]/

                  And question 2 is:
                  When we should give in to the above (0)-(2) situation without any
                  workaround, how could we achieve the following or its equivalence?:

                  nmap <F9> :% s/\s\+$//g<CR> <-- This is OK
                  imap <F9> <C-O>:% s/\s\+$//g<CR> <-- This is OK
                  nmap <S-F9> :% s/[0x00-0x1f0x80-0xff]/ /g<CR> <-- This doesn't work
                  imap <S-F9> <C-O>:% s/[0x00-0x1f0x80-0xff]/ /g<CR> <-- This doesn't work

                  In other word, trailing spaces, spaces in blank lines, and TABs shoud be
                  simply white while those harmfull byte values should have the most garish
                  color!

                  Thanks in advance again!!!

                  --
                  Hiroshi Iwatani

                  *stop cruelty* Annual number of institutionally euthanized cats and dogs
                  including kittens and puppies: US 5 million, JP 500 thousand. How about your
                  country? *for our better karma*
                  ---------------------
                • Antoine J. Mechelynck
                  ... Let s try another variant ... see ... and don t forget to scroll ... 32-126 are always printable regardless of isprint non-printable characters
                  Message 8 of 16 , Feb 2, 2004
                  • 0 Attachment
                    Hiroshi Iwatani <HGA03630@...> wrote:
                    > Antoine J. Mechelynck wrote:
                    > > set isprint=32-126
                    > > highlight SpecialChar guibg=Magenta
                    > Doesn't work.

                    Let's try another variant

                    :set isprint=
                    :highlight SpecialChar ctermbg=Magenta guibg=Magenta
                    :highlight NonText ctermbg=Magenta guibg=Magenta

                    If it still doesn't work, try in addition:
                    :set display+=uhex

                    see
                    :help 'highlight'
                    " and don't forget to scroll
                    :help 'isprint'
                    " 32-126 are always "printable" regardless of 'isprint'
                    " non-printable characters are highlighten in NonText

                    Please be more specific: if it "doesn't work", what does it show? (Also for
                    other proposals). And did you read the help and try to invent other things
                    for yourself?

                    -- What 'encoding' are you using? From :help 'isprint' (paraphrased):
                    Multibyte characters 256 and above are always regarded as "printable",
                    except for intrinsically "unprintable" or "zero-width" Unicode characters.

                    HTH,
                    Tony.
                  • Gary Johnson
                    ... I think I found the problem. I did a :helpgrep unprintable c and found this at line 1370 of $VIMRUNTIME/doc/todo.txt: 7 SpecialKey highlighting
                    Message 9 of 16 , Feb 2, 2004
                    • 0 Attachment
                      On 2004-02-02, "Antoine J. Mechelynck" <antoine.mechelynck@...> wrote:
                      > Hiroshi Iwatani <HGA03630@...> wrote:
                      > > Antoine J. Mechelynck wrote:
                      > > > set isprint=32-126
                      > > > highlight SpecialChar guibg=Magenta
                      > > Doesn't work.
                      >
                      > Let's try another variant
                      >
                      > :set isprint=
                      > :highlight SpecialChar ctermbg=Magenta guibg=Magenta
                      > :highlight NonText ctermbg=Magenta guibg=Magenta
                      >
                      > If it still doesn't work, try in addition:
                      > :set display+=uhex
                      >
                      > see
                      > :help 'highlight'
                      > " and don't forget to scroll
                      > :help 'isprint'
                      > " 32-126 are always "printable" regardless of 'isprint'
                      > " non-printable characters are highlighten in NonText
                      >
                      > Please be more specific: if it "doesn't work", what does it show? (Also for
                      > other proposals). And did you read the help and try to invent other things
                      > for yourself?
                      >
                      > -- What 'encoding' are you using? From :help 'isprint' (paraphrased):
                      > Multibyte characters 256 and above are always regarded as "printable",
                      > except for intrinsically "unprintable" or "zero-width" Unicode characters.

                      I think I found the problem. I did a ":helpgrep unprintable\c" and
                      found this at line 1370 of $VIMRUNTIME/doc/todo.txt:

                      7 SpecialKey highlighting overrules syntax highlighting. Can't give an
                      unprintable char another color. Would be useful for ^M at end of line.

                      and this at line 327 of $VIMRUNTIME/doc/version6.txt:

                      Use "SpecialKey" highlighting for unprintable characters instead of "NonText".
                      The idea is that unprintable text or any text that's displayed differently
                      from the characters in the file is using "SpecialKey", and "NonText" is used
                      for text that doesn't really exist in the file.

                      I think some of the help files have not been updated to reflect the
                      latter change. So I think the answer for now is that there is no
                      way to get the highlighting the OP wants.

                      Gary

                      --
                      Gary Johnson | Agilent Technologies
                      garyjohn@... | Wireless Division
                      | Spokane, Washington, USA
                    • Hiroshi Iwatani
                      Gary, Thanks a lot fot the *definitive* information about the SpecialKey group. It s a *definitively* sad news for us though. ;-) ... -- Hiroshi Iwatani *stop
                      Message 10 of 16 , Feb 2, 2004
                      • 0 Attachment
                        Gary,
                        Thanks a lot fot the *definitive* information about the SpecialKey
                        group. It's a *definitively* sad news for us though. ;-)

                        Gary Johnson wrote:
                        > On 2004-02-02, "Antoine J. Mechelynck" <antoine.mechelynck@...> wrote:
                        >
                        >>Hiroshi Iwatani <HGA03630@...> wrote:
                        >>
                        >>>Antoine J. Mechelynck wrote:
                        >>>
                        >>>> set isprint=32-126
                        >>>> highlight SpecialChar guibg=Magenta
                        >>>
                        >>>Doesn't work.
                        >>
                        >>Let's try another variant
                        >>
                        >> :set isprint=
                        >> :highlight SpecialChar ctermbg=Magenta guibg=Magenta
                        >> :highlight NonText ctermbg=Magenta guibg=Magenta
                        >>
                        >>If it still doesn't work, try in addition:
                        >> :set display+=uhex
                        >>
                        >>see
                        >> :help 'highlight'
                        >> " and don't forget to scroll
                        >> :help 'isprint'
                        >> " 32-126 are always "printable" regardless of 'isprint'
                        >> " non-printable characters are highlighten in NonText
                        >>
                        >>Please be more specific: if it "doesn't work", what does it show? (Also for
                        >>other proposals). And did you read the help and try to invent other things
                        >>for yourself?
                        >>
                        >>-- What 'encoding' are you using? From :help 'isprint' (paraphrased):
                        >>Multibyte characters 256 and above are always regarded as "printable",
                        >>except for intrinsically "unprintable" or "zero-width" Unicode characters.
                        >
                        >
                        > I think I found the problem. I did a ":helpgrep unprintable\c" and
                        > found this at line 1370 of $VIMRUNTIME/doc/todo.txt:
                        >
                        > 7 SpecialKey highlighting overrules syntax highlighting. Can't give an
                        > unprintable char another color. Would be useful for ^M at end of line.
                        >
                        > and this at line 327 of $VIMRUNTIME/doc/version6.txt:
                        >
                        > Use "SpecialKey" highlighting for unprintable characters instead of "NonText".
                        > The idea is that unprintable text or any text that's displayed differently
                        > from the characters in the file is using "SpecialKey", and "NonText" is used
                        > for text that doesn't really exist in the file.
                        >
                        > I think some of the help files have not been updated to reflect the
                        > latter change. So I think the answer for now is that there is no
                        > way to get the highlighting the OP wants.
                        >
                        > Gary
                        >

                        --
                        Hiroshi Iwatani

                        *stop cruelty* Annual number of institutionally euthanized cats and dogs
                        including kittens and puppies: US 5 million, JP 500 thousand. How about your
                        country? *for our better karma*
                        ---------------------
                      • Antoine J. Mechelynck
                        ... So it _is_ SpecialKey after all! But what about setting isprint to the empty string? That would make all characters [under 256] other than 32-126
                        Message 11 of 16 , Feb 2, 2004
                        • 0 Attachment
                          Gary Johnson <garyjohn@...> wrote:
                          > On 2004-02-02, "Antoine J. Mechelynck"
                          > <antoine.mechelynck@...> wrote:
                          > > Hiroshi Iwatani <HGA03630@...> wrote:
                          > > > Antoine J. Mechelynck wrote:
                          > > > > set isprint=32-126
                          > > > > highlight SpecialChar guibg=Magenta
                          > > > Doesn't work.
                          > >
                          > > Let's try another variant
                          > >
                          > > :set isprint=
                          > > :highlight SpecialChar ctermbg=Magenta guibg=Magenta
                          > > :highlight NonText ctermbg=Magenta guibg=Magenta
                          > >
                          > > If it still doesn't work, try in addition:
                          > > :set display+=uhex
                          > >
                          > > see
                          > > :help 'highlight'
                          > > " and don't forget to scroll
                          > > :help 'isprint'
                          > > " 32-126 are always "printable" regardless of 'isprint'
                          > > " non-printable characters are highlighten in NonText
                          > >
                          > > Please be more specific: if it "doesn't work", what does it show?
                          > > (Also for other proposals). And did you read the help and try to
                          > > invent other things
                          > > for yourself?
                          > >
                          > > -- What 'encoding' are you using? From :help 'isprint'
                          > > (paraphrased):
                          > > Multibyte characters 256 and above are always regarded as
                          > > "printable",
                          > > except for intrinsically "unprintable" or "zero-width" Unicode
                          > > characters.
                          >
                          > I think I found the problem. I did a ":helpgrep unprintable\c" and
                          > found this at line 1370 of $VIMRUNTIME/doc/todo.txt:
                          >
                          > 7 SpecialKey highlighting overrules syntax highlighting. Can't
                          > give an unprintable char another color. Would be useful for
                          > ^M at end of line.
                          >
                          > and this at line 327 of $VIMRUNTIME/doc/version6.txt:
                          >
                          > Use "SpecialKey" highlighting for unprintable characters instead
                          > of "NonText". The idea is that unprintable text or any text
                          > that's displayed differently from the characters in the file is
                          > using "SpecialKey", and "NonText" is used for text that doesn't
                          > really exist in the file.
                          >
                          > I think some of the help files have not been updated to reflect the
                          > latter change. So I think the answer for now is that there is no
                          > way to get the highlighting the OP wants.
                          >
                          > Gary
                          >
                          > --
                          > Gary Johnson | Agilent Technologies
                          > garyjohn@... | Wireless Division
                          > | Spokane, Washington, USA

                          So it _is_ SpecialKey after all! But what about setting 'isprint' to the
                          empty string? That would make all characters [under 256] other than 32-126
                          "unprintable", wouldn't it? Then they would fall under the SpecialKey
                          highlight wouldn't they? (and be represented as ^C for 0x03, ~D for 0x84, /F
                          for 0xD6 etc., unless 'display' uncludes "uhex" in which case they would be
                          <xx> where xx = hex value) Then why couldn't we set the latter's background
                          to magenta [or its background and foreground to any garish colors we would
                          want, for that matter] with a ":highlight" command?

                          see
                          :help 'isprint'

                          Regards,
                          Tony.
                        • Gary Johnson
                          ... Yes, that does seem to work, at least for me. (I finally created a file containing characters 0x00 through 0xff and played with isprint for a while.)
                          Message 12 of 16 , Feb 2, 2004
                          • 0 Attachment
                            On 2004-02-03, "Antoine J. Mechelynck" <antoine.mechelynck@...> wrote:
                            > Gary Johnson <garyjohn@...> wrote:
                            > > On 2004-02-02, "Antoine J. Mechelynck"
                            > > <antoine.mechelynck@...> wrote:
                            > > > Hiroshi Iwatani <HGA03630@...> wrote:
                            > > > > Antoine J. Mechelynck wrote:
                            > > > > > set isprint=32-126
                            > > > > > highlight SpecialChar guibg=Magenta
                            > > > > Doesn't work.
                            > > >
                            > > > Let's try another variant
                            > > >
                            > > > :set isprint=
                            > > > :highlight SpecialChar ctermbg=Magenta guibg=Magenta
                            > > > :highlight NonText ctermbg=Magenta guibg=Magenta
                            > > >
                            > > > If it still doesn't work, try in addition:
                            > > > :set display+=uhex
                            > > >
                            > > > see
                            > > > :help 'highlight'
                            > > > " and don't forget to scroll
                            > > > :help 'isprint'
                            > > > " 32-126 are always "printable" regardless of 'isprint'
                            > > > " non-printable characters are highlighten in NonText
                            > > >
                            > > > Please be more specific: if it "doesn't work", what does it show?
                            > > > (Also for other proposals). And did you read the help and try to
                            > > > invent other things
                            > > > for yourself?
                            > > >
                            > > > -- What 'encoding' are you using? From :help 'isprint'
                            > > > (paraphrased):
                            > > > Multibyte characters 256 and above are always regarded as
                            > > > "printable",
                            > > > except for intrinsically "unprintable" or "zero-width" Unicode
                            > > > characters.
                            > >
                            > > I think I found the problem. I did a ":helpgrep unprintable\c" and
                            > > found this at line 1370 of $VIMRUNTIME/doc/todo.txt:
                            > >
                            > > 7 SpecialKey highlighting overrules syntax highlighting. Can't
                            > > give an unprintable char another color. Would be useful for
                            > > ^M at end of line.
                            > >
                            > > and this at line 327 of $VIMRUNTIME/doc/version6.txt:
                            > >
                            > > Use "SpecialKey" highlighting for unprintable characters instead
                            > > of "NonText". The idea is that unprintable text or any text
                            > > that's displayed differently from the characters in the file is
                            > > using "SpecialKey", and "NonText" is used for text that doesn't
                            > > really exist in the file.
                            > >
                            > > I think some of the help files have not been updated to reflect the
                            > > latter change. So I think the answer for now is that there is no
                            > > way to get the highlighting the OP wants.
                            > >
                            > > Gary
                            > >
                            > > --
                            > > Gary Johnson | Agilent Technologies
                            > > garyjohn@... | Wireless Division
                            > > | Spokane, Washington, USA
                            >
                            > So it _is_ SpecialKey after all! But what about setting 'isprint' to the
                            > empty string? That would make all characters [under 256] other than 32-126
                            > "unprintable", wouldn't it? Then they would fall under the SpecialKey
                            > highlight wouldn't they? (and be represented as ^C for 0x03, ~D for 0x84, /F
                            > for 0xD6 etc., unless 'display' uncludes "uhex" in which case they would be
                            > <xx> where xx = hex value) Then why couldn't we set the latter's background
                            > to magenta [or its background and foreground to any garish colors we would
                            > want, for that matter] with a ":highlight" command?
                            >
                            > see
                            > :help 'isprint'

                            Yes, that does seem to work, at least for me. (I finally created a
                            file containing characters 0x00 through 0xff and played with
                            'isprint' for a while.)

                            Gary

                            --
                            Gary Johnson | Agilent Technologies
                            garyjohn@... | Wireless Division
                            | Spokane, Washington, USA
                          Your message has been successfully submitted and would be delivered to recipients shortly.