When saving a java source file that resides in a project, eclim will update that source file in Eclipse and will report any validation errors found. Any errors will be placed in the current window’s location list (:help location-list) and the corresponding lines in the source file will be marked via Vim’s :sign functionality with ‘>>’ markers in the left margin.
Automatic validation of java source files can be disabled via the g:EclimJavaValidate variable (described below). If you choose to disable automatic validation, you can still use the :Validate command to manually validate the current file.
g:EclimJavaValidate (Default: 1) - If set to 0, disables source code validation.
Note
When enabled, syntastic is disabled so that eclim and syntastic don’t step on each other. If you’d like to use syntastic over eclim for validation, then simply disable eclim’s validation.
If you’d like to disable eclim’s source code validation for all languages, eclim provides a global variable for that as well:
let g:EclimFileTypeValidate = 0
g:EclimValidateSortResults (Default: ‘occurrence’) - If set to ‘severity’, the validation results will be sorted by severity (errors > warnings > info > etc.)
Eclim settings
Code correction in eclim is equivalent to the quick fix functionality of Eclipse. When you save a java source file, eclim validates the file and notes which lines contain errors. To have eclim suggest possible corrections for an error, you simply place the cursor on the error line and issue :JavaCorrect.
The result will be a small window opened at the bottom of Vim where any correction proposals will be noted. To apply a suggested change, simply move the cursor to the line describing the modification and hit <enter>. Upon doing so, the change will be applied to the source file.
Example output of :JavaCorrect.
The serializable class Foo does not declare a static final serialVersionUID field of type long
0.1227: Add @SuppressWarnings 'serial' to 'Foo'
...
@SuppressWarnings("serial")
public class Foo
implements Serializable
...
To apply the above change you would hit <enter> on the line:
0.1227: Add @SuppressWarnings 'serial' to 'Foo'
Note
Java code corrections are handled just like a refactoring so the RefactorUndo and RefactorRedo commands can be used to undo/redo corrections that can’t be handled by vim’s undo (like file moves).
When editing a java source file, eclim provides the command :Checkstyle which will invoke checkstyle on the current file.
Additionally, you can configure eclim to execute checkstyle automatically when you save a java source file by setting the eclim project settings org.eclim.java.checkstyle.onvalidate to true.
Please note that both methods of invoking checkstyle require that you first configure the location of your checkstyle config file using the eclim setting org.eclim.java.checkstyle.config, described in the configuration section below.