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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. Removing Blank Lines in Eclipse

Removing Blank Lines in Eclipse

Erich Styger user avatar by
Erich Styger
·
Sep. 07, 12 · Interview
Like (1)
Save
Tweet
Share
33.63K 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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Best Practices for Writing Clean and Maintainable Code
  • Distributed Stateful Edge Platforms
  • The 31 Flavors of Data Lineage and Why Vanilla Doesn’t Cut It
  • Web Application Architecture: The Latest Guide

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: