coc-java icon indicating copy to clipboard operation
coc-java copied to clipboard

How to trigger code formatting? CTRL+F "format" in the entire docs and issues and can't figure out how still.

Open geoboom opened this issue 4 years ago • 1 comments

    "java.format.enabled": true,
    "java.format.onType.enabled": true,
    "java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml"

I have tried all permutations of the above yet can't get autoformatting to work on typing ;/}/<return> etc... Furthermore is it possible to trigger formatting behavior on save? It seems more intuitive that way like prettier plugin for js.

geoboom avatar Oct 28 '20 09:10 geoboom

The answer to the question can be found in :h coc-nvim as detailed under the quick start section of the home page for coc.nvim.

Simply add the following to your :CocConfig to format on save:

  "coc.preferences.formatOnSaveFiletypes": [
    "java"
  ]

kdormer avatar Nov 19 '20 13:11 kdormer

Should be fixed on recent version of coc-java, try upgrade coc.nvim to latest release and coc-java to version 1.14.0.

Make sure to use configuration "coc.preferences.formatOnType": true" to enable format on type with coc.nvim.

chemzqm avatar Jan 29 '23 09:01 chemzqm