2017-02-18 22:21:30 +08:00
---
title: "Use Vim as a Java IDE"
2018-05-27 20:54:33 +08:00
categories: [tutorials, blog]
2018-10-02 21:04:30 +08:00
excerpt: "A general guide for using SpaceVim as Java IDE, including layer configuration and requiems installation."
2017-02-18 22:28:49 +08:00
redirect_from: "/2017/02/11/use-vim-as-a-java-ide.html"
2017-12-28 23:46:56 +08:00
type: BlogPosting
2018-01-25 22:57:56 +08:00
comments: true
2018-07-05 16:16:34 +08:00
commentsID: "Use Vim as a Java IDE"
2017-02-18 22:21:30 +08:00
---
2018-10-02 21:04:30 +08:00
# [Blogs](../blog/) >> Use Vim as a Java IDE
2017-02-11 11:37:50 +08:00
2018-10-02 21:04:30 +08:00
This is a general guide for using SpaceVim as a Java IDE, including layer configuration and usage.
Each of the following sections will be covered:
2017-02-11 12:08:12 +08:00
2018-10-02 21:04:30 +08:00
<!-- vim - markdown - toc GFM -->
2017-02-11 12:08:12 +08:00
2018-10-02 21:04:30 +08:00
- [Installation ](#installation )
- [Code completion ](#code-completion )
- [Syntax lint ](#syntax-lint )
- [Import packages ](#import-packages )
- [Jump to test file ](#jump-to-test-file )
- [running code ](#running-code )
- [Code formatting ](#code-formatting )
- [REPL ](#repl )
2017-02-11 11:37:50 +08:00
2018-10-02 21:04:30 +08:00
<!-- vim - markdown - toc -->
## Installation
SpaceVim is a Vim and neovim configuration, so you need to install vim or neovim,
here are two guides for installing neovim and vim8 with `+python3` feature.
following the [quick start guide ](../quick-start-guide/ ) to install SpaceVim.
SpaceVim do not enable language layer by default, so you need to enable `lang#java` layer.
Press `SPC f v d` to open SpaceVim configuration file, and add following section:
2017-02-11 10:48:06 +08:00
2018-10-02 21:04:30 +08:00
```toml
[[layers]]
name = "lang#java"
```
2017-02-11 12:08:12 +08:00
2017-02-11 10:48:06 +08:00
## Code completion
2017-02-11 11:37:50 +08:00
2018-10-02 21:04:30 +08:00
javacomplete2 which has been included in `lang#java` layer provides omnifunc for java file and deoplete source.
with this plugin and `autocomplete` layer, the completion popup menu will be opened automatically。
2017-02-11 12:17:37 +08:00
2018-10-02 21:04:30 +08:00

2017-12-19 21:32:07 +08:00
2018-10-02 21:04:30 +08:00
## Syntax lint
2017-02-11 12:08:12 +08:00
2018-10-02 21:04:30 +08:00
`checkers` layer provides asynchronous linting feature, this layer use [neomake ](https://github.com/neomake/neomake ) by default.
neomake support maven, gradle and eclipse project. it will generate classpath automatically for these project.
2017-02-11 12:17:37 +08:00
2018-10-02 21:04:30 +08:00

2017-02-11 10:48:06 +08:00
2018-10-02 21:04:30 +08:00
within above picture, we can see the checkers layer provides following feature:
2017-02-11 12:08:12 +08:00
2018-10-02 21:04:30 +08:00
- list errors and warnings in quickfix windows
- sign error and warning position on the left side
- show numbers of errors and warnings on statusline
- show cursor error and warning information below current line
2017-02-11 12:08:12 +08:00
2018-10-02 21:04:30 +08:00
## Import packages
There are two kind features for importing packages, import packages automatically and manually. SpaceVim will import the packages after selecting the class name on popmenu.
2018-10-07 08:50:27 +08:00
Also, you can use key binding `<F4>` to import the class at the cursor point. If there are more than one class, a menu will be shown below current windows.
2018-10-02 21:04:30 +08:00

## Jump to test file
2017-02-11 10:48:06 +08:00
2018-10-02 21:04:30 +08:00
SpaceVim use vim-project to manager the files in a project, you can add a `.projections.json` to the root of your project with following content:
```json
{
"src/main/java/*.java": {"alternate": "src/test/java/{dirname}/Test{basename}.java"},
"src/test/java/**/Test*.java": {"alternate": "src/main/java/{}.java"}
}
```
with this configuration, you can jump between the source code and test file via command `:A`

## running code
Base on JavaUnite, you can use `SPC l r c` to run current function or use `SPC l r m` to run the main function of current Class.

## Code formatting
2019-01-14 15:42:17 +08:00
For formatting java code, you also nEed have [uncrustify ](https://github.com/uncrustify/uncrustify ) or [astyle ](http://astyle.sourceforge.net/ ) in your PATH.
2018-10-02 21:04:30 +08:00
BTW, the google's [java formatter ](https://github.com/google/google-java-format ) also works well with neoformat.
2017-02-11 12:17:37 +08:00
2018-10-02 21:04:30 +08:00

2017-02-11 10:48:06 +08:00
2017-12-19 21:32:07 +08:00
## REPL
2018-03-12 23:22:31 +08:00
you need to install jdk9 which provide a build-in tools `jshell` , and SpaceVim use the `jshell` as default inferior REPL process:
2017-02-11 10:48:06 +08:00
2017-12-19 21:32:07 +08:00
