2

我正在寻找一种在 TextMate 中所选文本的每一行上方插入一行文本的方法。

有谁知道如何编写命令或片段来做到这一点?

示例,选定的文本:

This is line 1
This is line 2
This is line 3
This is line 4

我想在所选的每一行上方插入以下内容:

--我是一个插入的行--

这将导致以下结果:

-

-im an inserted line--
This is line 1
--im an inserted line--
This is line 2
--im an inserted line--
This is line 3
--im an inserted line--
This is line 4

这可以使用 *NIX 命令完成,然后我可以设置一个 TextMate 命令来执行此操作吗?

4

3 回答 3

2

Select your text, press APPLE + F, then replace \n with \n--Im an inserted line--\n. Make sure that 'Regular expression' is ticked and that you hold in SHIFT while pressing the 'Replace All' button.

于 2011-07-29T13:11:47.520 回答
1

我会录制一个宏:

  1. 在上面插入一个新行⌥</kbd>⌘</kbd>↩</kbd>
  2. 粘贴所需的文本

然后将其保存为命令并可能为其分配快捷方式。

编辑

在 TextMate 中实现所需内容的最佳方法是选择所有行然后点击⌥</kbd>⌘</kbd>a (Text > Edit Each Line in Selection) then do all the keyboard mashing necessary to paste what you want where you want:

  1. ⌘</kbd>←</kbd> to go back to the beginning of the line
  2. ↩</kbd> to insert a newline, effectively adding a blank line above the current line
  3. ↑</kbd> to jump to the new blank line
  4. ⌘</kbd>v to paste your text

它将同时在每条选定的行上执行此操作。

You can save a few keystrokes the next time you have to do that by recording all these steps in a macro and save it as a command as in the first part of my answer.

于 2011-07-28T17:21:40.060 回答
0

在当前行上方插入行

我相信关键的捷径是:⌥</kbd> + ⌘</kbd> + ↩</kbd>

于 2011-07-28T14:49:24.727 回答