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

Re: Uppercase keywords

Expand Messages
  • A.J.Mechelynck
    ... I think it should be possible to write a function or command to put the cursor on each word in turn, determine if it is a keyword, and depending on the
    Message 1 of 3 , Oct 2, 2006
    • 0 Attachment
      Marius Roets wrote:
      > Hi Vimmers,
      > I have a big a (3000+ lines) source code file. The syntax highlighting
      > works perfectly, so all keywords are highlighted correctly. Is there
      > any way that I can use this fact to convert all keywords to uppercase,
      > or do I have to do them all one by one?
      >
      > Thanks
      > Marius
      >

      I think it should be possible to write a function or command to put the cursor
      on each word in turn, determine if it is a keyword, and depending on the
      result, do either nothing or "normal gUaw" (without the quotes). You may want
      to do this within a visual highlighted area (i.e., from mark `< to mark `> )
      or as a command accepting a range (like the :s command).

      Note that highlight names usually vary from language to language. Three may
      even be several in a single language: e.g. vimAutoCmd links to vimCommand
      which links to Statement

      See
      :help text-objects
      :help gU
      :help synID()
      :help synIDattr()
      :help synIDtrans()
      :help line()
      :help col()
      :help :command
      :help :function


      Best regards,
      Tony.
    • David Fishburn
      ... Right you are Tony, that is exactly how I wrote it. SrchRplcHiGrp.vim - Search and Replace based on a highlight group
      Message 2 of 3 , Oct 2, 2006
      • 0 Attachment
        > -----Original Message-----
        > From: A.J.Mechelynck [mailto:antoine.mechelynck@...]
        > Sent: Monday, October 02, 2006 7:44 AM
        > To: Marius Roets
        > Cc: vim@...
        > Subject: Re: Uppercase keywords
        >
        > Marius Roets wrote:
        > > Hi Vimmers,
        > > I have a big a (3000+ lines) source code file. The syntax
        > highlighting
        > > works perfectly, so all keywords are highlighted correctly.
        > Is there
        > > any way that I can use this fact to convert all keywords to
        > uppercase,
        > > or do I have to do them all one by one?
        > >
        > > Thanks
        > > Marius
        > >
        >
        > I think it should be possible to write a function or command
        > to put the cursor on each word in turn, determine if it is a
        > keyword, and depending on the result, do either nothing or
        > "normal gUaw" (without the quotes). You may want to do this
        > within a visual highlighted area (i.e., from mark `< to mark
        > `> ) or as a command accepting a range (like the :s command).

        Right you are Tony, that is exactly how I wrote it.

        SrchRplcHiGrp.vim - Search and Replace based on a highlight group
        http://www.vim.org/script.php?script_id=848

        Basic usage:
        Place your cursor on the highlighted text.
        :SRChooseHiGrp
        It tells you what it found:
        SRHiGrp - Group ID: 268 Name: vimLet

        Or:
        :SRChooseHiGrp!
        SRHiGrp - Group ID: 49 Name: Statement

        Add the ! if you want the base color.

        Then you can visually select the region you want, the plugin supports all 3
        visual modes (characterwise, linewise and blockwise).

        Then run:
        :'<,'>SRHiGrp

        It asks you for 2 pieces of information:
        1. What to match (via a regex) default is current word - '\(\w\+\>\)'
        2. What to do with the match. The default is to UPPERCASE the match -
        '\U\1'

        You can also use this plugin to just search for highlight groups using the
        SRSeach command.

        :h SRHiGrp

        Enjoy, and please rate it if you find it helpful.
        Feedback is always welcome.

        Dave

        finds - '\(\w\+\>\)'
      Your message has been successfully submitted and would be delivered to recipients shortly.