Roel
Roel

Reputation: 19612

Eclipse - search and replace beginning of line

I want to add two spaces to the beginning of each line in my selection. Every sane editor I've ever used let me do this using the equivalent of s/^/ /g (that's two spaces but SE collapses it into one). In Eclipse (Kepler), I go to Edit->Find/Replace, type '^' into the 'Find:' box, ' ' in the "Replace with" box, select 'Selected lines' under 'Scope', and check the 'Regular expressions' check box. When I click 'Replace All', nothing happens, except that the Find/Replace dialog says 'String Not Found' at the bottom. What incantation do I have to use to please Eclipse in this case?

Upvotes: 1

Views: 3335

Answers (2)

Joe Elleson
Joe Elleson

Reputation: 1373

^ and $ are zero width anchors. You need to put some content with them. In this case you can capture a group and add spaces in front as follows:

Find: ^(.*)$ Replace: $1 (Two spaces followed by $1)

Upvotes: 2

Kent
Kent

Reputation: 195039

try:

find : ^.

replace: (two spaces)$0

Upvotes: 4

Related Questions