Duplicate Line?

Posted by jiminoc on 2007-01-30 18:50
Forums: Komodo support | OS: All / Any

Is there a keyboard shortcut for duplicating a line?

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

toddw
ActiveState Staff
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
ActiveState Staff
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
ActiveState Staff
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-komodo/
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
ActiveState Staff
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).

nanomir | Sat, 2009-02-14 07:47

Hi all, I was looking for:

Update: The duplicate line command has been added to Komodo 4.4

But couldn't find in Komodo Edit 5... This was one of the features of Notepad++ I miss the most, so I decided to make a plugin, please check here:

MoreNppKomodo
http://code.google.com/p/morenppkomodo/wiki/StartPage?tm=6

There's a bit of a discussion there too... The source is given as a Komodo Edit project, that compiles within Komodo Edit 5. Any feedback welcome...

toddw
ActiveState Staff
Sat, 2009-02-14 11:53

The duplicate line command is included in Komodo 5, though it is not assigned a keybinding by default.

To assign it, go to your Komodo "Editor->Key Bindings" preferences and search for "duplicate", click on the "Editor: Duplicate Line" entry and then in the "New Key Sequence" field hit Ctrl-D, then click Add.

Cheers,
Todd

pawprint_net | Tue, 2009-10-27 09:20

YEAH!

It may sound silly but this is the one feature that has been holding me back from finally dropping Zend 5 (after their whole eclipse debacle I refused to upgrade) I have only been trying Komodo for about 2 days now but adding this in the mix I'm sold. Oh Soooo much better!

So cast my vote for adding this as a default command as described in the latest enhancement req for dup'ing the Line or Selection!

toddw
ActiveState Staff
Tue, 2009-10-27 09:34

The "duplicate line" command is already included in Komodo. Here's how to set it up:

  • Open the "Editor->Key Bindings" preferences
  • search for "duplicate" in the search texbox
  • click on the "Duplicate Line or Selection"
  • type "Ctrl+D" in the "New Key Sequence" textbox
  • click OK and you've got your duplicate command ready to go

Cheers,
Todd

janwen | Sun, 2011-01-23 20:28

i used ultraedit & eclipse,ctrl+d is the shortcuts for delete lines,but i do not find the similar function in the komodo editor,the following code is not for delete,is for copy & paste

// Macro recorded on: Mon Jan 24 2011 11:16:18 GMT+0800
komodo.assertMacroVersion(3);
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');

chemix | Mon, 2011-01-24 04:04

Hi

it's easy just go to Edit -> Preferences -> Editor -> Key Bindings

now find in input Commands: "delete" and you see "Editor: Delete Line" select this line and add New Key Sequence

chemiX // http://chemix.cz