Saturday, March 6, 2010

Re: Search and Replace Across Multiple Files


On Sat, Mar 6, 2010 at 12:53 PM, Davaris <david_moffatt@hotmail.com> wrote:

Hi,
 I'm a new Vim user and want to use it to convert some JavaScript code to C#
code.

The only problem is I can't get the patterns to work. :-/

I was given this to use,

%s/var \(.*\) : \(.*\) = \(.*\);/\2 \1 = \3;/g
%s/var \(.*\) : \(.*\);/\2 \1;/g
%s/function \(.*\)() : \(.*\)/public \2 \1()/g
%s/function \(.*\)/public void \1
%s/boolean/bool

but when I paste in the first line in command mode, it says

E486: Pattern not found: var \(.*\) : \(.*\) = \(.*\);
Would suggest that you try to search for incremental atoms and check if each exists, before attempting to do %s. E.g,
/var
/var \(.*\) :
/var \(.*\) : \(.*\) =
etc..
Other suggestion is to use \s instead of raw space (for at times it could be a tab).

My other question, is it possible in Vim to enter all of these commands at
once, rather than 1 at a time for each file I want to convert?
You can put all the patterns in a function:
function MyRepace()
%s/var \(.*\) : \(.*\) = \(.*\);/\2 \1 = \3;/g
%s/var \(.*\) : \(.*\);/\2 \1;/g
%s/function \(.*\)() : \(.*\)/public \2 \1()/g
%s/function \(.*\)/public void \1
%s/boolean/bool
endfunction

--
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

--
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: