Back to Spacevim

SpaceVim lang#java layer

docs/layers/lang/java.md

2.4.04.9 KB
Original Source

Available Layers >> lang#java

<!-- vim-markdown-toc GFM --> <!-- vim-markdown-toc -->

Description

This layer is for Java development.

Feature

  • code completion: autocomplete layer
  • code formatting: format layer
  • refactoring
  • syntax checking: checkers layer
  • REPL(requires jshell)
  • code runner
  • debug: check out the debug layer

Install

To use this configuration layer, update your custom configuration file with:

toml
[[layers]]
  name = "lang#java"

Layer options

  • format_on_save: Enable/disabled code formatting when saving current file. The default value is false. To enable this feature:
    toml
    [[layers]]
      name = 'lang#java'
      format_on_save = true
    
  • java_formatter_jar: Set the full path of google's formater jar.
    toml
    [[layers]]
      name = 'lang#java'
      java_formatter_jar = 'path/to/google-java-format.jar'
    
  • java_file_head: The default file header for new java file. by default it is:
    toml
    [[layers]]
      name = 'lang#java'
      java_file_head = [
        '/**',
        ' * @author : `fnamemodify(expand("~"), ":t")`',
        ' * @created : `strftime("%Y-%m-%d")`',
        '**/',
        ''
      ]
    

Key bindings

Import key bindings

Key BindingsDescriptions
SPC l IImport missing classes
SPC l RRemove unused classes
SPC l ismart import class under cursor
Ctrl-j I (Insert)Import missing classes
Ctrl-j R (Insert)Remove unused classes
Ctrl-j i (Insert)smart import class under cursor

Generate key bindings

ModeKey BindingsDescriptions
normalSPC l g Agenerate accessors
normal/visualSPC l g sgenerate setter accessor
normal/visualSPC l g ggenerate getter accessor
normal/visualSPC l g agenerate setter and getter accessor
normalSPC l g Mgenerate abstract methods
insertCtrl-j sgenerate setter accessor
insertCtrl-j ggenerate getter accessor
insertCtrl-j agenerate getter and setter accessor
normalSPC l g tgenerate toString function
normalSPC l g egenerate equals and hashcode function
normalSPC l g cgenerate constructor
normalSPC l g Cgenerate default constructor

Code formatting

The default formater of java language is google's formater jar. You need to download the jar and set the java_formatter_jar layer option.

The default key bindings for format current buffer is SPC b f. And this key binding is defined in format layer. You can also use g= to indent current buffer.

Maven support

Key BindingsDescriptions
SPC l m iRun maven clean install
SPC l m IRun maven install
SPC l m pRun one already goal from list
SPC l m rRun maven goals
SPC l m RRun one maven goal
SPC l m tRun maven test

Gradle support

Key BindingsDescriptions
SPC l a bgradle build
SPC l a Bgradle clean build
SPC l a rgradle run
SPC l a tgradle test

Code runner

Key bindingsDescriptions
SPC l r mrun main method of current file
SPC l r mrun the current method
SPC l r trun all test methods

Inferior REPL process

Start a jshell inferior REPL process with SPC l s i.

Send code to inferior process commands:

Key BindingsDescriptions
SPC l s bsend buffer and keep code buffer focused
SPC l s lsend line and keep code buffer focused
SPC l s ssend selection text and keep code buffer focused