Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad++: disable auto-indent after empty lines

People also ask

How do you get rid of multiple lines indentation?

If you're using IDLE, you can use Ctrl+] to indent and Ctrl+[ to unindent.


1) First install NppAutoIndent plugin if you don't have it.

Plugins > Plugin Manager > Show Plugin Manager, then install NppAutoIndent from the "Available" tab of that menu.

2) This behavior can be turned off by doing:

Plugins > NppAutoIndent > Previous line

3) If this option is disabled, you may need to first check this option:

Plugins > NppAutoIndent > Ignore language


I can confirm that this issue happens with Notepad++ version 5.0.3. The only related setting I have found is under Settings > Preferences > MISC > Auto-Indent, but that just turns all auto-indenting on or off.

I have used Editra (http://editra.org) in the past and was happy with it and it appears to handle indenting the way you are describing.


I found another way:

Use the macro "Trim Trailing and save" short-cut "Alt + Shift + S"

I you need this all the time, just swap the save short-cut with the macro "Trim Trailing and save" short-cut.

I only tend to use notepad++ when I'm programming so this works well for me.


It is unfortunate that Notepad++ doesn't trim the second empty new line automatically. But, as a work-around, I agree with user108570: a macro would be perfect.

I like to make a conceptual distinction between "soft" versus "hard" linefeeds, analogously to the two types of tabs. The output of the former depends on the current style and indentation settings. The output of the latter, however, should always be a simple, unadulterated, plain vanilla new-line.

The most frequently used flavour of linefeed should, of course, be mapped to the simpler key-combination. For most of your editing you would probably want to leave "soft linefeed" mapped to the "Enter" key and change "Ctrl+Enter" to trigger a "hard linefeed".

In "Menu -> Settings -> Shortcut Mapper -> Main Menu" you will see that by default "Ctrl+Enter" is mapped to "Word Completion". This needs to be disabled first by mapping it to "None".

Then simply record a macro:

  1. Menu -> Macro -> Start Recording
  2. Keyboard -> Enter
  3. Keyboard -> Tab
  4. Keyboard -> Shift + Home
  5. Keyboard -> Delete
  6. Menu -> Macro -> Stop Recording
  7. Menu -> Macro -> Save Current Recorded Macro

The last step will pop a dialog where you would name the macro (e.g. "Hard Linefeed") and set its mapping (i.e. "Ctrl+Enter").

At step 3 we could have added anything (printable). Its sole purpose is to add something to delete if there was nothing before, so that any text following the cursor will remain untouched.


Trim Trailing Space and Save is annoying. You'll notice that you are inserting few characters to documents unintentionally.

Instead record a macro and bind it to your ctrl + s.

Here is how to do it:

  1. Macro -> Start Recording
  2. Edit -> Trim Trailing Space
  3. File -> Save
  4. Macro -> Stop Recording
  5. Macro -> Save current recorded macro (Trim and Save)
  6. Settings->Shortcut Mapper
  7. Main Menu -> Save -> Ctrl + Alt + Shift + Save
  8. Macros-> Trim and Save -> Ctrl + S

What I do in Notepad++ is:

  • There's a "trim trailing spaces" macro in TexFX > TexFX Edit.
  • Use this to build a "trim and save" macro.
  • Bind that macro to CTRL+S, and bind 'Save' to something else.

I'd tell you how to record a macro that uses another macro, but it's years ago I did it and now I just copy the file around. I expect it Just Works, or possibly I did it by manually editing the shortcuts file. It looks like this (in shortcuts.xml):

<Macro name="Trim and save" Ctrl="no" Alt="yes" Shift="yes" Key="83">
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
    <Action type="0" message="2327" wParam="0" lParam="0" sParam="" />
    <Action type="0" message="2327" wParam="0" lParam="0" sParam="" />
    <Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
    <Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
</Macro>

Two warnings:

  • The trim macro is buggy. It only works if the cursor is at the end of a line when it's used. I occasionally think about trying to fix it or do my own, but can never be bothered because I reflexively work around it by moving the cursor myself before saving. The same workaround could just be built into your "trim and save" macro.

  • Some people get upset if you strip trailing whitespace out of "their" files - either because they like it, or because they sometimes use diff without ignoring whitespace (for instance in change reports) and don't want to see that you've changed half the file when really it was a one-liner. So for those files, just leave the trailing whitespace as it is and save with alt-f-s (or the 'something else' you moved save to) instead of ctrl-s. You probably need to set Notepad++ not to clear the undo buffer on save: otherwise a mistake here would be a bit of a disaster. But I set that anyway.