This is a discussion on Visual Studio Tips & Tricks within the C# Programming forums, part of the Software Development category; 1.4 -Selecting a Single Word (Ctrl+W) To select a single word when editing code: Double-click anywhere in ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 1.4 -Selecting a Single Word (Ctrl+W) To select a single word when editing code: Double-click anywhere in the word or just press Ctrl-W. Double-clicking in a word is a common method used by many word processing and publishing programs to quickly select a word. |
| Sponsored Links |
| |||
| 1.5 -Placing Code into the Toolbox (Ctrl-Alt-X) When creating a project, you may want to use certain pieces of code or text again and again. You may have a standard copyright header that you place at the top of each file or a certain line of code to perform a common task. To simplify this repetitive task, you can place it into your Toolbox. The Toolbox is the window that lists all windows or web controls. To place your item into the Toolbox, use the following method: 1. Pull up the Toolbox: Press Ctrl-Alt-X. 2.Move the frequently used text or code into the Toolbox: Highlight your item and drag the selected text onto the General tab in your Toolbox (see Figure 10). 3.Rename the produced text item in your Toolbox Right-click it and choose Rename Item from the pop-up menu. ![]() Figure 10. Adding text to the Toolbox To insert an item into your text or code from the Toolbox: Select the item in your Toolbox, then either: Drag it into your code window or Place your cursor in your text where you want to insert the item, Double-click the entry The General tab in the Toolbox is project and solution independent, and it retains its content even after you restart VS.NET. |
| |||
| 1.6 - Using the Clipboard Ring (Ctrl-Shift-V) The Clipboard Ring works like a historical file of the last used text selections that you placed on the Clipboard. Because it preserves many levels of selections, it is useful when you accidentally overwrite the current Clipboard content or when you find yourself needing several different items concurrently. To use the Clipboard Ring you can either: Double-click one of the remembered Clipboard items to paste it at the cursor’s current location or Drag it into the editor. When the Clipboard Ring contains many Clipboard items, or when you cannot see the complete contents of each item in the ring, it’s useful to cycle through the Clipboard Ring. To progress one item at a time through the Clipboard Ring: Select Edit > Cycle Clipboard Ring (Ctrl-Shift-V) Doing this repeatedly makes VS.NET cycle through the Clipboard Ring’s contents, displaying the stored Clipboard contents in the text editor at the cursor’s current location. This method makes it easy to paste specific content in the code editor as it becomes visible during the cycling. Continue cycling through the Clipboard’s contents until you find your desired item. |
| |||
| 1.7 - Transposing a Single Character or Word (Ctrl-T or Ctrl-Shift-T) To switch the position of the current characters or words on either side of the cursor you need to use Transpose. This procedure switches the characters or words, then moves the cursor to the right. Transpose is useful if you mistype a word or write a sentence or code segment with words in the incorrect order. To transpose a single character: Press Ctrl-T. This swaps the two characters surrounding the cursor and moves the cursor to the right by one character. Pressing Ctrl-T repeatedly allows you to move a single character further to the right one character at a time. To transpose a single word: Press Ctrl-Shift-T. Note: This does more than just swap two adjacent words. VS.NET knows to ignore “unimportant” single characters, such as equal signs, string quotes, white spaces, commas, etc. Suppose you have a line of code that originally looks like this: new SqlCommand("trans", stored_procedure, conn); Pressing Ctrl-Shift-T repeatedly on the word “trans” would yield the following: new SqlCommand("stored_procedure", trans, conn); and finally this: new SqlCommand("stored_procedure", conn, trans); The quotation marks and commas retain their original positions throughout the process. When you reach the end of a line, pressing Ctrl-Shift-T transposes the word with the first word of the next line. |
| |||
| 1.8 - Cutting, Copying, Deleting, and Transposing a Single Line If you need to cut, copy, delete or transpose an entire line, you can do this easily with one keyboard sequence. To copy the complete, current line to the Clipboard: Press Ctrl-C (or click the Copy icon) without any text selected. To cut an entire line: Press Ctrl-X (or click the Cut icon) without any text selected. This will cut the entire current line and place it in the Clipboard. To delete a single line: Press Ctrl-L without any text selected. To transpose, or swap the current line with the one below it: Press Alt-Shift-T without any text selected. Doing this also moves the cursor down by one line. This allows you to press this keyboard shortcut repeatedly until you move your current line to the desired position. |
| |||
| 1.9 - Formatting Entire Blocks (Ctrl-K, Ctrl-F or Ctrl-K,Ctrl-D) To apply formatting to an entire selection, there are several useful functions you can use. Uppercasing, lowercasing, or deleting horizontal white spaces are just a few examples. To access these features: Select Edit > Advanced One of the most useful features here is the Format Selection function. To access the Format Selection Function: Press Ctrl-K, Ctrl-F, This feature formats an entire selection and inserts tabs where appropriate to modify the code with the correct code-specific block indentation. This is usually done automatically when someone enters code upon closing a block (such as by typing the “}” sign in Visual APL) but Format Selection forces this automatic format (see Figures 11 and 12). You can also format the entire document. To do this: Press Ctrl-K, Ctrl-D. ![]() Figure 11. Before formatting block ![]() Figure 12. After formatting block |
| |||
| 1.10 - Toggling Word-Wrapping (Ctrl-R,Ctrl-R) To turn word wrapping on and off for the current view: Select Edit > Advanced Or use the keyboard shortcut: (Ctrl-R, Ctrl-R) |
| |||
| 1.11 - Creating GUIDs As you develop new classes and components, you often need to create Global Unique Identifiers (GUIDs). These are 128-bit values often represented by 32 hexadecimals. In the past, component developers used GUIDs to assign their components with unique names to reduce the likelihood of two components sharing the same GUID. Developers now use GUIDs for anything that requires a unique identifier. GUIDs can be created manually by randomly selecting 32 hexadecimals, but this is somewhat tedious. VS.NET comes with a utility that creates GUIDs for you whenever you need one. To create a GUID, open the Create GUID dialog box: Select Tools > Create GUID (see Figure 13). Here you can generate identifiers in various formats, including common code items often used in COM development. ![]() Figure 13. Create GUID tool |
| |||
| 1.12 - Creating Rectangular Selections To make a rectangular selection of text or code, there is a technique which allows you to do this without including the intervening lines (see Figure 14). To select a rectangular area: Press the Alt key while dragging the mouse to select the area. Manipulating the selection by copying, cutting, or pasting rectangular blocks can be done very easily this way. ![]() Figure 14. Rectangular selection |
| |||
| 1.13 - Switching Between Views (F7) For Windows forms, you can easily switch between both views. To toggle between designer and code views: Press F7 (designer and code) |
| |||
| 1.14 - Going to a Line Number (Ctrl-G) For quick and easy navigation inside your code or text file, you can jump to a particular line. To go to a specific line number you need to access the go to dialog box. To do this, either: press Ctrl-G or double-click the line number status bar at the bottom. A small dialog box will appears. To jump to a line number: enter a line number If you type a line number that is out of the range of possible line numbers, the cursor jumps to the beginning or end of the file, respectively. A number which exceeds the number of lines in the file will place you at the end of the file. A number that is too low will jump you to the beginning of the file. |
| |||
| 1.15 - Searching for a Word There are several methods for searching for a word inside a file. It is helpful to know all the methods for ease in moving around your file. The following are common methods for finding a word. 1.Access the Find dialog box Select Edit > Find Enter a term in the Find dialog box. 2.Access the Combo box in the main toolbar next to the configuration drop-down list. To open the combo box and invoke the search function: Press Ctrl-D Enter or paste a word into this list and press Enter Repeat pressing Enter in that drop-down list to find the next match. 3.Select the entire word, or place the cursor somewhere inside the word: Press Ctrl-F3. This invokes the same search function I described just previously. Repeatedly pressing Ctrl-F3 iterates over all matches. Using either the combo box or the Ctrl-F3 shortcut applies the same search options specified in the Find dialog box. Set the options you desire in the Find dialog box first to search correctly (for example, enabling Search Hidden Text to include all collapsed regions in the search area). |
| |||
| 1.16 - Performing an Incremental Search (Ctrl-I) An incremental search allows you to find occurrences of a search key as you type it one letter at a time. After each keystroke, VS.NET immediately highlights the next available occurrence that matches whatever you have typed so far. The more letters you type, the more likely is it that the found occurrence is indeed what you are seeking. To initiate an incremental search: Press Ctrl-I You do not need to enter the entire word to find a specific occurrence; you only need to type the minimum number of characters that would uniquely identify the word for which you are searching. To return to normal editing mode: Press Escape In the Cielo Explorer you have to single click with the mouse. If you are unsatisfied, press Ctrl-I repeatedly to find the next occurrence that matches your partial search key, or press Ctrl-Shift-I to find the previous matches. You can, of course, simply enter more letters to narrow the search further. |
| |||
| 1.17 - Searching or Replacing with Regular Expressions or Wildcards Regular expressions can look extremely intimidating, but they are extremely powerful tools to find complicated search keys and patterns. Regular expressions is a built in feature that allows you to describe a searchable pattern in terms of wildcards, characters, and groups. This feature in VS.NET is often overlooked by many developers. To access this feature, bring up the Search or the Replace dialog box: Press either Ctrl-F or Ctrl-H, respectively Note: Besides the regular options to refine your search, the last check box allows you to define your search based on regular expressions or wildcards. You can use either of two modes. To use Regular Expression mode, specify the expression using a similar notation you are accustomed to with the System.Text.RegularExpressions namespace. To see a list of possible constructs that you can insert into your regular expression: Click the arrow button next to the Find What field (see Figure 15). ![]() Figure 15. Use regular expressions. To use Wildcard mode, construct your search pattern using the more commonly known wildcards from MS-DOS, such as “*” and “?”. If used correctly, these two modes can be very helpful in refining your search algorithm or when developing programs based on regular expressions. |
| |||
| 1.18 - Global Search or Replace (Ctrl-Shift-F or Ctrl-Shift-H) The global search and replace feature in VS.NET spans entire projects and solutions. This is similar to normal search and replace dialog boxes, except that you can specify the scope of the search or replace action over multiple files. To bring up the global search or global replace dialog box: Press Ctrl-Shift-F or Ctrl-Shift-H, respectively This feature allows you to perform a global search and replace in just the current document, the current project, the entire solution, or any open documents (see Figure 16). You can also filter which files you want to search based on wildcards. ![]() Figure 16. Global search and replace. Once the search or replace action is started, VS.NET searches all specified documents and modifies them if required. The global replace, will also prompt you to leave modified documents open. This option allows you to undo the replace, because only open documents offer the undo feature. If you don’t select that option, global replace will automatically save the modified files and make this a permanent action. To immediately stop a global search or replace anytime: Press Ctrl-Break. Once a search or replace action is completed, a list of occurrences that have been found will be displayed in the “Find Result” dialog box. To iterate over the Find Result list: Press F8 or navigate to an occurrence by double-clicking it. If that occurrence is currently located in a collapsed region, you can expand it. To automatically expand the region: Double-click the same find result in the list again. On initiating a new find or replace action, VS.NET clears this window to fill the list with the new results. If you want to keep the results of the previous search and output the result in a second window: Check the Display in Find 2 option in the search dialog box You can then tab between both result sets. All find/replace functionalities are included in a single dialog box (see Figure 17), you can also access the global find/replace functionalities using the drop-down list at the top. All shortcuts remain the same. ![]() Figure 17. Global replace in files |
| |||
| 1.19 - Using Bookmarks Bookmarks enable you to return quickly to a given page or section of your code or file. When you determine critical sections of your programming that you want to return to frequently, instead of scrolling to these places, bookmark those lines. To place a bookmark, first, make the bookmark toolbar visible: Right-click any existing toolbar and select Text Editor from the pop-up menu. Click on the blue flag icon in Text Editor toolbar. Another method which can be used to place a bookmark: Press Ctrl-K, Ctrl-K. This second method not only makes a bookmark visible on the left side of the code, but you can now jump quickly among other bookmarks. To jump to the other bookmarks you can either: Click the appropriate flag buttons on the toolbar (see Figure 18) or Press Ctrl-K, Ctrl-P (for the previous bookmark) or Ctrl-K, Ctrl-N (for the next bookmark). ![]() Figure 18. Bookmark toolbar To clear all bookmarks: Press the Clear Flag icon or Press Ctrl-K, Ctrl-L. The Find dialog box in VS.NET allows you to bookmark all matching occurrences as follows: Click the Mark All button. As part of VS.NET 2005 considerable support for bookmarks, you can also have the option of moving to the next or previous bookmark within the same file as follows: Press the appropriate buttons on the bookmark toolbar (see Figure 28). ![]() Figure 28 - Move to bookmarks in the same file in VS.NET 2005 You can also name your bookmarks by first opening a new Bookmarks window: Press Ctrl-K, Ctrl-W or Select View > Other Windows >Bookmark Window. This displays all the bookmarks that you have created (see Figure 19). To jump to a bookmark’s location: Double-click the bookmark. To rename a bookmark: Press F2 or Right-click the bookmark and use the Rename context menu item. You can categorize your bookmarks and organize them into folders. You can also, jump to the next or previous bookmark within the same folder. To perform any of these functions, simply select the appropriate icon on the toolbar. ![]() Figure 19. Manage your bookmarks in the Bookmarks Window. The Bookmarks window shows check boxes next to each folder and bookmark. These allow you to disable a bookmark without deleting it. Disabled bookmarks are skipped when you use any of the buttons or shortcuts to navigate your bookmarks. |
| |||
| 1.20 - Using Browser-Like Navigation (Ctrl -, Ctrl Shift -) VS.NET is equipped with browser-like “back” and “forward” buttons in the IDE that allow you to review the most recent cursor locations. The Navigate-Backward and Navigate-Forward buttons are located to the right of the Undo and Redo buttons (see top left of Figure 20). You can also access them in the View menu. ![]() Figure 20. Navigate buttons Similar to a web browser, VS.NET keeps a history of your recently accessed locations. After using the Go To Definition feature or after switching arbitrarily to another file or even just jumping between different line numbers of the same file, you can easily return back to the last edit location as follows: Click the Navigate-Backward button. These Navigate buttons have pre-assigned shortcuts. To Navigate back: Press Ctrl-Hyphen To Navigate forward: Press Ctrl-Shift-Hyphen. |