Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Format of css Stylesheets in Eclipse

Tags:

css

eclipse

So Eclipse can auto-format my css files under Source->Format, or by hitting Cntl-Shift-F.

When I group selectors for a single rule, eclipse formats it like this:

.planner th,.planner td {
    border: 1px solid black;
}

I would really like Eclipse to add a space between the selectors to aide readability, like this:

.planner th, .planner td {
    border: 1px solid black;
}

Is there any way I can configure Eclipse to do this? I'm running Eclipse Indigo.

like image 828
Tom Tresansky Avatar asked Jun 02 '12 18:06

Tom Tresansky


People also ask

Can we use CSS in eclipse?

Eclipse Web Developer Tools Includes the HTML, CSS, and JSON Editors, and JavaScript Development Tools from the Eclipse Web Tools Platform project, aimed at supporting client-side web development and node. js applications.

Where does eclipse keep CSS files?

It can reside in the same folder where your html/jsp page resides, or it can reside in any sub folder within that too. But accordingly to you have to specify the path. Deploy them in subdirectories under "[your-project]/WebContent". I usually name the subdirectories "js" and "css".


2 Answers

The Aptana Studio plugin for eclipse has a formatter that's pre-configured according to your needs.

I recommend using it regardless as it ease up the development process a great deal for web developers (all sorts of nifty features like built-in Git integration, code assist for common JavaScript libraries, integrated FTP client, embedded AJAX server [Jaxer], nice themes included, etcetera, etcetera...).

References:

  • Aptana Studio download page
like image 200
Eliran Malka Avatar answered Oct 05 '22 12:10

Eliran Malka


The easiest way to solve your problem would be to run a find/replace command like so.

  1. Open up File/Replace ( Ctrl+F) on the CSS file.
  2. Find: ,\.
  3. Replace: , \.
  4. Check the regular expressions box.
  5. Click Replace All.

Alternatively If your want can't be configure through the CSS editor (which seems to be so), then you're going to have to make a plugin for it.

CSS Editor is located here:

Preferences > Web > CSS Files > Editor

If you're considering making a plugin, then check out the package org.eclipse.jdt.core.formatter for help.

More information here:

  • Eclipse CSS Editor options
  • Eclipse Plugin Tutorial
like image 31
Larry Battle Avatar answered Oct 05 '22 10:10

Larry Battle