replace

26 views
Skip to first unread message

Cliff Oliveira

unread,
Aug 31, 2011, 10:04:52 AM8/31/11
to vim...@googlegroups.com
I would like to find and replace at once a word within multiple directories from a project, MacVim offers this possibility?

--
 Cliff Oliveira
www.tribodeideias.com.br

David Patrick Henderson

unread,
Aug 31, 2011, 11:06:23 AM8/31/11
to vim...@googlegroups.com
On 31 Aug 2011, at 07:04, Cliff Oliveira wrote:

I would like to find and replace at once a word within multiple directories from a project, MacVim offers this possibility?

See help for vimgrep, args, and argsdo 


David P Henderson
--
"Beautiful bodies and beautiful personalities rarely go together."
    -- Carl Jung

Kyle Lippincott

unread,
Aug 31, 2011, 2:26:29 PM8/31/11
to vim...@googlegroups.com
Keep in mind also that Mac OS X is UNIX, and you can use :! in vim to shell out, so something like:
:!find project/directory -name '*.cc' | xargs sed -i 's/original/replacement/'

Depending on how many files there are, this may be much faster than args/argdo.

--
You received this message from the "vim_mac" 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

Kyle Lippincott

unread,
Aug 31, 2011, 2:27:18 PM8/31/11
to vim...@googlegroups.com
err...  you might need to escape the | in that, vim has its own uses for it (I can't remember if after :! it's *not* treated specially).  It's probably easier to just open a terminal and do it there.

Cliff Oliveira

unread,
Aug 31, 2011, 4:39:15 PM8/31/11
to vim...@googlegroups.com
I managed to locate the files using:! grep but how to replace the word being searched?

I used

:!grep sistema. ~/workspace/canto/*



2011/8/31 David Patrick Henderson <dp.cha...@gmail.com>

--
You received this message from the "vim_mac" 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



--
 Cliff Oliveira
www.tribodeideias.com.br

Kyle Lippincott

unread,
Aug 31, 2011, 5:59:22 PM8/31/11
to vim...@googlegroups.com
This only does all of the files in one directory, is that what you intended?  If so:
:!sed -i 's/sistema./replacement/' ~/workspace/canto/*
should work.  http://en.wikipedia.org/wiki/Sed is the wikipedia page for sed, and there are many many tutorials out there on how to use it :)

Cliff Oliveira

unread,
Sep 1, 2011, 6:23:56 AM9/1/11
to vim...@googlegroups.com
I tried the tip but sent it returned following error:

:!sed -i 's/sistema./www./' ~/workspace/canto/*
[No write since last change]
sed: 1: "/Users/cliffoliveira/wo ...": command c expects \ followed by text

I tried to put \ at the end but did not work



2011/8/31 Kyle Lippincott <spec...@pewpew.net>



--
 Cliff Oliveira
www.tribodeideias.com.br

Kyle Lippincott

unread,
Sep 1, 2011, 9:45:25 AM9/1/11
to vim...@googlegroups.com
Doh. I forgot that -i takes an argument.  Does sed -i -e 's/sistema./www./' ~cliffoliveira/workspace/canto/* work?

I keep responding from my iPhone, so I can't really check if the command I'm giving has the correct syntax. :(
Reply all
Reply to author
Forward
0 new messages