Textmate add multiline text at end of line

9

2

In Textmate, I am able to add text to several lines at once by clicking and holding the Option key and dragging with the mouse. say I have the following lines:

foo 1: 
foo 2:
foo 3:

I can easily click and hold option and then drag down with the lines to select the text at the end of each line, and then type "bar" once and it will be added to all lines, as such:

foo 1: bar
foo 2: bar
foo 3: bar

Fantastic.

The problem I run into, is when my lines aren't the same length, as such

foo 19: 
foo 37842342346: 
foo 503: 

Now if I want to add text to the end of each line, I have to either do it manually, or choose enough space so that the longest line is not overwritten, as such:

foo 19:          bar
foo 37842342346: bar 
foo 503:         bar

This results in a lot of unwanted whitespace in lines that don't need it. Granted, I could easily run a regular expression search to replace all multiple occurrences of a space with a single one, but I was wondering if there's a way to select all ending of lines at once without having to do that.

Any idea?

Thanks!

Yuval

Posted 2011-01-01T00:20:35.413

Reputation: 2 088

Answers

11

Select all the lines you want to edit then type + + a. You will be able to edit each line simultaneously.

The command is called "Edit Each Line in Selection" and can be found in the "Text" menu.

romainl

Posted 2011-01-01T00:20:35.413

Reputation: 19 227

perfect! that's exactly what I wanted. thank you so much! :) – Yuval – 2011-01-04T04:04:53.040

2

Nice!. But note that this is superseded for Textmate 2: See below, or also this youtube screen cast http://d.pr/9rBS

– tim – 2013-07-03T10:16:40.053

@tim: I'll believe you by default, I've stopped using TextMate a long time ago. – romainl – 2013-07-03T10:49:49.837

5

In textmate 2, make a vertical multiline selection (just ⇧-↓ to select multiple lines then ''tap'' the option key to make a vertical selection)

Now.. just move to the end of the line (⌘→) - boom! you can edit the end of each line!

Lorem ipsum dolor, ADDED THIS TO EACH !!
consectetur, ADDED THIS TO EACH !!
do eiusmod tempor incididunt, ADDED THIS TO EACH !!

See this screencast for more info http://d.pr/9rBS

tim

Posted 2011-01-01T00:20:35.413

Reputation: 329