在emacs中如何从当前位置删除至行首?

13

Ctrlk可以删除光标当前位置到行末的所有内容。有没有相应的方法可以删除光标当前位置到行首的所有内容呢?

3个回答

15

对于我来说,Ctrl-0Ctrl-k可以达到您想要的效果。我认为这是默认配置,肯定不是我修改过的。

如果这不起作用,请尝试Ctrl-u0Ctrl-k。同样,这似乎是我的安装(Emacs 24.x,Mac OS X)中Emacs的默认行为。


对我来说不起作用... 嗯... 它只会从当前位置删除到行末(因为 C-k ,'前缀' C-0 似乎没有任何效果) - One Two Three
1
另外,M-0 C-k 我认为这是你指的第一个键绑定。M-arg 通常用作 C-u arg command 的速记。 - user797257
@wvxvw:不,我指的是我写的键绑定,在我的电脑上可以使用。请参见http://www.emacswiki.org/emacs/BackwardKillLine。 - High Performance Mark
嗯...有趣,没想到呢。 - user797257
我所需要的只是 C-u - Jake Ireland

1

如果您更喜欢较少的按键绑定(而不是单独使用删除行的按键,或者必须调用前缀参数),您可以使用crux-smart-kill-line,它将“杀死到行尾并在下一次调用时杀死整行”。但如果您更喜欢删除而不是杀死,则可以使用以下代码。

对于点到字符串操作(杀死/删除),我建议使用zop-to-char

(defun aza-delete-line ()
  "Delete from current position to end of line without pushing to `kill-ring'."
  (interactive)
  (delete-region (point) (line-end-position)))

(defun aza-delete-whole-line ()
  "Delete whole line without pushing to kill-ring."
  (interactive)
  (delete-region (line-beginning-position) (line-end-position)))

(defun crux-smart-delete-line ()
  "Kill to the end of the line and kill whole line on the next call."
  (interactive)
  (let ((orig-point (point)))
    (move-end-of-line 1)
    (if (= orig-point (point))
        (aza-delete-whole-line)
      (goto-char orig-point)
      (aza-delete-line))))

源代码


0

Emacs 学习曲线陡峭。当新用户遇到这个问题时,她应该记录一个由 2 个按键组成的宏:Shift+Ctrl+a 和 Ctrl-w(剪切),给它命名、保存并设置一个键绑定,以便在后续的 Emacs 会话中使用该宏。


重点是:学会记录宏并将其保存在您的.emacs.d中以备将来使用。 - Boris Stitnicky

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接