I'm looking for the emacs equivalent of vi's ^
.
How can I move my cursor to the first non-whitespace character in a line?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityI'm looking for the emacs equivalent of vi's ^
.
How can I move my cursor to the first non-whitespace character in a line?
This is what I picked up from a previous Stack Overflow question:
(defun smart-beginning-of-line ()
"Move point to first non-whitespace character or beginning-of-line.
Move point to the first non-whitespace character on this line.
If point was already at that position, move point to beginning of line."
(interactive)
(let ((oldpos (point)))
(back-to-indentation)
(and (= oldpos (point))
(beginning-of-line))))
(global-set-key [home] 'smart-beginning-of-line)
(global-set-key "\C-a" 'smart-beginning-of-line)
M-m
is exactly the analog of ^
in vim and hence exactly the right answer.
Jun 27, 2019 at 3:16
You can install crux
type C-a
to switch cursor between beginning of line and the first non-whitespace character
^
in vim, which is exactly M-m
.
Jun 27, 2019 at 3:17