I make tools to help people create wonderful things.


MonoDevelop Tips: Block Selection Mode

Sometimes it's useful to be able to edit multiple lines at once in a similar way. This is possible in MonoDevelop using block selections. To make a block selection, drag the mouse between the start and end points while holding down the Alt key on Linux or Windows, or Command key on Mac. Alternatively, you can make a normal selection, then use the Edit->Toggle block selection mode to toggle the selection into a block selection with the same start and end points.

A block selection in the MD text editor

Block selections can be cut or copied, and when pasted will paste as a block. Block selections can also be edited, to modify text on multiple lines at once. An side effect of this is that a zero-width block selection can be used an a sort of multi-line caret, to type identical text on multiple lines.

MonoDevelop Tips: Show Next/Previous Result

One of the most useful pairs of commands in MonoDevelop is Show Next Result and Show Previous Result. These commands move through items in the most recently active navigation list. Right after building, they will cycle though the build errors and warnings; after searching, they cycle through the search results; after running unit tests, they cycle though the test failures, and so on.

The commands can be found in the Search menu as Show Previous and Show Next, and the names change to indicate which type of result is active. The keyboard shortcuts on Windows and Linux are F4 to move to the next result, and Shift-F4 to move to the previous result. On Mac, they're Command-= and Command-+ respectively.

MonoDevelop Tips: The Clipboard Ring

The MonoDevelop text editor keeps track of the most recent 12 things that have been cut or copied. This can be useful when you realize you want something you cut or copied earlier. These items can be found in the Clipboard Ring in the toolbox. Simply double-click on one to insert it at the caret, or drag it to a specific location to insert it at that location.

The Clipboard Ring

MonoDevelop Tips: Dynamic Abbrev

MonoDevelop's code completion for C# provides highly context-sensitive and accurate suggestions. However, it can't provide completion in plain text, such as comments or strings. To help with cases like this, and for languages where MD does not have a completion engine, we've implemented a feature from Emacs called "dynamic abbrev".

Simply type the start of a word, and then use the dynamic abbrev command to cycle though the available completions for that word until you get the word you want. The default key combination is Alt-/ on Windows or Linux, and Command-/ on Mac. It doesn't pop up a completion list, it just replaces the completed word in place each time you press the combination. The words used for this autocompletion are found by first looking at all words in the current file, and then the words in all other files that are open.

MonoDevelop Tips: Renaming Symbols

One of the most useful refactoring commands is "Rename", which renames a symbol by accurately finding all occurrences and changing them. To rename a symbol, right click on it and choose Refactor->Rename context menu command, or use the keybinding: F2 on Windows and Linux, and Cmd-R on Mac.

The Rename dialog

You will be shown a dialog allowing you to enter a new name, then given the option to either preview all the changes before applying, or apply them immediately. The preview shows a diff of all changes that will be made in the solution.

Rename Preview

Full renaming can be very slow, because it has to inspect all files in all projects within the solution. However, when renaming locals, since the changes only affect the current file, MonoDevelop makes the changes inline in real time. It selects all of the occurrences of that symbol and links them, so that as you alter the definition, all the references are immediately updated to match.

Inline Renaming

You can hit Enter to finish the rename or Escape to cancel it.

Going to GDC

I'm going to be in San Francisco next week for GDC. I'll be wandering around SF on Sunday 27th Feb, going to the summits on Monday and Tuesday, then on the Mono booth in the GDC Expo Wednesday through Friday.

If you're at GDC, please drop by our booth! And whether you're at GDC or just in the area, drop me an email or tweet me if you'd like to hang out (schedule permitting) and discuss anything related to Mono in games, Mono in general, MonoTouch, MonoDroid, and MonoDevelop.

MonoDevelop Tips: Override Completion

When you type the "override" keyword in a C# class, MonoDevelop will show a completion list of all abstract or virtual members on base classes that have not been overridden, and interface members that have not been implemented. You don't even need to type the modifier (e.g. "public"), you can simply type "override" directly in the class body.

