I do a lot of python coding and am trying to determine if electric indent can be customized to help me with the following scenario:

Let's say my cursor (point) is at the end of the following excerpt, at the 'X':

if (some_condition):

If I hit RET, the cursor is moved to the next line immediately below the 'a'. Great. BUT... if all I want to do is insert a blank line, I will quickly move point somewhere else, and then some unwanted whitespace is left in the empty line:

if (some_condition):
.... # <-- unwanted whitespace left here

Binding RET to electric-indent-just-newline does not give me what I want, because that causes the cursor, in this scenario, to go to column 0.

I guess what I'm looking for is a clean way to:

  • Automatically move the cursor to the same level of indentation as the previous line if I hit RET, BUT
  • If the subsequent line just needs to be a newline / blank line, don't poop it up with whitespace.

Or do I need to resort to calling the function that deletes trailing whitespace?

Please let me know if I need to clarify the problem I'm trying to solve.

  • 1
    Try using C-o to add a newline after point and then move it somewhere else. – user12563 Jun 26 '18 at 20:56
  • @DoMiNeLa10 Awesome - this actually will get me what I need - I just need to develop the habit. Thanks! – Larold Jun 26 '18 at 21:33
  • In that case, I'll post it as an answer. – user12563 Jun 27 '18 at 15:53

You can add just a newline after point with open-line, which is bound to C-o by default, and it will work in pretty much every major mode out there. It might take a little bit before you get used to it, but it saved me a LOT of keystrokes and time because of how often I need to perform such an operation.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.