如何在Emacs中复制整行? [英] How do I duplicate a whole line in Emacs?

查看:264
本文介绍了如何在Emacs中复制整行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了 VIM的同样问题,我自己想知道如何做Emacs的东西。在ReSharper我使用CTRL-D这个动作。

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?

推荐答案

我使用

C-a C-SPACE C-n M-w C-y

分成


  • Ca :将光标移动到行首

  • C-SPACE :开始选择(设置标记)

  • Cn :将光标移动到下一行

  • Mw :复制区域

  • Cy :paste(yank)

  • C-a: move cursor to start of line
  • C-SPACE: begin a selection ("set mark")
  • C-n: move cursor to next line
  • M-w: copy region
  • C-y: paste ("yank")

C-a C-k C-k C-y C-y

等于同一事物(TMTOWTDI)

amounts to the same thing (TMTOWTDI)


  • Ca :将光标移至行首

  • Ck :cut(kill)该行

  • Ck :剪下换行符

  • yank)(我们回到正方形)

  • Cy :再次粘贴

  • C-a: move cursor to start of line
  • C-k: cut ("kill") the line
  • C-k: cut the newline
  • C-y: paste ("yank") (we're back at square one)
  • C-y: paste again (now we've got two copies of the line)

与编辑器中的 Cd 相比,这些都是尴尬的冗长,但在Emacs总是有一个定制。默认情况下 Cd 绑定到 delete-char ,所以 Cc Cd ?只需将以下内容添加到您的 .emacs

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的elisp版本可能是更好的,因为如果任何键绑定发生改变,它不会中断。)

(@Nathan's elisp version is probably preferable, because it won't break if any of the key bindings are changed.)

一些Emacs模式可以回收 Cc Cd 来执行其他操作。

Beware: some Emacs modes may reclaim C-c C-d to do something else.

这篇关于如何在Emacs中复制整行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