Override completion

When you commit a selection from the list, it generates the implementation with the correct signature, with a single statement &emdash; a call to the base implementation if appropriate, or a NotImplementedException. This implementation is selected so you can immediately start replacing it with a real implementation.

Generated override implementation

MonoDevelop Tips: Code Snippets

Code snippets (or code templates) are an incredibly useful feature. They allow inserting and editing template blocks of code, which is useful for quickly replicating common patterns, or learning new patterns. This post explains how to use snippets, and a future post will explain how to create snippets.

Inserting Snippets

There are three ways to use snippets: the Insert Template command, Tab expansion, and the Toolbox.

Insert Template Command

The Insert Template... command can be activated from the Edit->Insert Template... menu, or the Control-T keybinding on Windows and Linux. It shows a list of all templates valid for the current file type, and you can match them using the same substring matching as the completion list. Select one and hit Enter to activate it.

The Insert Template list

If there is a selection, then this command will turn into the Surround With... command. This only shows templates that have the "Surround With" flag. They will take the current selection and incorporate it into the template. For example, the "for" template will put the selection into the loop body.

Tab Expansion

If the snippet has a shortcut, type the shortcut and then hit Tab. The shortcut will be in the completion list, so if you pick the item from the completion list you must hit tab twice, once to commit the selection, and once to expand it. The second tab is necessary because snippets may have the same name as keywords or symbols, and if they activated as soon as they were committed, you would not be able to type the keyword or symbols. Indeed, there are built-in snippets for many C# keywords.

The Toolbox

When the text editor is focussed, the Toolbox Pad shows all of the snippets valid for the current document. Drag one to the text editor to insert it at a specific position, or double-click it to insert it at the caret position.

Code Snippets in the Toolbox

Using Snippets

When a snippet is inserted, it may simply insert plain text and move the caret to a location somewhere within it. However, advanced snippets will have linked regions to enable you to customize the usage of the snippet. For example, the C# "for" snippet contains two editable regions, with other regions linked to them.

Expansion of the 'for' template showing linked regions

When the template is activated, the region with the declaration of the loop variable "i" is selected. You may type a new name, and both other uses of that name will be updated. Then, hit Tab to move to the next editable region. You can now change the value of the upper limit of the loop. Tab and Shift-Tab can be used to cycles between the editable regions, and when you are done, hit Enter or Escape to exit region editing mode and move the caret to the loop body.

MonoDevelop Tips: Comment Block of Code

While experimenting with code, it can be very useful to comment a block of code temporarily.

To comment a block of code, use select Toggle Line Comment(s) from the context menu, or use the Control-Alt-C keybinding on Windows and Linux. If the current line is commented, it will be uncommented, or if it is not commented, it will be commented. If multiple lines are selected, then if any are not commented, they will all be commented. If all are commented, they will all be uncommented.

For C# files, this feature uses line comments, and if lines that are already commented are commented as part of a larger block, it adds another "level" of line comments onto those lines. This is useful, because it means that a region of code can be commented then uncommented, and actual comments within it will be preserved.

If you prefer to use multiline comments or #if false directives, you can use "surround with" templates, which will be covered tomorrow.

MonoDevelop Tips: Changing Indentation

It's easy to increase or decrease indentation of a block of code in MonoDevelop. Hit the Tab key while there is a selection, and the selected lines' indentation will be increased. Similarly, hit Shift-Tab and the indentation will be decreased.

There is also a command to do this. The indent command can be found in the Edit->Format->Indent Selection menu, with the keybinding Control-Alt-End on Windows and Linux, and Cmd-] on Mac. The unindent command is Edit->Format->Unindent Selection, with the keybinding Control-Alt-Home on Windows and Linux, and Cmd-[ on Mac.

MonoDevelop can also set the indentation to the "correct" value (as determined by the smart indenter) when tab is pressed, like emacs does. This can be enabled with Preferences->Behavior->Interpret tab as reindent command. For some reason, this command isn't keybindable.


Subscribe to Journal