0

So I have a set of statements such as

    if                       {return IF;}
    int                       {return INT;}
    for                       {return FOR;}

and I want it it to read like

    if                       {return IF;}        IF
    int                       {return INT;}      INT
    for                       {return FOR;}      FOR

This is because I need to copy all of these variables to another section of the code and I could do an easy text block if the page is formatted as such.

I figure the easiest way to do this would be with a find/replace regex. However while it easy to SELECT the things I want by saying [return .*}], I cant seem to figure out how I would be able to move it elsewhere.

Thank you for your help!

Daniel Imberman
  • 618
  • 1
  • 5
  • 18
  • Description is a bit unclear - could you tell us which language is this and what do these spaces mean? Do you want to replace all statements one at a time? – Andrey Chaschev Oct 19 '13 at 20:44

3 Answers3

1

You might want to have a glance at Structural Replace accessed by Ctrl+Shift+M. It's a plugin which is present in the core distribution, but might be disabled in some installations.

A simpler and less capable option are regex replacements in Idea's search&replace back-referencing for which is covered here.

Community
  • 1
  • 1
Andrey Chaschev
  • 16,160
  • 5
  • 51
  • 68
0

What you need is this nifty thing called "match groups". You do this using parentheses in the find expression, then you can refer to those groups in the "replace" using numeric group references. \1 refers to the first group, \2 the second, and so forth. To hell with that, here's an example:

s/\(.*return \)\(.*\)\(;.*\)/\1\2\3       \2/

That worked in vi. Note the \ before each parenthesis in the find expression. It's ugly, but you need that. Otherwise it'll be interpreted as you trying to match a parenthesis. Of course, in vi, you could just put a % in front of the find/replace to apply to all lines at once.

Very important. Editors can sometimes be configured to include end of line characters in what a "." matches. For this to work, you'd have to either have that disabled, or replace the "." with an expression that doesn't match end of line characters. I think [\s\S] will work.

Another slight detail. If you want them nice and lined up line you have there, rather than just typing a bunch of spaces in the replace expression, you could put a couple \t's for fixed-position tabs.

sdanzig
  • 4,510
  • 1
  • 23
  • 27
0

You can press this 'select all occurrences' button.

Lets you copy/cut etc.

enter image description here

wilmol
  • 1,429
  • 16
  • 22