ActiveState Powered by ActiveState

ActiveState Community


Duplicate Line?

Posted by jiminoc on 2007-01-30 18:50
OS: All / Any

Is there a keyboard shortcut for duplicating a line?

in other editors its something like control + D or CMD + D

ToddW | Tue, 2007-01-30 19:23

There is no one command that does this by default, but you can easily replicate this functionality through Komodo macros, see below:

Create a new macro in your toolbox, labeled "duplicate Line" or similar, add the following Javascript code:

// Macro recorded on Tue Jan 30 2007 18?? GMT-0800 (PST)
komodo.assertMacroVersion(2);
if (komodo.view) { komodo.view.setFocus() };
// Remove any current selection
var currentPos = komodo.editor.currentPos;
komodo.editor.setSel(currentPos, currentPos);
komodo.doCommand('cmd_copy');
komodo.doCommand('cmd_paste');

Then, in the macro properties form, go the "Key Binding" tab and in the "New Key Sequence" press Ctrl-D, then click on the "Add" button to assign the keybinding.

Close the macro, go back to your editing file and try using Ctrl-D.

Note: To create similar macros yourself, take advantage of the Macro recording tools:

  • Tools->Macros->Start Recording
  • Go to your editor, hit Ctrl-C (copy) then hit Ctrl-V (paste)
  • Tools->Macros->Stop Recording
  • Tools->Macros->Save To Toolbox

For further macro information, check out the Macro API documentation in Komodo's internal help.

Hope this helps,
Todd

jiminoc | Tue, 2007-01-30 20:25

Todd, you're the man. That worked great, thanks!

davida | Fri, 2007-02-02 10:02

Note that Ctrl+C if there is no selection copies the current line. I tend to do Ctrl+C/Ctrl+V to duplicate lines (making sure I have no selection first).

It's a controversial feature, FWIW. =)

--david

chemix | Fri, 2007-07-20 08:37

// Macro recorded on Tue May 15 2007 01:18:00 GMT+0200
komodo.assertMacroVersion(2);
if (komodo.view) { komodo.view.setFocus() };
komodo.doCommand('cmd_end')
komodo.doCommand('cmd_selectHome')
komodo.doCommand('cmd_selectHome')
komodo.doCommand('cmd_copy')
komodo.doCommand('cmd_lineNext')
komodo.doCommand('cmd_paste')
komodo.doCommand('cmd_newline')
komodo.doCommand('cmd_linePrevious')

chemix | Tue, 2007-07-24 19:02

// Macro recorded on Tue May 15 2007 01:18:00 GMT+0200
komodo.assertMacroVersion(2);
if (komodo.view) { komodo.view.setFocus() };

var ke = komodo.editor;
var savePos = ke.currentPos;
    
komodo.doCommand('cmd_end')
komodo.doCommand('cmd_selectHome')
komodo.doCommand('cmd_selectHome')
komodo.doCommand('cmd_copy')
komodo.doCommand('cmd_lineNext')
komodo.doCommand('cmd_paste')
komodo.doCommand('cmd_newline')
//komodo.doCommand('cmd_linePrevious')

ke.gotoPos(savePos);

chemix | Thu, 2007-08-02 07:07

http://pastie.caboo.se/84357

// Macro recorded on Tue May 15 2007 01:18:00 GMT+0200
komodo.assertMacroVersion(2);
if (komodo.view) { komodo.view.setFocus() };

var ke = komodo.editor;
var savePos = ke.currentPos;

komodo.doCommand('cmd_end')    
komodo.doCommand('cmd_newline')
komodo.doCommand('cmd_linePrevious')

komodo.doCommand('cmd_end')
komodo.doCommand('cmd_selectHome')
komodo.doCommand('cmd_selectHome')
new_selection = komodo.interpolate('%s');

komodo.doCommand('cmd_lineNext')

var pos = ke.currentPos;
ke.insertText(pos,new_selection);


ke.gotoPos(savePos);

zeropaper@drupal.org | Sun, 2007-10-21 02:55

Even if a copy/paste would do the thing, i found it really helpful.
I was using Notepad++ until yesterday, i do try to use Komodo now and it was a missing feature for me.

dafi | Sun, 2007-10-21 03:07

The version not using clipboard is perfect for me, thank you very much

dafi
Enhance KomodoEdit with MoreKomodo

mircho | Mon, 2008-01-14 07:12

(this is tested on Komodo Edit 4.2.1)

komodo.assertMacroVersion(2);
if (komodo.view) { komodo.view.setFocus() };
var ke = komodo.editor;
ke.lineDuplicate();

ToddW | Mon, 2008-01-14 13:36

Good spotting mircho. I did not even know that was already a function of Scintilla.

I've added the following bug to have this command added by default into Komodo:
http://bugs.activestate.com/show_bug.cgi?id=74284

Cheers,
Todd

ToddW | Wed, 2008-01-16 16:00

Does anyone want this duplicate line command to be enabled and assigned by default in Komodo? If so, to what key binding (Ctrl-D, Cmd-D)?

If enough people want it, then we'll turn it on by default. Appreciate your input.

Thanks,
Todd

Yes
corelist | Sat, 2008-04-19 09:25

Ctrl-D to be line duplicate by default :)

Yes
aaroncampbell | Thu, 2008-07-17 08:27

I'd like it, moving from Zend Studio I use it a lot (it's on ctrl+D by default there). However, I'd also like to see it duplicate the current line UNLESS there is a section, in which case it should duplicate the selection (be that a couple words or a few lines). Again, it's mostly because that's what I got used to in Zend Studio, but it's really nice to have.

ramin | Thu, 2008-01-17 12:00

Yes!
Cmd-D to use with Cmd-E (my personalization) to delete a Line

mircho | Fri, 2008-01-18 00:56

Duplicate line and the move line up and down were the things I missed the most when switched from notepad++
There it was Ctrl+D

WolframKriesing | Mon, 2008-06-30 10:36

I wrote this tiny macro that replicates the current line or selection, see more here:
http://blog.uxebu.com/2008/06/26/duplicate-lineselection-macro-for-komod...
looks like it could be optimized

have fun

Wolfram

chemix | Fri, 2008-07-18 08:40

// Duplicate Line or Duplicate Selection
komodo.assertMacroVersion(2);
if (komodo.view) { komodo.view.setFocus() };

var ke = komodo.editor;

if (ko.views.manager.currentView.scimoz.selText){
    // Copy the current selection
    new_selection = komodo.interpolate('%s');
    var pos = ke.currentPos;
    ke.insertText(pos,new_selection);
}else {
    ke.lineDuplicate();
}

chemiX // http://www.chemix.cz

ToddW | Thu, 2008-07-17 12:06

Update: The duplicate line command has been added to Komodo 4.4, though it does not have an assigned keybinding by default. You can search for the command in Komodo's "Editor->Key binding" preferences and assign whatever keys you like.

aaroncampbell | Thu, 2008-07-17 13:09

I opened an enhancement request (bug 78819) to make it duplicate the current line OR the currently selected text (if there is any).

-->