Skip to content

gochev/vscode-java-indent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Smart Indent

A VS Code extension that replaces the built-in Java auto-indent with Eclipse JDT-style bracket-aware indentation.

The Problem

VS Code's built-in editor.autoIndent for Java copies the previous line's indentation level regardless of bracket context. This causes incorrect indentation when pressing Enter after lines like:

public void doSomething(String param,
                        int value) {  // ← cursor here, press Enter
    // VS Code puts you at the `int` column; Eclipse/this extension puts you here (inside the block)

What This Extension Does

Implements Eclipse JDT's JavaAutoIndentStrategy heuristics:

  • Enter after { → indent one level deeper
  • Enter after ; → stay at the same indent as the previous statement (sibling)
  • } on empty line → re-aligns to match the opening {'s indent
  • {|} expansion → when cursor is between { and }, Enter produces three lines with the caret in the middle
  • else/catch/finally → aligns with matching if/try
  • case/default → aligns with switch + one level

Setup

  1. Install the extension (.vsix file via Extensions: Install from VSIX…)
  2. Add to your settings.json:
"editor.autoIndent": "none",
"javaSmartIndent.enabled": true

Setting autoIndent to "none" prevents VS Code's built-in indentation from fighting with this extension.

Configuration

Setting Default Description
javaSmartIndent.enabled true Enable/disable the extension
javaSmartIndent.autoCloseBrace true Insert closing } when unclosed brace detected

Building from Source

npm install
npm run bundle
npm run package  # produces java-smart-indent-0.1.0.vsix

About

Fixing the vscode on enter indent that is broken based on Eclipse logic

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors