Camsoft
Camsoft

Reputation: 12005

TextMate bundle to insert a line of text above each line selected?

I'm looking for a way to insert a line of text above each line in the selected text in TextMate.

Does anyone know how to write a command or snippet to do this?

Example, selected text:

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

I want to insert the following above each line selected:

--im an inserted line--

Which would result in the following:

-

-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

Could this be done using *NIX commands then I could setup a TextMate command to do this?

Upvotes: 2

Views: 1244

Answers (3)

sqwk
sqwk

Reputation: 1596

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.

Upvotes: 2

romainl
romainl

Reputation: 196596

I would record a macro:

  1. Insert a new line above with
  2. Paste desired text

Then save it as a command and possibly assign a shortcut to it.

EDIT

The best way to achive what you want in TextMate is to select all the lines then hit a (Text > Edit Each Line in Selection) then do all the keyboard mashing necessary to paste what you want where you want:

  1. to go back to the beginning of the line
  2. to insert a newline, effectively adding a blank line above the current line
  3. to jump to the new blank line
  4. v to paste your text

It will do that on each selected line simultaneously.

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.

Upvotes: 1

Lea Hayes
Lea Hayes

Reputation: 64206

To insert line above current line

I believe the key shortcut is: + +

Upvotes: 0

Related Questions