2

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?

Camsoft
  • 11,718
  • 19
  • 83
  • 120
  • Would love to know why this question has been flagged as off topic? My question was relating to TextMate bundle programming. – Camsoft Jul 28 '11 at 15:28

3 Answers3

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.

sqwk
  • 1,506
  • 2
  • 12
  • 13
1

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.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • I need this to insert the same line of text above every line on selected text. I have 1000's of lines selected and it would take too long to do manually. – Camsoft Jul 28 '11 at 21:51
  • To be honest, that's the kind of thing that made me move to Vim. – romainl Jul 29 '11 at 12:29
  • I'm a bit scared by Vim. I know TextMate can do it I'm just not sure how to make it do it! – Camsoft Jul 29 '11 at 12:43
  • 1
    See my edit, it will solve your problem. I was scared/attracted by Vim until I found myself with nothing to do for a week. I tried it seriously (`$ vimtutor`) and now I don't see myself going back to TextMate. – romainl Jul 29 '11 at 12:53
0

To insert line above current line

I believe the key shortcut is: + +

Lea Hayes
  • 62,536
  • 16
  • 62
  • 111
  • @Camsoft insert blank line above current line. – Lea Hayes Jul 28 '11 at 14:55
  • @Camsoft, scroll down a little and you'll see it here: http://projects.serenity.de/textmate/tutorials/basics/#commonbundleshortcuts – Lea Hayes Jul 28 '11 at 14:56
  • Sorry I don't think I was being clear. I was not trying to insert a blank line but needed a TextMate command or snippet to insert a line of text above each selected line. – Camsoft Jul 28 '11 at 15:01
  • @Camsoft in that case your probably going to need to create a bundle snippet. This isn't something that I've done before, but the following may help you: http://manual.macromates.com/en/snippets Looks like you'll need an understanding of objective-c to do this. – Lea Hayes Jul 28 '11 at 15:07
  • Yeah I was aware of that, that was why I asked the orignal question. ;-) Thanks anyway. – Camsoft Jul 28 '11 at 15:28