相当于vi的 dd 的emacs是什么?我想删除当前行。尝试 CTRL + k 但它只从当前位置删除。
答案 0 :(得分:199)
C-a # Go to beginning of line
C-k # Kill line from current point
还有
C-S-backspace # Ctrl-Shift-Backspace
调用M-x kill-whole-line
。
如果你想设置一个不同的全局键绑定,你可以把它放在〜/ .emacs中:
(global-set-key "\C-cd" 'kill-whole-line) # Sets `C-c d` to `M-x kill-whole-line`
如果要删除多个整行,可以在命令前加上一个数字:
C-u 5 C-S-backspace # deletes 5 whole lines
M-5 C-S-backspace # deletes 5 whole lines
C-u C-S-backspace # delete 4 whole lines. C-u without a number defaults to 4
C-u -5 C-S-backspace # deletes previous 5 whole lines
M--5 C-S-backspace # deletes previous 5 whole lines
有时我也会发现C-x z
有用:
C-S-backspace # delete 1 whole line
C-x z # repeat last command
z # repeat last command again.
# Press z as many times as you wish.
# Any other key acts normally, and ends the repeat command.
答案 1 :(得分:9)
如果您不想杀死该行(将其放入操作系统剪贴板并杀死响铃),只需删除它:
(defun delete-current-line ()
"Delete (not kill) the current line."
(interactive)
(save-excursion
(delete-region
(progn (forward-visible-line 0) (point))
(progn (forward-visible-line 1) (point)))))
答案 2 :(得分:1)
删除该行而不将其放入kill ring的另一种方法:
(defun delete-current-line ()
"Deletes the current line"
(interactive)
(delete-region
(line-beginning-position)
(line-end-position)))
这会将点留在空白行的开头。为了消除这种情况,您可能希望在函数的末尾添加(delete-blank-lines)
之类的内容,如本例所示,这可能会不太直观:
(defun delete-current-line ()
"Deletes the current line"
(interactive)
(forward-line 0)
(delete-char (- (line-end-position) (point)))
(delete-blank-lines))
答案 3 :(得分:0)
从任何点删除(终止)整行的最快/最简单的方法 在线,没有选择任何东西,是:
C-w ; kill-region
它可以删除任何选中的内容,或默认情况下的一行 如果没有选择任何东西。
考虑到这个问题,您可能也对复制感兴趣
Vim" yank",yy
(虽然在Emacs的说法中,#34; yank"令人困惑
Vim" put",p
)。这是:
M-w ; kill-ring-save
美好而且一致,而且很容易记住。甚至略微
类似于Vim' i_CTRL-W
。
一旦你用上述任何一种东西放入杀戮戒指中, 你可能想要"猛拉" (粘贴):
M-y ; yank-pop
(请注意,C-S-backspace可能无法在终端Emacs中使用。)
答案 4 :(得分:0)
不必使用单独的键来删除行,也不必调用
前缀参数。您可以使用crux-smart-kill-line
这将“杀死到该行的末尾,并在下一条杀死整个行
通话”。但是,如果您更喜欢delete
而不是kill
,则可以使用
下面的代码。
对于点对字符串操作(杀死/删除),我建议使用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))))
答案 5 :(得分:0)
安装包 whole-line-or-region
,然后运行 (whole-line-or-region-global-mode)
。如果没有区域(选择)处于活动状态,这将使 C-w
终止整个行。
查看包的 GitHub 页面 https://github.com/purcell/whole-line-or-region