Monday, August 24, 2009

Re: Use VIM to perform text manipulation on file (like sed/awk)

On Mon, Aug 24, 2009 at 10:30:23AM -0700, Gary Johnson wrote:

Hi WL,

> On 2009-08-24, WL wrote:
...
> > I want to use vim -c to do to tasks.
> > a- comment out a given section (say section that starts with comment
> > #Company IT )
> > b- uncomment a given section (say section that starts with comment
> > #Lab1)

I played around with the old vimscript shell script idea, and had to
modify it quite a bit to make it work again. This might provide an
example testbed or at least some ideas for non-interactive vim within
pipes.

Note that you still need a tty for vim to work.

You can find my take here:

http://github.com/jakobi/script-archive/blob/master/vim/vimscript


Gary, I think:
> I think that vim is the cannon in this case. It's a large program;
> it has to read the entire file into memory rather than reading only
> the part it needs to perform the operation; it doesn't work in a
> pipeline except at the end.

Not quite correct - vim can be made to work successfully in a pipe
both interactively or as above shows non-interactively (at least for
Linux environments; I'd bet on portability problems :/).

But getting it to work again was rather painful, and one of the areas
where vim seems to have changed since the days of the original
vimscript on vim.org.

Oh, and avoid g//p, the *p* printing does some really strange
doublication / triplication with my vimscript example. Other than
that, things seem to work nicely for vimscript with and without
buffer access.

--
cu
Peter l Jakobi
lists@kefk.oa.shuttle.de

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

No comments: