我使用emacs进行开发,并且经常需要移动到行的开头(C-a).但是,如果该行缩进,我想移动到代码开始的位置.
所以在浏览代码时:( ) for x in xy|z:.打字时C-a我们得到这个:|( ) for x in xyz:.但相反,我想这样:( ) |for x in xyz:
这里| 表示cursor和()表示空格或制表符.
我怎样才能做到这一点?
Tre*_*son 31
我最喜欢处理这个问题的方法是C-a在行的开头和代码的开头之间切换.您可以使用此功能执行此操作:
(defun beginning-of-line-or-indentation ()
"move to beginning of line, or indentation"
(interactive)
(if (bolp)
(back-to-indentation)
(beginning-of-line)))
Run Code Online (Sandbox Code Playgroud)
并将适当的绑定添加到您喜欢的模式映射:
(eval-after-load "cc-mode"
'(define-key c-mode-base-map (kbd "C-a") 'beginning-of-line-or-indentation))
Run Code Online (Sandbox Code Playgroud)
ama*_*loy 18
我做同样的切换技巧,如Trey,但默认为缩进而不是开头.它需要稍多的代码,因为我知道没有"开始缩进"功能.
(defun smart-line-beginning ()
"Move point to the beginning of text on the current line; if that is already
the current position of point, then move it to the beginning of the line."
(interactive)
(let ((pt (point)))
(beginning-of-line-text)
(when (eq pt (point))
(beginning-of-line))))
Run Code Online (Sandbox Code Playgroud)
这可能会让你继续使用Ctrl- a并让它做你最想做的事情,同时仍然能够轻松获得内置行为.