Reputation: 190859
I like the TextMate that can select a line to move it with a simple keystroke.
Command-shift L (select a line) Control-Command Arrow(up and down) (move the selected line)
How can I do the same thing with emacs?
Upvotes: 6
Views: 1030
Reputation: 3755
bbatsov's prelude (a kind of Emacs starter kit) includes this functionality (see this section of code):
(defun prelude-move-line-up ()
"Move the current line up."
(interactive)
(transpose-lines 1)
(forward-line -2)
(indent-according-to-mode))
and binds it to M-S-up and M-S-down.
Upvotes: 0
Reputation: 30258
SO user, Sanityinc developed move-text.el
(an extract of from basic-edit-toolkit.el - by emakswiki regular, Andy Stewart (lazycat))
See: Move line/region up and down in emacs
It does this task very nicely...
M-Up or M-Down to move the current line (or marked region's whole lines.)
I've added it to http://www.emacswiki.org/emacs/MoveText
Edit the bindings at the bottom to suit your preference.
Upvotes: 7
Reputation: 2850
The standard command C-x C-t is bound to transpose-lines
. This is useful for transporting lines via interchange in a few ways.
The most obvious is that exchanges the line the point is in with the previous line.
With an argument of 0 (i.e. M-0 C-x C-t), it swaps the line that has the mark in it with the line that has the point in it.
Upvotes: 4
Reputation: 4115
move-line does that, except for the highlighting, which should be reasonably easy to add.
Upvotes: 4
Reputation: 386010
I just delete the line, then yank it back in the new location. C-a C-k C-k (move to new location) C-y
Upvotes: 6