Visual Studio Hacks [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Visual Studio Hacks [Electronic resources] - نسخه متنی

Andrew Lockhart

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Hack 6. Master the Clipboard

In theory, a clipboard should be simple: copy,
cut, or paste. But that's no fun! You can learn how
to really supercharge these operations.


Visual
Studio contains a number of different features pertaining to cutting
and pasting and the clipboard. Some of these features are old text
editor favorites that are finally making it into Visual Studio, and
some are new innovations from the Visual Studio team. These might
seem like small features in a program that is as feature-packed as
Visual Studio, but the clipboard will affect your day-to-day
programming more than most other features.


2.2.1. Clipboard Ring


When you copy and paste text in any application, you are usually
limited to copying and pasting one item at a time. If you want to
copy two separate sentences, you have to copy the first one, paste
it, then come back and repeat this for the next sentence. This can
become tedious when you have 10 different things to copy and they
reside in 10 different places in the document. You end up switching
back and forth between the two documents 10 times, once for each
sentence you want to copy.

The clipboard ring eliminates this limitation. The clipboard ring
allows you to cut or copy up to 20 selections and access them using a
keyboard shortcut. Here is the process for using
the clipboard ring:

Copy (Ctrl-C, Edit.Copy) or Cut (Ctrl-X,
Edit.Cut) up to 20 text selections, one after the other. These
selections are organized as a last-in-first-out (LIFO) stack. That
is, the last item you cut or copy will be the top item on the
clipboard ring.

Press
Ctrl-Shift-V
to paste the first selection (the item on the top) from the clipboard
ring into your document.

If you don't want to paste the first selection,
press Ctrl-Shift-V (Edit.CycleClipboardRing) again, and the first
thing you pasted will be replaced with the next selection from the
clipboard ring. For example, if you wanted to paste the fourth item
in the clipboard ring, you would simply press Ctrl-Shift-V four
times. If you want to paste the same item more than once, simply
pressing
Ctrl-V
(Edit.Paste) after the first time will work, since it will now be the
current item on the clipboard.

Instead of moving between two documents a number of times, copying
and pasting different selections, you can first copy all of the
selections from the first document, then go to the second document
and, using the clipboard ring, paste all of those selections. The
clipboard ring also comes in handy when you have two or more separate
things that you need to paste multiple times; using the clipboard
ring, you can switch back and forth between these items easily.

You can also view the current contents of the clipboard ring by
selecting the Clipboard Ring tab in the Toolbox dialog. This tab,
shown in Figure 2-1, displays all of the selections
currently living in the clipboard ring and allows you to drag the
selections to paste them into your document.


Figure 2-1. Clipboard Ring tab in Toolbox dialog

While the Clipboard Ring tab is a good way to get a better
understanding of the clipboard ring, it is not as efficient as the
shortcut keys. Visual Studio .NET 2003 users will find that the
Clipboard Ring tab is absent in Visual Studio 2005, so it is best to
use the shortcut keys instead of the Toolbox tab.


2.2.2. Line-Based Cut and Paste


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.


2.2.3. Block Selection


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.


Figure 2-2. Normal text selection

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.


Figure 2-3. Block text selection

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.


/ 172