views:

35

answers:

3

Maybe a strange question, but is there a way to do a copy while paste? eg.

you have a mapper where you want to switch mapping direction:

object1.MyProperty = object2.HisProperty;

to

object2.HisProperty = object1.MyProperty;

I know you can to this with som regex gymnastics in an external editor, but if you do this with regular copy paste it will look like this after the first cut-paste:

object2.HisPropertyobject1.MyProperty = ;

And then you have to select the object1.MyProperty and cut-paste it over to the right side.

What I would like is a function that copy/cuts the text I'm replacing during paste.

Cheers!

A: 

You can use Regex in the find & replace dialog in Visual Studio, too ("select the Use check box under Find Options and choose Regular expressions"):

:b*{[^:b]+}:b*=:b*{[^:b]+};

and replace by

\2 = \1;

(Sorry, I was not able to test this expression, but it will give you an idea, at least)

tanascius
+1  A: 

The quick and dirty way would be to use three search/replace operations and a temporary dummy name:

  1. Replace .MyProperty with .OmgTizIsDaCrazyStuff
  2. Replace .HisProperty with .MyProperty
  3. Replace .OmgTizIsDaCrazyStuff with .HisProperty

This assumes that you want to replace all occurences of access to .MyProperty and .HisProperty

Jørn Schou-Rode
A: 

You can't do that directly with a single keypress 'out of the box'.

There are three commands that transpose characters, words, and lines - but these wouldn't help you in your particualr example. (though you could hit return in the middle of the line, transpose lines, and hit delete to join them back together, it wouldn't be any easier than copy & paste)

However, it's pretty easy with:
Cut part A.
Move to the end of B and paste
Cut B
Move to the beginning and paste.

Or, if you use the clipboard ring:
Cut part A
Cut part B
Paste part B
Paste with ctrl+shift+V twice to paste A

And, if you think you'll ever need to do that operation again, it would take about 1 minute to write a Macro to do what you want, and assign it to a keypress so you could achieve it with a single keypress every time. VS Macros are extremely powerful, and I'd highly recommend you at least learn how to record and play back a temporary macro, as it is a massive timesaver when you want to repeat an action more than 2 or 3 times.

Jason Williams
Yes, I guess the clipboard ring is as close as I can get :)
Mojito71