shift-text.el provides commands to move the current line or active region
up or down, often referred to as “dragging” lines. It “Does What I Mean”
by automatically detecting whether to move a single line or the selected region.
- Move current line or active region up/down with
shift-text-upandshift-text-down - Automatically re-indents the moved text in supported major modes
(see
shift-text-indent-modes).
(add-to-list 'load-path "/path/to/shift-text.el")
(require 'shift-text)Bind the commands to your preferred keys, for example:
(global-set-key (kbd "M-<up>") #'shift-text-up)
(global-set-key (kbd "M-<down>") #'shift-text-down)You can also provide a prefix argument to move by multiple lines:
C-u 5 M-<up> will move the text 5 lines up.
emacs -batch -l ert -l shift-text-tests.el -f ert-run-tests-batch-and-exitGPL-3.0-or-later