More Visual Studio 2008 Shortcuts: Trasposing Characters, Words and Lines

1 minute read

I love shortcuts. I really do. So with some excitement I have found a few in the Visual Studio Editor that may come handy once in a while. These are the shortcuts to transpose characters, words and lines:

CTRL + T Transpose characters
CTRL + SHIFT + T Transpose words
ALT + SHIFT + T Transpose lines

Transposing Characters (CTRL+T)

This is mostly useful if you mispelled a word. Since most code typing is done with Intellisense, I have found this useful for comments mostly.

Transposing Words (CTRL + SHIFT + T)

Beside the occasional typo writing comments, this is handy when after refactoring a function signature I have changed the order of the parameters.
Suppose you have for example you call a function in the following way:

calculateVat(price, percentage)

if for whatever reason calculateVat signature has changed so that the percentage comes first, you just need to put the cursor on price or between the two words and pressing CTRL + SHIFT + T you'll have the following:

calculateVat(percentage, price)

Transposing lines (ALT + SHIFT + T)

I use the following formatting to wrap long function signauters across more lines:

public void AddEmployee(
    string name,
    string surname,
    string address,
    string homePhone,
    string mobilePhone,
    string email)
{
   // implementation here
}

Suppose that I decide that I want to reorder the parameters such that the mobilePhone comes before than homePhone, for whichever reason. I just need to place the cursor somewhere on the line of "homePhone" and the two lines will swap. To remember which is the direction of swapping, my mnemonic is that the line where the cursor is will fall.

public void AddEmployee(
    string name,
    string surname,
    string address,
    string mobilePhone, // this line has moved up
    string homePhone,  // this line has moved down
    string email)
{
   // implementation here
}

This is especially useful if you have more overloads of the same function where you need to update the order of the parameters in each of them. It's certainly quicker than a copy&paste tecnhique.

If you need to move one line of more than one position down, just keep pressing the ALT + SHIFT + T combination and the line will keep falling down (the cursor automatically stays in the line that is moving).

Updated:

Leave a Comment