Go Back
1 Vote

Selectively reformatting code in VS


Reformatting code with CONTROL+KD in Visual Studio is a great tool, and very helpful in finding extra or missing END statements. 

But the problem comes when you are making changes to large existing sources which have never had CONTROL+KD performed on them.  This can result in source code thinking you have changed every line in the source, and makes it impossible to review Pull requests.

It's fine if you are just changing a few lines and you can manually tab code to align with the existing code.

But say you are adding 100+ lines of new code as a block - say a new internal subroutine.

It would be great if you could highlight that block only and use CONTROL+KD on it, without affecting the rest of the source.

 

7 Comments | Posted by Gordon Ireland to Visual Studio Integration on 9/11/2025, 8:58 AM
Steve Ives
Try makeing a selection then using Ctrl+K+F
 

9/11/2025, 4:32 PM   0  
Gordon Ireland
I expected I should be able to select and Control KD would only work on the selection, but it works on the whole source.

What you are describing is the fuinctionlity I am looking for

I am on  the latest synergy, SDI and VS 2022, windows 11

9/11/2025, 5:08 PM   0  
Steve Ives
So it didn't work? I am also on the latest Synergy, SDI and VS 2022, Windows 11, and it works great for me.

9/11/2025, 5:10 PM   0  
Gordon Ireland
No - should I follow up with support?

9/11/2025, 5:21 PM   0  
Steve Ives
I guess so. I tested it in both traditional and .NET and it worked great.

9/11/2025, 5:51 PM   0  
Kish Baley

Gordon,

<CTRL>KF works for me too, while I'm not on the absolute latest versions, I'm close.

We have a similar situation, where we have a lot of legacy code that's not always well formatted. What we normally do is pull the source into VS, <CTRL>KD it first *before* making any changes to the code, then Push it noting in the commit that this was just a reformat. After that, you can make your changes. For our customer anyways, reformatting the whole source makes sense since the format could be *way off* as different developers touch different sections of source. Note that we also change <TAB> to spaces as part of the initial reformat, since other devs do not use VS and we want the formatting to look the same for their editor of choice.

If you forget to reformat and Push first, which we sometimes do, they I compare the changes ignoring whitespace so you only see the code changes and not the whitespace changes.


9/15/2025, 3:40 PM   0  
Gordon Ireland
Sorry guys

I didn't know about control KF.  That works fine for me

I thought control KD (not KF) would work on a selection,

I didn't realise they were 2 different shortcuts.

Control KF does exactly what I need it do, and only reformats my new internal subroutines, and not the code written using vi or edt over 40 years ago


 

9/19/2025, 3:52 PM   0  
Please log in to comment on this idea.