选择一行以使用emacs移动它

时间:2010-10-04 14:19:40

标签: emacs textmate

我喜欢TextMate,它可以选择一行来通过简单的按键移动它。

Command-shift L (select a line) 
Control-Command Arrow(up and down) (move the selected line)

我如何使用emacs做同样的事情?

5 个答案:

答案 0 :(得分:7)

SO用户,Sanityinc开发move-text.el(来自basic-edit-toolkit.el的摘录 - 由emakswiki常规,Andy Stewart(懒人))

请参阅:Move line/region up and down in emacs

它很好地完成了这项任务......

M-Up M-Down 移动当前行(或标记区域的整行。)

我已将其添加到http://www.emacswiki.org/emacs/MoveText

根据您的偏好编辑底部的绑定。

答案 1 :(得分:6)

我只是删除该行,然后将其拉回到新位置。 C-a C-k C-k(移动到新位置)C-y

答案 2 :(得分:4)

除了突出显示之外,

move-line会这样做,这应该相当容易添加。

答案 3 :(得分:4)

标准命令C-x C-t绑定到transpose-lines。这对于通过交换以几种方式运输线路非常有用。

最明显的是将该点与前一行交换。

如果参数为0(即M-0 C-x C-t),它会将带有标记的行与包含该点的行交换。

答案 4 :(得分:0)

bbatsov's prelude(一种Emacs入门套件)包含此功能(请参阅this section of code):

(defun prelude-move-line-up ()
  "Move the current line up."
  (interactive)
  (transpose-lines 1)
  (forward-line -2)
  (indent-according-to-mode))

并将其绑定到 M-S-up M-S-down