37

I find the autoindent style of Notepad++ a little weird: when I am typing on an indented line, I do want it to indent the next line after I press Enter (this it does properly). However, when I am on an empty line (no indentation, no characters) and I press Enter, it indents the next line, using the same indentation as the last non-empty line. I find this extremely annoying; have you ever encountered this problem and do you know how to fix it?

(Note: I'm editing HTML/PHP files.)

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Laurent
  • 5,953
  • 14
  • 43
  • 59

8 Answers8

27

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

Daniel Hári
  • 7,254
  • 5
  • 39
  • 54
  • Setting this plugin to "Smart Indent" worked well for me with PHP. – b01 Jan 27 '13 at 20:37
  • 10
    I had to go to Plugins > Plugin Manager > Show Plugin Manager, then install NppAutoIndent from the "Available" tab of that menu (The online download of the plugin wouldn't work). Once installed, go to Plugins > NppAutoIndent, then check "Ignore Language" and "Previous Line". – Qutorial Nov 24 '13 at 14:20
  • I'm getting the same indent but with tabs instead of spaces. This is infuriating with python. How can something so simple be done so badly. – jozxyqk Sep 07 '14 at 09:30
  • Ahhh, thank you. I had resorted to putting a 'pass' after every block in Python until I found this. – Grault Nov 05 '14 at 23:52
  • @Qutorial: Great point about having to "ignore language" in some cases; I took the liberty of adding that to the answer. – Amos M. Carpenter Apr 09 '15 at 05:03
  • 2
    this presumes that you have the NppAutoIndent plugin enabled ... Mine was not enabled, BUT I was still getting some auto-indenting ... which means that there exists some other feature within Npp that is also governing auto-indenting. – dsdsdsdsd May 18 '16 at 14:52
18

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.

3

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.

b01
  • 4,076
  • 2
  • 30
  • 30
2

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.

Community
  • 1
  • 1
1

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
user108570
  • 129
  • 1
  • 3
1

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.

Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
Steve Jessop
  • 273,490
  • 39
  • 460
  • 699
0

To be honest, this to me seems expected behaviour. Blank lines are used a lot by myself to break up the code to make it more readable, having the program make me have to tab out again would be VERY annoying.

I can understand this as a frustration with something like Python, but not with PHP... Though, before braces etc etc this might be annoying.

Try out Komodo Edit however, it's free, and I've found that it generally has been the best for auto-indenting for me. It seems to have learnt my coding style (or have the options in it for all coding styles and it picks up what you're using) and automatically indents everything correctly.

Edit: As you've noted in your reply, the issue is with "trailing whitespace" - I don't know Notepad++ too well, but most modern editors designed for coding have a "strip trailing whitespace on save" option (I know Komodo does!)

Mez
  • 24,430
  • 14
  • 71
  • 93
  • Is there a free (at least as in beer) version of komodo? on their site I can only find a "trial" version. – Laurent Sep 23 '08 at 02:16
  • Notepad++ comes with a trim macro, that can be used to make a trim-and-save macro, but it's kind of buggy. A warning: it took me some years to persuade my colleagues that if they leave trailing whitespace in their source, and I strip it out when I modify the file, that does not "pollute the diff"... – Steve Jessop Sep 23 '08 at 02:57
0

You can refer this setting and note the "tab size" . enter image description here