Welcome, guest | Sign In | My Account | Store | Cart

This Komodo macro moves the line containing the caret (cursor) down one line, and then puts the caret at the start of that line in its new position. Put the macro in your toolbox, and bind it to Ctrl-Shift-DownpArrow (unused in the default Komodo keybinding set) to get the same functionality as in some other popular editors).

JavaScript, 23 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if (komodo.view && komodo.view.scintilla) { komodo.view.scintilla.focus(); }
var scimoz = ko.views.manager.currentView.scimoz;
var curr_line = scimoz.lineFromPosition(scimoz.currentPos);
var line_count = scimoz.lineCount;
if (curr_line == line_count - 1) {
    // At end of buffer
    return;
} else if (curr_line == line_count - 2) {
    var lastLinePos = scimoz.getLineEndPosition(line_count - 1);
    if (lastLinePos == scimoz.length) {
        alert("Last line in the buffer needs to end with a newline");
        return;
    }
}
scimoz.beginUndoAction();
try {
    scimoz.lineCut();
    scimoz.lineDown();
    scimoz.paste();
    scimoz.lineUp();
} finally {
    scimoz.endUndoAction();
}

This macro won't do anything when the caret is on the last line of a buffer. If the caret is on the second-last line, but the last line doesn't contain a newline, the macro also does nothing. I made this choice in order to make this macro the complete opposite of move-line-up. If I don't add a newline, the pasted line would be grafted to the last line. And if I did add a newline, then doing a move-line-up afterwards wouldn't completely undo the actions of move-line-down.

1 comment

Adam 10 years, 4 months ago  # | flag

Just a FYI to anyone looking here. This: http://community.activestate.com/forum/move-line-move-line-down-macros seems to be simpler and work better, has a macro for doing line or selection. Just need to change the komodo.assertMacroVersion(2); to: komodo.assertMacroVersion(3);