On Wed, 13 Nov 2013 14:50:10 -0600
Tim Chase<vim@tim.thechases.com> 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@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Wednesday, November 13, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment