在Emacs中,一次编辑多行

我相信textmate有一个模式,如果你开始input,同样的事情将被input到你select的所有行。 在emacs中有类似的东西吗? 我猜有矩形可以帮助我的方式,但我不知道如何…

这很简单: Cx rt

你绝对需要尝试安装多个游标:

https://github.com/magnars/multiple-cursors.el

这是在果酱和梅尔帕只是:

 Mx包安装多个游标

其中一个解决scheme是使用CUA模式。 使用Mx cua-mode激活cua模式,select矩形begin:首先按下C-Enter然后用标准的移动命令移动光标以进行select,现在随时按下enter键将光标循环通过矩形的angular落,使您可以预先或附加文本到select。

您可以使用以下命令(和键)来完成此操作:

  • 开矩形(Cx,r,o)添加空格
  • 杀 – 矩形(Cx,r,k)删除
  • 清除矩形(Cx,r,c)用空格replace
  • Mxstring插入矩形填充指定的文本

以下是这些function的完整说明: http : //www.gnu.org/software/emacs/manual/html_node/emacs/Rectangles.html

对于那些想要为更复杂的场景做这些事情,并且想要在没有安装新模块的情况下进行操作,请继续阅读。 (这是Emacs可能没有安装MarkMultiple,虽然我个人使用和爱MarkMultiple)

我最近不得不OUTPUT一个SQL查询到一个文件,然后格式化成一个MYSQL INSERT查询。 这是Emacs如何让我的生活变得轻松….

文件看起来像:

 1 I am a random text 2 I am not 3 G, you've gone mad 4 Click on this link 5 Transfer in progress (we've started the transfer process) 6 But transfer happend yesterday 7 No you are 8 Oh please! this is getting too much! 9 I love emacs 10 I cant be bothered with this any more 11 its time to raise the bar 12 show me how to expand my territory 

我想让它看起来像:

 (1, ,'I am a random text'), (2, ,'I am not'), (3, ,'G, youve gone mad'), (4, ,'Click on this link'), (5, ,'Transfer in progress (weve started the transfer process)'), (6, ,'But transfer happend yesterday'), (7, ,'No you are'), (8, ,'Oh please! this is getting too much!'), (9, ,'I love emacs'), (10, ,'I cant be bothered with this any more'), (11, ,'its time to raise the bar'), (12, ,'show me how to expand my territory'), 
  1. 将光标放在第一行
  2. 按下Cx (开始录制macros[此时您的所有按键input都正在录制,请仔细按照说明进行操作]
  3. Ca键可以到行的开头
  4. 键入“(”后跟Mf前进一个单词,然后键入“,”
  5. Cn去下一行,接着Cx )结束这个macros
  6. Cu 11 Cx e重复macrosn(本例中为11)次

find了! 现在,如果你没有失败,你会得到这样的东西:

 (1, I am a random text (2, I am not (3, G, youve gone mad (4, Click on this link (5, Transfer in progress (weve started the transfer process) (6, But transfer happend yesterday (7, No you are (8, Oh please! this is getting too much! (9, I love emacs (10, I cant be bothered with this any more (11, its time to raise the bar (12, show me how to expand my territory 

在这一点上,我打算让你找出其余的。 但是,在我走之前,我想提一下,实现这种事情的方法有很多。 这只是其中一种方式,恰巧是我最喜欢的方式。

希望你发现它有帮助;)

矩形是为了简单的东西,像删除相邻行中相同数量的空间。

否则键盘macros是要走的路。

上面显示的答案是用于在列中插入文本。 无论每行的长度如何,TextMate的“在select中编辑每行”都会在每行中插入相同的文本。 我正在学习Lisp,所以作为一个练习,我写了一个函数来做到这一点:

 (defun append-to-lines (text-to-be-inserted) ;;Appends text to each line in region (interactive "sEnter text to append: ") (save-excursion (let (point-ln mark-ln initial-ln final-ln count) (barf-if-buffer-read-only) (setq point-ln (line-number-at-pos)) (exchange-point-and-mark) (setq mark-ln (line-number-at-pos)) (if (< point-ln mark-ln) (progn (setq initial-ln point-ln final-ln mark-ln) (exchange-point-and-mark)) (setq initial-ln mark-ln final-ln point-ln)) (setq count initial-ln) (while (<= count final-ln) (progn (move-end-of-line 1) (insert text-to-be-inserted) (next-line) (setq count (1+ count)))) (message "From line %d to line %d." initial-ln final-ln )))) 

首先进行包含所有要影响的行的select,然后使用Mx append-to-lines运行该函数。