0

I want an emacs binding (in evil mode) to take the selection and move it over one space at a time to the right, or to the left. For example, highlight five line, hit [some-key] and all five lines slide one space to the right, and hit [shift some-key] and all lines slide one space to the left.

justingordon
  • 12,553
  • 12
  • 72
  • 116

1 Answers1

0

This might be a better approach than the one I had originally posted.

(defun jg-indent (start end count)
  (interactive "r\np")
  (save-excursion
    (let ((start (if (use-region-p)
                     start
                   (beginning-of-line)
                   (point)))
          (end (if (use-region-p)
                   end
                 (end-of-line)
                 (point))))
      (indent-rigidly start end count))))

(defun jg-unindent (start end)
  (interactive "r")
  (jg-indent start end -1))

(global-set-key "\C-c=" 'jg-indent)
(global-set-key "\C-c+" 'jg-unindent)
Eric Johnson
  • 696
  • 4
  • 23
  • I just stumbled into indent-rigidly which may be a better choice. Mine is bound to C-x C-i. – Eric Johnson Mar 28 '12 at 16:43
  • Eric, it's close, but I lose my region after the first hit. I want to be able to hit this multiple times, like binding ctrl-= to go right and ctrl-+ (ctrl shift =) to go left, for the region, and if there is no region, the current line should be used. – justingordon Mar 29 '12 at 03:52
  • I posted a better approach above. I was unable to bind it to the keys you wanted. There's something troublesome about those two keys. Sorry! – Eric Johnson Mar 29 '12 at 14:53