views:

5515

answers:

8

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.)

(Also, suggestions of other good free editors for HTML/PHP are welcome, in case there is no way of changing this behaviour.)

+1  A: 

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
Is there a free (at least as in beer) version of komodo? on their site I can only find a "trial" version.
Laurent
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
http://www.activestate.com/Products/komodo_ide/komodo_edit.mhtml
Mez
A: 

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.

Michael Paladino
A: 

@Martin: The problem is this leads to loads of trailing white space on all those empty lines, which seems dirty and a waste of memory.

Thanks for the pointer to Komodo.

Laurent
oh, and feel free to accept/upvote ;)
Mez
+1  A: 

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.

Steve Jessop
+4  A: 

this behavior can be turned off by doing :

Plugins > NppAutoIndent > Previous line

A: 

Laurent,

Regarding Komodo Edit, it is free. The full Komodo IDE, however, is not free but does have a trial version.

operknockity
A: 

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
A: 

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.

Dejan Budimir