Home > Blockchain >  Can I restore previous IntelliJ IDEA "Delete to Word End" behavior to delete leading white
Can I restore previous IntelliJ IDEA "Delete to Word End" behavior to delete leading white

Time:09-02

Until somewhat recently, using the "Delete to Word End" functionality in IntelliJ IDEA (macOS keyboard shortcut: ⌥⌦) would delete through the end of the current line as well as any leading whitespace on the next line before the first word:

Line 1
   Line 2

=>

Line1Line2

This changed within the last year or two to keep the leading whitespace from the next line:

Line 1
   Line 2

=>

Line1   Line2

I much prefer the previous behavior. While cleaning up code for readability, I'll often pull code that is split across multiple lines onto one line using this functionality. What was previously one set of keystrokes is now two (I need to use the "Delete to Word End" key combination twice). What's worse, if the next line happens to not have leading whitespace, I have to override the muscle memory and only type the shortcut once, or else I'll delete part or all of the code on the following line.

As a minimalistic yet realistic example, I might use this behavior to do the following code transformation:

  List<String> myList = otherList.stream()
      .map(this::aMethod)
      .toList();

=>

  List<String> myList = otherList.stream()
      .map(this::aMethod).toList();

I don't know what version specifically the change occurred, but I have a version of IntelliJ IDEA from 2016 which has the old functionality, and one 2021 with the new functionality. I think the change happened in 2020 or 2021.

Is there a way to revert the behavior to the previous functionality (or perhaps an equivalent functionality under a different name)?

CodePudding user response:

While it's not exactly the same functionality, the Join Lines action (⌃⇧J on macOS) accomplishes the same goal in many cases. Regardless of where the caret is on the current line, it joins the current line to the next line, in context-sensitive ways.

For the given Java method call example, it has exactly the intended behavior of moving the method call to the current line without any spaces:

  List<String> myList = otherList.stream()
      .map(this::aMethod)
      .toList();

=>

  List<String> myList = otherList.stream()
      .map(this::aMethod).toList();

For a concatenated Java string split over the two lines, it will remove the string concatenation operator, combining the two strings into one:

System.out.println("A"  
    "B");

=>

System.out.println("AB");

In a plain text file, it will combine the lines, with a single space before the non-space text of the second line:

Line 1
   Line 2

=>

Line 1 Line 2
  • Related