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

Applying batch file to a text file.

Expand Messages
  • john Culleton
    I want to apply a batch file foo to a text file bar . ... (I can delete the : if that helps.) So given these facts what does the command line for vim or ex
    Message 1 of 4 , Nov 13 12:10 PM
      I want to apply a batch file "foo" to a text file "bar".
      The commands in foo are of the form:

      :% s/elephant/\\idx{&}/g

      (I can delete the : if that helps.)

      So given these facts what does the command line for vim or ex
      look like? In particular I need to know how to get both foo and
      bar into the command. This is to build an index for TeX.

      Linux of course.

      --
      John Culleton
      Wexford Press
      Free list of books for self-publishers:
      http://wexfordpress.net/shortlist.html
      PDF e-book: "Create Book Covers with Scribus"
      available at http://www.booklocker.com/books/4055.html

      --
      --
      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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Tim Chase
      ... It sounds like you want the :source command, so you can do vim file_to_edit.tex ... Just make sure that it s only run once or that you take extra pains
      Message 2 of 4 , Nov 13 12:50 PM
        On 2013-11-13 15:10, john Culleton wrote:
        > I want to apply a batch file "foo" to a text file "bar".
        > The commands in foo are of the form:
        >
        > :% s/elephant/\\idx{&}/g
        >
        > (I can delete the : if that helps.)
        >
        > So given these facts what does the command line for vim or ex
        > look like? In particular I need to know how to get both foo and
        > bar into the command. This is to build an index for TeX.

        It sounds like you want the ":source" command, so you can do

        vim file_to_edit.tex
        :source batch_script.vim

        Just make sure that it's only run once or that you take extra pains
        to ensure your search term excludes previously-replaced items.
        Otherwise, subsequent runs could end up with the following
        replacements:

        \\idx{elephant}
        \\idx{\\idx{elephant}}
        \\idx{\\idx{elephant}}}

        Also note that, without "\<...\>" guards, order may matter:

        :%s/politics/dogma/g
        :%s/dog/cat/g

        can result in "The president talked about politics and the Whitehouse
        dog" changing into "The president talked catma and the Whitehouse
        cat"

        This can be worked around, most atomically by creating a dictionary
        and then using a regexp that finds all words, then replaces them by
        trying to look them up in the mapping-dictionary:

        :let my_map={}
        :let my_map["old"] = "NEW!"
        :let my_map["dog"] = "cat"
        :" lots more mappings can get created here
        :%s/\w\+/\=has_key(my_map, submatch(0))?my_map[submatch(0)]:submatch(0)/g

        Hope this gives you some ideas to work with.

        -tim




        --
        --
        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

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Tony Mechelynck
        ... In addition to Tim s reply, this sounds like a case for running Vim in batch mode if you want to do it at the command prompt without the need for an
        Message 3 of 4 , Nov 13 1:28 PM
          On 13/11/13 21:10, john Culleton wrote:
          > I want to apply a batch file "foo" to a text file "bar".
          > The commands in foo are of the form:
          >
          > :% s/elephant/\\idx{&}/g
          >
          > (I can delete the : if that helps.)
          >
          > So given these facts what does the command line for vim or ex
          > look like? In particular I need to know how to get both foo and
          > bar into the command. This is to build an index for TeX.
          >
          > Linux of course.
          >
          In addition to Tim's reply, this sounds like a case for running Vim "in
          batch mode" if you want to do it at the command prompt without the need
          for an interactive Vim editor:

          vim -es -S foo bar

          This assumes that your "batch file" ends with a quit command (for
          instance :x), otherwise you can add that at the command-line:

          vim -es -S foo -cx bar

          The : at the start of each line may be omitted, but you don't have to.

          See
          :help -e
          :help -s-ex
          :help -S
          :help -c

          If you have a symlink named "ex" which redirects to Vim, then the -e
          switch can be omitted:

          ex -s -S foo -cx bar


          Best regards,
          Tony.
          --
          Really heard in court in the U.S.A.:
          Q.: Were you present when your photo was taken?
          A.: Are you kidding?

          --
          --
          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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • john Culleton
          On Wed, 13 Nov 2013 14:50:10 -0600 ... If I add c to each command will the system wait for me to say yes or no as in an interactive session? That would be
          Message 4 of 4 , Nov 13 2:14 PM
            On Wed, 13 Nov 2013 14:50:10 -0600
            Tim Chase<vim@...> wrote:

            > On 2013-11-13 15:10, john Culleton wrote:
            > > I want to apply a batch file "foo" to a text file "bar".
            > > The commands in foo are of the form:
            > >
            > > :% s/elephant/\\idx{&}/g
            > >
            > > (I can delete the : if that helps.)
            > >
            > > So given these facts what does the command line for vim or ex
            > > look like? In particular I need to know how to get both foo
            > > and bar into the command. This is to build an index for
            > > TeX.
            >
            > It sounds like you want the ":source" command, so you can do
            >
            > vim file_to_edit.tex
            > :source batch_script.vim
            >
            > Just make sure that it's only run once or that you take extra
            > pains to ensure your search term excludes previously-replaced
            > items. Otherwise, subsequent runs could end up with the
            > following replacements:
            >
            > \\idx{elephant}
            > \\idx{\\idx{elephant}}
            > \\idx{\\idx{elephant}}}
            >
            > Also note that, without "\<...\>" guards, order may matter:
            >
            > :%s/politics/dogma/g
            > :%s/dog/cat/g
            >
            > can result in "The president talked about politics and the
            > Whitehouse dog" changing into "The president talked catma and
            > the Whitehouse cat"
            >
            > This can be worked around, most atomically by creating a
            > dictionary and then using a regexp that finds all words, then
            > replaces them by trying to look them up in the
            > mapping-dictionary:
            >
            > :let my_map={}
            > :let my_map["old"] = "NEW!"
            > :let my_map["dog"] = "cat"
            > :" lots more mappings can get created here
            > :%s/\w\+/\=has_key(my_map,
            > submatch(0))?my_map[submatch(0)]:submatch(0)/g
            >
            > Hope this gives you some ideas to work with.
            >
            > -tim
            >
            >
            >
            >

            If I add "c" to each command will the system wait for me to say
            yes or no as in an interactive session? That would be good for
            avoiding the doubling up as you cite above.

            --
            John Culleton
            Wexford Press
            Free list of books for self-publishers:
            http://wexfordpress.net/shortlist.html
            PDF e-book: "Create Book Covers with Scribus"
            available at http://www.booklocker.com/books/4055.html

            --
            --
            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

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          Your message has been successfully submitted and would be delivered to recipients shortly.