DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Debug Like a Pro in 2025: 10 New Eclipse Java Debugger Features to Enhance Your Productivity (With Spring Boot Examples)
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Trending

  • Why Your QA Engineer Should Be the Most Stubborn Person on the Team
  • How AI Is Rewriting Full-Stack Java Systems: Practical Patterns with Spring Boot, Kafka and WebSockets
  • The Cost of Knowing: When Observability Becomes the Outage
  • The 7 Pillars of Meeting Design: Transforming Expensive Conversations into Decision Assets
  1. DZone
  2. Coding
  3. Frameworks
  4. Removing Blank Lines in Eclipse

Removing Blank Lines in Eclipse

By 
Erich Styger user avatar
Erich Styger
·
Sep. 07, 12 · Interview
Likes (2)
Comment
Save
Tweet
Share
37.7K Views

Join the DZone community and get the full member experience.

Join For Free

many times i end up using source files from somebody else. and such files might have a lot of empty lines in it i want to get removed. the question is: how to get rid of empty or blank lines in the eclipse editor view? or even better: how to merge multiple empty lines into one?

shortcut: ctrl+d

deleting a line is easy: i place the cursor on a line and press ctrl+d (for line d elete). that works as well for multiple line selection. using the ‘ mother of all shortcuts ‘ reveals even more shortcut options:

delete commands

delete commands

this approach is fine, but manual. there must be something better.

search-and-replace: regular expression

and there is: to automatically remove empty lines, the search-and-replace functionality helps. for this i press ctrl-f (for find) and configure it like this:

regular expression to remove empty lines

regular expression to remove empty lines

the magic is using a regular expression checkbox. it uses the regular expression

^\s*\n

to find one or multiple empty lines and replaces it with ‘nothing’. that way i can clean up a full file and get rid of all empty lines.

if i do not remember the syntax of regular expressions any more, then there is help too: the dialog has content assist available:

content assist

content assist

so that way pressing ctrl+space helps a lot:

content assist help

content assist help

merging empty lines

with this in mind, it is easy to do something more advanced :-) : to merge multiple empty lines into a single one. again, a regular expression does the magic work:

merging multiple empty lines into a single one

merging multiple empty lines into a single one

with this, the regular expression

^\s*\n

finds one or multiple empty lines (as before), and it replaces it with a single empty line:

\r

now the sources need much less screen real estate :grin: .

happy removing:-)

Blank (solution) Eclipse Content assist

Published at DZone with permission of Erich Styger. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Debug Like a Pro in 2025: 10 New Eclipse Java Debugger Features to Enhance Your Productivity (With Spring Boot Examples)
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook