Wednesday, August 26, 2009

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

On Tue, Aug 25, 2009 at 7:33 PM, Ben Fritz wrote:
> It is possible to save the operations that you would do by hand to a
> file, and just run them exactly as if typed. No knowledge of vimscript
> required.
>
> You could make it even easier if you first run Vim interactively with -
> w to record everything as you type it. See :help -w. The only problem
> is you'll need to get it exactly right while you're recording or
> you'll need to record again or edit the recorded file.

Sounds like the most straightforward way to me, and I prefer to KISS.
I made two such scripts that negate each other - each turns on
different DNS settings by commenting and de-commenting different
sections in resolv.conf.
Both are basically same:
- vi -w on /etc/resolv/conf
- %s/^nameserver/#&/
- /<header of desired DNS settings section
- j
- v}
- s/^#//

only the section header is different. However while one of them gets
the job done the other fails miserably. Since the script is in binary
and running to fast to follow I can't really troubleshoot why.

I think its time to call perl to the rescue :)
Thanks for the answers.
Yosi

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

No comments: