Search code examples
javamacosnano

auto-indent in nano not working while writing java files


I put set auto-indent in ~/.nanorc but auto-indent still not work. typing nano lol.java:

public class lol {
public static void main(String[] args) {
}
}

I'm on macOS.


Solution

  • nano is a very simple editor, and doesn't have language-specific syntax features. The autoindent setting (note, no hyphen) is described in the nano settings documentation:

    Automatically indent a newly created line to the same number of tabs and/or spaces as the previous line (or as the next line if the previous line is the beginning of a paragraph).

    So the indentation is only applied when the previous line is already indented. It does not add indentation based on blocks identified by curly braces in Java.