6
votes

When pressing enter in Notepad++ to create a new line, is it possible to obtain the exact indentation of the previous line for the new line? No matter what I've tried, Notepad++ will always replace as many spaces as possible with tabs.

As an example, say I have the following (---> is a tab, . is a space, | is the cursor):

--->--->a_very_long_variable_name = another_long_name
--->--->..........................+ yet_another_variable|;

Lets say I want to add a third operand on a new line. After pressing Enter, I would expect the following:

--->--->a_very_long_variable_name = another_long_name
--->--->..........................+ yet_another_variable
--->--->..........................|;

Unfortunately, what Notepad++ actually produces is this:

--->--->a_very_long_variable_name = another_long_name
--->--->..........................+ yet_another_variable
--->--->--->--->--->--->--->--->..|;

Does anyone know of a setting or plugin that can be used to get an exact copy of the indentation, rather than replacing spaces by tabs?

It would also be nice if block indenting/unindenting would only affect the number of leading tabs, rather than again changing spaces to tabs.

2
Why do you want to mix spaces and tabs like that?ellak
@ellak We follow the principle that tabs are used for indentation, and spaces are used for alignment. This allows everyone to choose an indentation size they like, without running into misalignment issues when different people use different indentation sizes. The front two tabs are indentation, the spaces are alignment.zennehoy
Check this answer here, maybe it will help: stackoverflow.com/a/8197841/3437245user3437245

2 Answers

4
votes

I came across this question looking for something similar (working on multiple projects with different indentation styles), and thought I'd provide an answer for anyone else stumbling across this.

There's a nice plugin which makes Notepad++ keep indentation without doing any conversion, "TabIndentSpaceAlign": http://code.google.com/p/kereds-notepad-plus-plus-plugins/

Also available from the Notepad++ Plugin manager. Don't forget to enable the plugin after installing it! (see Plugins menu)

2
votes

I am not aware of any setting that would copy the exact indentation style (combination of tabs and spaces) from the previous line. You can chose to convert all tabs to spaces and the number of spaces per tab (tab stops) in the settings dialog but I think that's the limit of your options. It should be possible to develop a plugin to do this afterwards but I'm not aware of a plugin that does this currently.