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 (although that version declares compatibility with Emacs 25.1 rather than

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

(defun move-text-internal (arg)
   ((and mark-active transient-mark-mode)
    (if (> (point) (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)
      (setq deactivate-mark nil)))
    (let ((column (current-column)))
      (when (or (> arg 0) (not (bobp)))
        (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.