I'm familiar with and use very frequently the C-l
(recenter-top-bottom
) to
Move current line to window center, top, and bottom, successively.
I'd like to have an equivalent command to move the current column to window center, left and right borders, successively. Either built-in or a snippet of Elisp.
Here you go:
(defun my-horizontal-recenter ()
"make the point horizontally centered in the window"
(interactive)
(let ((mid (/ (window-width) 2))
(line-len (save-excursion (end-of-line) (current-column)))
(cur (current-column)))
(if (< mid cur)
(set-window-hscroll (selected-window)
(- cur mid)))))
And the obvious binding (from obvio171) is:
(global-set-key (kbd "C-S-l") 'my-horizontal-recenter)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With