MoveText

MoveText will move the current line (or if marked, the current region’s, whole lines.)

The default bindings are M-up-arrow and M-down-arrow. It works like Eclipse’s (same binding) and NetBeans M-S-up/down.

Download move-text.el here. A more up to date version is maintained at https://github.com/emacsfodder/move-text (although that version declares compatibility with Emacs 25.1 rather than 23.0.60.1).

This is a feature is extracted from basic-edit-toolkit.el

(defun move-text-internal (arg)
  (cond
   ((and mark-active transient-mark-mode)
    (if (> (point) (mark))
        (exchange-point-and-mark))
    (let ((column (current-column))
          (text (delete-and-extract-region (point) (mark))))
      (forward-line arg)
      (move-to-column column t)
      (set-mark (point))
      (insert text)
      (exchange-point-and-mark)
      (setq deactivate-mark nil)))
   (t
    (let ((column (current-column)))
      (beginning-of-line)
      (when (or (> arg 0) (not (bobp)))
        (forward-line)
        (when (or (< arg 0) (not (eobp)))
          (transpose-lines arg))
        (forward-line -1))
      (move-to-column column t)))))

(defun move-text-down (arg)
  "Move region (transient-mark-mode active) or current line
  arg lines down."
  (interactive "*p")
  (move-text-internal arg))

(defun move-text-up (arg)
  "Move region (transient-mark-mode active) or current line
  arg lines up."
  (interactive "*p")
  (move-text-internal (- arg)))

(provide 'move-text)


(global-set-key [M-up] 'move-text-up)
(global-set-key [M-down] 'move-text-down)

Also look at DragStuff

Also look at Shift-Text GitHub page which has also functions to move horizontally.


CategoryRegion