Prevent Code-Formatting in Eclipse by HotKey
eclipse, formatting, hotkeys, java, optimization
Solution
Yes, that is possible:
Create new template: `Windows->Preferences->Java->Editor->Templates->New` (screenshot)
Give a name to the template something like `non-formater` and put the Pattern:
// @formatter:off
${line_selection}${cursor}
// @formatter:on
Now, you can select the text and type Alt+Shift+Z and a number of the template - here 4
Problem
I knew one can prevent the code formatting in eclipse by surrounding the code with ``` // @formatter:off // my awesome formatted code... public Set<Person> transformCustomersToPersons(List<Customer> customers){ Set<Person> persons = new HashSet<Person>(); for (Customer customer : customers) { persons.add(new Person( customer.getFirstname(), customer.getLastname(), customer.getTitle(), customer.getBirthday(), customer.getAddress(0).getCity(), customer.getAddress(0).getStreet(), customer.getAddress(0).getHousenumber(), customer.isMan() ? "m" : "w", customer.getCardNumber()) ); } return persons; } // @formatter:on ``` But I don't want to write it manually all the time. It would be perfect just mark the code, press a hotkey and the code gets prevented from formatting. Anybody knows how? Thx!