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

139903Re: Applying batch file to a text file.

Expand Messages
  • Tim Chase
    Nov 13, 2013
    • 0 Attachment
      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.
    • Show all 4 messages in this topic