My name is Michael Hutchinson and I'm a software engineer working for Xamarin on the MonoDevelop IDE and Mono for mobile platforms. Here you can find my journal, projects and photos.

Journal

MonoDevelop Tips: Pinned Search Results

Some kinds of pads in MonoDevelop are transient. They cannot be accessed directly from a menu, but instead appear when needed to show the results of some operation, such as Find in Files, or Find References. Once closed, they can only be recovered by re-running the operation.

When another operation of the same kind runs again, it re-uses any existing pad of that kind, so they don't proliferate wildly. However, you can "pin" the pad by using the pin button in the pad, which means that it will not be re-used this way. Instead, the next operation will create a new pad. You can pin several pads, to save several sets of results, and further new pads will be created as necessary. When you are done, close or unpin the pad.

The following image shows a pinned pad. The pin button is at the bottom on the right side of the pad. Note that some MonoDevelop builds have a bug that causes the icon not to appear, but the button is still present and usable — it highlights when the mouse move over it, and shows a depressed state when enabled.

A pinned Search Results pad

MonoDevelop Tips: Show All Files

The MonoDevelop Solution Pad shows projects and folders that correspond to real folders on disk, but by default it only shows files and folders within them that have been included in the project. This behaviour can be changed using the Display Options->Show All Files toggle option in the Solution Pad context menu. The option is contextual — it applies only to the item on which it is toggled, and recursively applies to all its children. To have it apply to the whole Solution Pad, toggle it on the root solution or workspace.

When Show All Files is enabled, files that are not included in the project will be shown in the folder hierarchy, but with semi-transparent icons to indicate their status. They can be edited and moved and so on, though they will not be included in the code completion system. Perhaps the most useful thing that this option enables is the Include in project context menu command on non-included files, which can be used to include them in the project quickly and easily.

MonoDevelop Tips: Code Generation Window

The Code Generation window can be used to automatically generate code for various patterns, based on existing code. It can be triggered from the context menu, or from the Edit->Show Code Generation Window menu. On Windows and Linux the keyboard shortcut is Alt-Insert and on Mac there's currently no keybinding (if you'd like to suggest one please use the MonoDevelop mailing list).

The code generation window is shown at the caret location, and its contents are context-dependent. For example, within a method it can generate things like null checks for the method's arguments, and in a class body it can generate things like a constructor with parameters that are assigned to properties and fields in the class.

Highlight usages

Navigate up and down in the window using the arrow keys to select the code generator you wish to use, then move to the item list using the enter or tab key. Here you can navigate up and down using the arrow keys and toggle items on and off using the space key. The mouse can be used too, but the keyboard is much faster. if you change you mind about which generator to use, shift-tab will move the focus back up to the list of generators. Finally, press the enter key to generate the code for the items you selected.

Here is the constructor code generated after selecting all three properties in the dialog shown above:.

Highlight

MonoDevelop Tips: Hidden Editor Commands

The MonoDevelop text editor has many commands are not immediately obvious. Some are accessible from the Edit and Edit->Format menus, and some have default keybindings, but many can only be used if you manually add keybindings for them. Some even have keybindings that are hardcoded into the text editor, and will be available unless you override it by assigning that some keybinding to some other command.

Here is a selection of some that may be useful:

Join Lines
Joins the current line with the next line, i.e. removes the next line and appends it to the current line, separated by a space. If multiple lines are selected, it will join them all into one line.
Transpose characters
Swaps the characters on either side of the caret (Control-T on Mac)
Delete to end of line
Deletes from the caret to the end of the current line (Control-K on Mac)
Find caret
Triggers an animation showing where the caret is (Command-| on Mac)
Go to matching brace
Moves the caret to the counterpart of the adjacent brace or bracket
Insert line break after caret
Moves the text after the caret onto a new line without moving the caret (Control-Enter on all platforms, and also Control-O on Mac)
Move caret to EOL and insert new line
Inserts a new line below the current line and moves the caret to it (Shift-Enter on all platforms
Recenter editor
Moves the scrollbars so that the caret is centered in the editor (Control-L on Mac)

MonoDevelop Tips: Next/Previous Usage

After the caret has been in an identifier in a C# file for a few seconds, then all the usages of that identifier in the current file are highlighted. This provides a nice visual cue for finding related code and following code flow.

Highlight usages

There are also commands for quickly moving between these usages. On Windows and Linux they're bound to Control-Shift-Up and Control-Shift-Down, and on Mac they're Command-Shift-Up and Command-Shift-Down.

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.

Pages

Subscribe to Journal