Moving to the start of a code line: Emacs

后端 未结 5 1862
自闭症患者
自闭症患者 2021-01-31 15:18

I use emacs for development and very often need to move to the start of a line (C-a). However if the line is indented, I\'d like to move to the point at which code st

5条回答
  •  一个人的身影
    2021-01-31 15:47

    A favorite way for me to handle this is to have C-a toggle between the beginning of the line and the beginning of the code. You can do so with this function:

    (defun beginning-of-line-or-indentation ()
      "move to beginning of line, or indentation"
      (interactive)
      (if (bolp)
          (back-to-indentation)
        (beginning-of-line)))
    

    And add the appropriate binding to your favorite mode map:

    (eval-after-load "cc-mode" 
         '(define-key c-mode-base-map (kbd "C-a") 'beginning-of-line-or-indentation))
    

提交回复
热议问题