I use evil-mode, but it doesn't support zs and ze shortcuts from Vim (scrolling horizontally to cursor position).
How can i map these keys to achieve the same behavior in Emacs?
Some explanation of what zs
/ze
do:
Let's assume i have a file with lines containing 500 chars and the line wrapping is turned off. My text editor window is 81 columns long, so i don't see all the chars in the lines, but i want to see them only from 100'th char (column) as far to the right as i can (the chars before 100'th do not interest me).
I move my cursor to 100'th char, which now is around center of the screen. When i press zs
now, the 100'th column becomes the first visible column on the screen so i can see characters from 100 to 180 in my text editor window.
When i press ze
now the current column (100'th) becomes the last visible column, so i can see the characters from 20 to 100'th.
Quote from Vim manual:
*zs* Scroll the text horizontally to position the cursor at the start (left side) of the screen. This only works when 'wrap' is off. {not in Vi} *ze* Scroll the text horizontally to position the cursor at the end (right side) of the screen. This only works when 'wrap' is off. {not in Vi}
Solution
What worked for me, thanks to /u/gilles:
(defun hscroll-cursor-left ()
(interactive "@")
(set-window-hscroll (selected-window) (current-column)))
(defun hscroll-cursor-right ()
(interactive "@")
(set-window-hscroll (selected-window) (- (current-column) (window-width) -1)))
(define-key evil-normal-state-map "zs" 'hscroll-cursor-left)
(define-key evil-normal-state-map "ze" 'hscroll-cursor-right)
(setq auto-hscroll-mode 't)
(setq hscroll-margin 0
hscroll-step 1)
zs
andze
and provided my own explanation