Oct 20th, 2008 | No Comments

The clipboard ring is not the only copy and paste feature in Visual Studio; a number of shortcut keys allow you to copy and paste code even faster.

Most applications rely on you selecting which text you want to cut, copy, or delete. Visual Studio makes the very simple assumption that if you have not selected any text that you want to cut, copy, or delete, the editing action will be performed on the entire current line. If you wanted to move one line below another line, you could move the cursor to the first line, press Ctrl-X (Edit.Cut) to cut the line, press the down arrow to move to the next line down, and then press Ctrl-V (Edit.Paste) to paste the entire line. Other shortcuts like Ctrl-C (Edit.Copy) and Ctrl-L (Edit.LineCut) follow this same rule and allow you to copy or delete the current line by simply pressing the shortcut keys without selecting any text. Any time you can avoid reaching for the mouse to select text is time saved.

Written by Ajay Matharu

October 20th, 2008 at 4:08 am

Oct 14th, 2008 | No Comments

Normal text selection is done on a line-by-line basis; it is impossible to select parts of multiple lines with normal text selection. Figure 2-2 shows how it is not possible to select just the right side of the equals sign using normal text selection. This is a drawback that most of us have become accustomed to.

Visual Studio has a feature that allows you to get around this limitation. By holding the Alt key while selecting text, you trigger block selection, which allows you to select text regardless of what line it is on. Figure 2-3 shows how block selection can be used to select only text to the right of the equals sign.

Block selection can be used to select any amount of text in a block, as opposed to line by line. You can use block selection whether you select text with the mouse or the keyboard (hold down Alt and Shift, and press the arrow keys to perform a block selection with the keyboard).

When pasting block selections, Visual Studio will insert each line of the block onto a subsequent existing line, unlike normal selections where new lines will be inserted. Thus, it is important to be sure that the destination for your block selection is the same number of lines as the source.

Written by Ajay Matharu

October 14th, 2008 at 4:52 am