71

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?

Pops
  • 8,623

4 Answers4

111

The command is back-to-indentation, bound by default to M-m.

Sean
  • 1,854
16

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)
George
  • 426
2

You can install crux

type C-a to switch cursor between beginning of line and the first non-whitespace character

1

Depending on the mode you are using, for example on JS or TS mode you can use the TAB key, as if you were indenting a single line.