如何在Emacs中复制一行? [英] How do I duplicate a whole line in Emacs?
问题描述
我看到与VIM相同的问题,它一直是我自己想知道如何为Emacs做的事情。在ReSharper中,我使用CTRL-D进行此操作。在Emacs中执行此命令的次数最少是多少?
我使用
Ca C-SPACE Cn Mw Cy
分解为
-
Ca
:将光标移动到行开始 -
C-SPACE
:开始选择(set mark) -
Cn
:将光标移动到下一行 -
Mw
:copy region -
Cy
:paste(yank)
上述
Ca Ck Ck Cy Cy
相同的东西(TMTOWTDI)
-
Ca
:将光标移动到行开始 -
Ck
:cut(kill)行 -
Ck
:剪切换行 -
Cy
:paste yank)(我们回到正方形) -
Cy
:再次粘贴(现在我们已经与Cd
相比,这些都是令人尴尬的冗长的
$ b <在您的编辑器中,但是在Emacs中总是有一个定制化。默认情况下,
Cd
绑定到 delete-char
,所以 Cc Cd
?只需将以下内容添加到 .emacs
中: (全局设置-key\Cc\Cd\Ca\C- \Cn\Mw\Cy)
(@ Nathan的elisp版本可能更为可取,因为如果任何一个关键绑定被更改,它不会中断。)
小心:某些Emacs模式可能会收回 Cc Cd
来执行其他操作。
I saw this same question for VIM and it has been something that I myself wanted to know how to do for Emacs. In ReSharper I use CTRL-D for this action. What is the least number of commands to perform this in Emacs?
I use
C-a C-SPACE C-n M-w C-y
which breaks down to
C-a
: move cursor to start of lineC-SPACE
: begin a selection ("set mark")C-n
: move cursor to next lineM-w
: copy regionC-y
: paste ("yank")
The aforementioned
C-a C-k C-k C-y C-y
amounts to the same thing (TMTOWTDI)
C-a
: move cursor to start of lineC-k
: cut ("kill") the lineC-k
: cut the newlineC-y
: paste ("yank") (we're back at square one)C-y
: paste again (now we've got two copies of the line)
These are both embarrassingly verbose compared to C-d
in your editor, but in Emacs there's always a customization. C-d
is bound to delete-char
by default, so how about C-c C-d
? Just add the following to your .emacs
:
(global-set-key "\C-c\C-d" "\C-a\C- \C-n\M-w\C-y")
(@Nathan's elisp version is probably preferable, because it won't break if any of the key bindings are changed.)
Beware: some Emacs modes may reclaim C-c C-d
to do something else.
这篇关于如何在Emacs中复制一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!