Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio CTRL+SHIFT+T transpose - what does it do?

I wrote some code and tried the Ctrl + T to check transpose feature in visual studio.

Just to check if CTRL + Shift + T does the reverse for this Transpose... I tried pressing Ctrl + Shift + T. and it just messed up everything...

Can anyone tell me what exactly this Ctrl + Shift + T does (especially with a block) ?

For instance:

public string returnDateTimeToMyformat(DateTime dt)
{
    dt = dt.AddYears(-1);
    return dt.ToString("yyyy MM dd HH mm ss");
}

To:

string returnDateTimeToMyformat publicdtDateTime (dt
{
    dt = )1AddYears(-.return;
    dt ).ToString("yyyy MM dd HH mm ss");
}

(I started with my cursor right after 'public')

like image 517
Umer Avatar asked Apr 05 '11 06:04

Umer


People also ask

What is the use of Ctrl-Shift-T?

It re-opens the last closed tab. We've all been there: Accidently closing a browser tab that you meant to keep open. Hit Ctrl-Shift-T and your tab will come back. Hit it multiple times to bring back the last several closed tabs in your history.

How do you transpose in VS Code?

To transpose characters, place the cursor between the two characters. With the caret in the correct position, you can press the appropriate shortcut key combination. To transpose characters, press Ctrl-T, for words use Ctrl-Shift-T and for entire lines press Shift-Alt-T.

What does Ctrl do in VS Code?

VS Code provides two powerful commands to navigate in and across files with easy-to-use key bindings. Hold Ctrl and press Tab to view a list of all files open in an editor group. To open one of these files, use Tab again to pick the file you want to navigate to, then release Ctrl to open it.

How do you use Alt Shift in VS Code?

You can select blocks of text by holding Shift+Alt (Shift+Option on macOS) while you drag your mouse. A separate cursor will be added to the end of each selected line.


4 Answers

Since CTRL-T swaps the two characters on either side of the cursor, the opposite of it is ...

wait for it ...

CTRL-T

:-)

CTRLSHIFTT transposes the two words after the cursor.

What it's doing to your block seems rather bizarre. It appears to doing it to multiple parts of each line. My only advice would be (as the doctor said to the patient who complained it hurts when banging their head against a wall): Don't do that.

like image 60
paxdiablo Avatar answered Oct 19 '22 17:10

paxdiablo


As others have pointed out, the two words following the cursor are transposed, and the cursor is placed after the words that have been transposed. However, Visual Studio 2010 at least appears to ignore commas and other punctuation when considering "words." One utility of this, then, is that you can reorder something like an enum. For instance,

typedef enum myEnum
{
  ThingOne,
  ThingThree,
  ThingTwo
};

Put the cursor somewhere near ThingThree and press CtrlShiftT to get:

typedef enum myEnum
{
  ThingOne,
  ThingTwo,
  ThingThree
};

This could be a good thing if you decide that a different order for your enums is better. You can also use this to help idiot-proof comparisons and/or quickly and easily format them to a better coding standard.

if ( ptr == NULL ) { /* stuff */ }

is considered bad (never mind that having an "if" on its own line is also bad) since you could easily write (or read) "ptr = NULL" by accident. You're better off with

if ( NULL == ptr ) { /* stuff */ }

So, if you did it wrong the first time, just select the offending expression and...CtrlShiftT to the rescue!

...Yeah, okay, so this thing isn't that useful.

Edit: Hmm, I should add that the behavior is a little weirder when your cursor is placed immediately before a punctuation symbol (such as a left-parenthesis), hence the weird result you got when you repeatedly hit CtrlShiftT on your code snippet. It seems to just swap any whitespace-terminated string after the cursor with the next alphanumeric "word," skipping over any punctuation symbols in between. The result is often difficult to read, though, so I'm not going to claim that's the exact pattern.

like image 27
Cosmicat Avatar answered Oct 19 '22 16:10

Cosmicat


According to this website:

Transposes the two words that follow the cursor. (For example, |End Sub would be changed to read Sub End|.)

The only question that remains is probably: WHY?? Well it might become handy when you have a block of code lines where variables are assigned values. (For example Load/Save) In the opposite function, you want to do the opposite assignment, maybe this shortcut can be used in such a situation...

like image 22
Rhapsody Avatar answered Oct 19 '22 17:10

Rhapsody


With this Visual Studio Document Reopen cool extension CTRL+SHIFT+T you can reopen the last closed document(s). It works like in Web browsers.

like image 44
Major Avatar answered Oct 19 '22 17:10

Major