> Can you provide an example, i didn't understand the
 > search/replace thing.

I originally missed that you wanted to run *Linux shell*
commands that were contained in the buffer.  I mis-read that
you wanted to run *Ex commands* contained in the buffer.  My
follow-up post using ":'<,'>!sh" and Gary's suggestion of
":'<,'>w !sh" work for the shell command processing.

Though it's not what you asked for originally, I'll try to
explain a little more what I was talking about:

I frequently get batch-changes of "perform some Vim
operation on any line matching some value" (whether
substitution as above, or some other transformation).  I
take my data file (source.txt) and want to make the changes
specified (in changes.txt).  So I open both files, and in
changes.txt, I execute something like one of these

   :%...@.*@:g/^&/sil! >  " indent lines containing the item
   :%...@.*@:g/^&/d       " delete lines contaning the item
        :%...@\(.*\)\t\(.*\)@:%s/\1/\2/g
                             " change the values from column A
                                                                                
         " to the corresponding values
                                                                                
         " from column B

With the resulting bunch of Ex commands in my changes.txt
window, I yank them, switch over to my data.txt and then
execute my grand list of commands with

   @"

In my case, the changes.txt file usually has a stack of
phone-numbers used to identify lines in data.txt and then
there's some fixed transform I want to perform such as
indenting the row (the 1st one), deleting the items (the 2nd
one), or performing some substitution on those phones.

 >> If they don't have leading colons, then it may be fastest
 >> to just use blockwise visual-mode to add 'em.
 >
 > Can you provide example for blockwise visual mode?

Using control+V (or, if you're one who has mswin.vim
sourced, control+Q) highlight the left-hand margin of your
Ex commands and press "I" (capital-eye) to enter insert
mode.  Type the missing colon, and then press <esc> which
will prefix the colon along the left-hand margin of the
formerly-selected block.  This would transform a bunch of
lines like

   abc
   def
   ghi

into

   :abc
   :def
   :ghi

Those resulting lines can then be executed by my above "yank
it and execute it as a macro" method.  Matt's alternative
use of the ":@" Ex command is probably a better (less
convoluted) way to go here, yanking the un-"colon"ed text
and just using

   :@"

instead.  I've used that method maybe twice in the last 14
years, so it evades my memory when I'm reation for ideas.

All that as a side footnote to your actual question which
was hopefully answered in one of the earlier emails. :)

-tim


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to