Update: This add-in breaks with the new Monodevelop 4 that ships with Unity 4.3. However, Monodevelop 4 comes with a “duplicate line” function for which you can assign a shortcut in the key bindings in preferences.

This is one of those things that you don’t know you need until you have it, and the one feature I’ve missed the most since my Eclipse/FlashBuilder days:
I wrote a little MonoDevelop Add-In that lets you duplicate the line you’re on (or multiple selected lines) by pressing Alt+Ctrl+Up to duplicate above or Alt+Ctrl+Down to duplicate below your current position. In combination with Alt+Up and Alt+Down (which move selected lines around), this comes in super handy for dealing with repetitive blocks of code (such as variable declarations).

You can download the plug-in here: http://www.philippseifried.com/files/MonoDevDuplicateSelection.zip

To install, close MonoDevelop and copy the DLL into the folder /Applications/Unity/MonoDevelop.app/Contents/MacOS/lib/monodevelop/AddIns on Mac, or [Unity install path]/Unity/MonoDevelop/AddIns on Windows. After starting MonoDevelop again, you can use the keyboard shortcuts, or access the functionality from the Edit menu.

Note that you will need to re-install the Add-In if you update Unity!

The Add-In is under MIT license, so feel free to use and redistribute it as you see fit. I’ve tested it on Windows and Mac (where I’ve been using it daily for a few weeks), but of course standard disclaimers apply: Use at your own risk!

 

4 Responses to Unity/MonoDevelop Add-In: Duplicate selected lines with a keystroke.

  1. Avatarchik says:

    Hi! Can put the source code?

  2. Philipp says:

    Hey!
    It was quickly hacked together, so it’s not super-clean, but you can check out the source here, if you want to: http://www.philippseifried.com/files/MonoDevDuplicateSelection_Source.zip

  3. Alex says:

    Hi Philip,

    Excellent idea! Unfortunately, I just tested it in MonoDevelop 4.0.1 (which now ships with Unity 4.3.x) and this doesn’t work. For reference, here’s the error code:

    System.MissingMethodException: Method not found: ‘Mono.TextEditor.LineSegment Mono.TextEditor.TextEditorData.GetLine(Int32)’.
    at MonoDevelop.PS.DuplicateSelection.DuplicateBelowHandler.Run()
    at MonoDevelop.Components.Commands.CommandHandler.Run(Object dataItem) in c:\BuildAgent\work\d478831d940d36a4\monodevelop\main\src\core\MonoDevelop.Ide\MonoDevelop.Components.Commands\CommandHandler.cs:line 61
    at MonoDevelop.Components.Commands.CommandHandler.InternalRun(Object dataItem) in c:\BuildAgent\work\d478831d940d36a4\monodevelop\main\src\core\MonoDevelop.Ide\MonoDevelop.Components.Commands\CommandHandler.cs:line 42
    at MonoDevelop.Components.Commands.CommandManager.DefaultDispatchCommand(ActionCommand cmd, CommandInfo info, Object dataItem, Object target, CommandSource source) in c:\BuildAgent\work\d478831d940d36a4\monodevelop\main\src\core\MonoDevelop.Ide\MonoDevelop.Components.Commands\CommandManager.cs:line 1097
    at MonoDevelop.Components.Commands.CommandManager.DispatchCommand(Object commandId, Object dataItem, Object initialTarget, CommandSource source) in c:\BuildAgent\work\d478831d940d36a4\monodevelop\main\src\core\MonoDevelop.Ide\MonoDevelop.Components.Commands\CommandManager.cs:line 1067

    • Philipp says:

      Hi! Yes, it’s broken in the new Monodevelop 4, and I don’t know if/when I’ll get around to fixing it. The good news is, Monodevelop can now duplicate at least the line you’re on. Look for “duplicate line” in the keybindings in preferences!

Leave a Reply

Your email address will not be published. Required fields are marked *

*


2 + = eleven

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>