Tuesday, November 6, 2012

Re: change all files

On 11/06/12 08:00, vicky b wrote:
> HI I have list of files in a dir, each file has a key=value pair
> kind of entries so it basically a prop file .I want to change
> all they key=value in all file to key,value is it possible using
> vim , sorry if it is off topi


Depending on the complexity, it could be as simple as

vim *.txt
:argdo %s/=/,/e|w

or slightly less recklessly,

vim *.txt
:set hidden
:argdo %s/=/,/e
(survey the changes)
:xa " if they're good save & quit all, or
:qa! " if they're bad, abandon all changes

The :s command could be made more complex to tighten the
requirements, something like

%s/^\w\+\zs\s*=\s*\ze\</,/e

which ensures that there's a "word" at the beginning of the line,
followed by some optional whitespace (that will removed), the equals
sign (which will get changed to a comma) followed by more optional
whitespace (that will also get removed), followed by the start of a
word. This can be tweaked depending on the particulars of your
use-case.

-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

No comments: