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

RE: multiples search and replace in the same command?

Expand Messages
  • Gene Kwiecinski
    ... Honestly, the way I d do it is to just throw it at sed (simple but constant multiple substitutions), or write a little lex script (more onvolved, with
    Message 1 of 4 , Nov 30, 2006
    • 0 Attachment
      >Hi, i'm trying to replace all occurrences of characaters like é, è, ê
      >etc ... by their corresponding htmlentities. To do that, i use the
      >following command:
      >%s/é/\é/g

      >The problem with that command is that i have to do that for all
      >characters. I was wandering if there's a way to do it with only one
      >command.

      Honestly, the way I'd do it is to just throw it at 'sed' (simple but constant multiple substitutions), or write a little 'lex' script (more onvolved, with reformatting, rearranging, whatever else needs to be done to the doc), depending on how involved it is and how often I'd need to use it. I've got DOS versions of both, which is what (still) I tend to use on Lose systems.

      As for 'vim', it's probably best to write a function which you could map to a single key like one of the F-keys. I'm still new at that, so couldn't tell you how to do that, but certainly someone here can tell you how to build the skeleton of the function; you'd add salt and pepper to taste.

      Then you'd just open up a doc, hit <F9> or something, and it's magically done in one pass.

      Don't have it here, but did write a few cheapo 'lex' scripts to turn 0xA0 to " ", convert and match ldquo/rdquo/lsquo/rsquo chars, ellipses, most of the common things I encounter. Gimme a yell today and I tomorrow can dig up and post the script here (if anyone else is interested) or via email directly.
    • Tim Chase
      ... I don t know of any inbuilt character-to-HTML-entity function in vim. However, if you ve got a file that looks like é,é where each line consists of
      Message 2 of 4 , Nov 30, 2006
      • 0 Attachment
        > Hi, i'm trying to replace all occurrences of characaters like é, è, ê
        > etc ... by their corresponding htmlentities. To do that, i use the
        > following command:
        > %s/é/\é/g
        >
        > The problem with that command is that i have to do that for all
        > characters. I was wandering if there's a way to do it with only one
        > command.

        I don't know of any inbuilt "character-to-HTML-entity" function
        in vim. However, if you've got a file that looks like

        é,é

        where each line consists of the character in question, a comma,
        and the HTML representation, you can do something like

        :%s/\(.*\),\(.*\)/:%s!\1!\\\2!ge

        on this auxiliary file. This yields N lines worth of these :s//
        statements that you would want to execute. You can then

        :%y

        to yank all those lines, switch to the buffer on which you want
        to make these changes, and then execute (in normal mode, not
        command mode)

        @"

        which will execute the contents of the scratch register as if it
        was a macro.

        You can modify the above ":%s/.../...!ge" statement to accomodate
        whatever format your big list is in. You can use ^I if it's
        tab-delimited, or whatever. The basic gist is that you want your
        resulting file to look like

        :%s!é!\é!ge

        on each line. Once you have a file that looks like this, it's
        simply a matter of running it on your target document.

        If you just wanted to replace a handful of "funky" (grave & acute
        accented, tilded, umlauted, etc) characters to their
        un-funk-ified versions, one might be able to exploit
        "similar-character" classes, such as

        :%s/[[=a=]]/a/g

        and just execute that for each of your letters (depending on your
        language, this would be 5 vowels, plus a small smattering of
        consonants if needed).

        -tim
      • Sean Plank
        ... From: A.J.Mechelynck To: Gene Kwiecinski Cc: Tanoor Dieng ; vim@vim.org Sent:
        Message 3 of 4 , Nov 30, 2006
        • 0 Attachment
          ----- Original Message ----
          From: A.J.Mechelynck <antoine.mechelynck@...>
          To: Gene Kwiecinski <gkwiecinski@...>
          Cc: Tanoor Dieng <newstanoor@...>; vim@...
          Sent: Thursday, November 30, 2006 12:48:06 PM
          Subject: Re: multiples search and replace in the same command?


          Gene Kwiecinski wrote:
          >> Hi, i'm trying to replace all occurrences of characaters like é, è, ê
          >> etc ... by their corresponding htmlentities. To do that, i use the
          >> following command:
          >> %s/é/\é/g


          I know you can use \| as a OR operator not sure how you would logically determine the correct htmlentities, though

          /é\|è

          >> The problem with that command is that i have to do that for all
          >> characters. I was wandering if there's a way to do it with only one
          >> command.
          >

          Sean Plank



          ____________________________________________________________________________________
          Do you Yahoo!?
          Everyone is raving about the all-new Yahoo! Mail beta.
          http://new.mail.yahoo.com
        • Vigil
          This could be construed as one command: %s/e/EEE/g | %s/a/AAA/g ... -- .
          Message 4 of 4 , Dec 1, 2006
          • 0 Attachment
            This could be construed as one command:

            %s/e/EEE/g | %s/a/AAA/g

            On Thu, 30 Nov 2006, Tanoor Dieng wrote:

            > Hi, i'm trying to replace all occurrences of characaters like é, è, ê
            > etc ... by their corresponding htmlentities. To do that, i use the
            > following command:
            > %s/é/\é/g
            >
            > The problem with that command is that i have to do that for all
            > characters. I was wandering if there's a way to do it with only one
            > command.
            >
            >
            > Best regards.
            >

            --

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