Tab replaces all leading spaces



  • After several years of use, this is the first time that this issue has occurred, in a free format text. Thanks for the recommended macro.



  • @dinkumoil

    Thank you for looking at this.
    I’ll examine them in detail, but from the short descriptions I think they operate under strict rules - I simply want that a Tab pressed be Tab, a space pressed be space in the text.

    @ PeterJones

    It is very unfortunate that Scintilla does not support the above-mentioned operation, the most simple Tab/Space handling , which is naturally supported by the Windows editors like Notepad, Pspad, Ultraedit, FCW editor,



  • @László-Botka

    there is a way to work around it, but it involves a scripting plugin.
    One would need to set tab indents attribute to false for each buffer which gets activated.
    I hope I understood your request correctly.



  • Hello, @lászló-botka, @peterjones, @alan-kilborn, @dinkumoil, @ekopalypse, and All,

    Have a look to the article, below :

    https://stackoverflow.com/questions/13973255/notepad-keeping-spaces-in-indent

    Answering to @ellak, the OP, @zennehoy, said something quite pertinent :

    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, [coming after], are alignment.


    Indenting problem is rather complex :

    • It depends on the key pressed ( Tab or Shift + Tab )

    • It depends on the position of cursor ( in the “indentation” part or in the “code” part )

    • It may depends of the character right before the cursor location ( a Tab character, a Space character or any other char )

    As for the indentation part of the next line, when hitting the Enter key :

    • It may be changed into a complete space characters area

    • It may be changed into a complete tab characters area, with additional space chars to respect the tabstops

    • It may fully copy the precedent indentation, without any modification


    I tested on N++ v7.6.3, both, the Elastic Tabstops and TabIndentSpaceAlign plugins. To install them :

    • Click on the Plugins > Open Plugins Folder.. option

    • Create a folder TabIndentSpaceAlign and/or a folder ElasticTabstops

    • Stop any Notepad++ instance

    • Place the downloaded dll files, inside its respective folder

    • Restart N++

    After some tests, it happened that the Elastic Tabstops is not suitable for your problem as it is rather used to align areas of text, in columns, separated with tabulation character(s), with elastic tabstops, which may be converted, later, in physical space characters

    Unfortunately, @ekopalypse, your Python work-around isn’t completely useful, too. Indeed, as soon as you hit the Enter key, the default N++ behavior occurs and changes most of the space characters to tabulation chars :-(

    So, @lászló-botka, I do think that the best, for you, would be to install the TabIndentSpaceAlign plugin ;-))


    Once the TabIndentSpaceAlign plugin enabled :

    • A hit on the Tab key, in the “indentation” part of a line :

      • Adds a Tabulation character, if the previous character was a Tabulation character ( of N space size )

      • Adds N space character(s) or less, if the previous characters was a space character

    • A hit on the Tab key, in the “code” part of a line :

      • Adds N space character(s) or less, in all cases ( Hold down the Alt key and hit , successively, on keys 0 and 9, of the numeric keypad, if you really want to insert a tabulation character )

    • A hit on the Shift + Tab key, in the indentation part of a line :

      • Remove the previous Tabulation character, right before the cursor location

      • Remove all the previous area of space character(s), right before the cursor location

    • A hit on the Shift + Tab key, in the code part of a line :

      • Simply move the cursor on the previous tabstop, whatever its location, without deleting* anything

    • A hit on the Enter key rewrites the exact indentation part of the current line in the next line

    Best Regards,

    guy038



  • Many thanks to everyone for their help

    @guy038

    The TabIndentSpaceAlign plugin works fine with Alt numpad 09 in the “code” part.
    But it’s complicate to press, and I’m sure I will sometimes press Tab and don’t notice when I write fast.

    I found the solution:
    If I use Ctrl V to Insert Tab (instead of pressing Tab), the result will be what I want: Tabs will be stored as Tab characters, Spaces will be stored as Space characters everywhere.

    [ To achieve this, I already have a hotkey defined with Ditto, an extension to the Windows Clipboard. I use it regularly, to insert a Tab character into the 'Find what" field, searching in Normal mode in the Ctrl+F “Find window”. ]



  • Thanks for the Alt numpad 09 tip, it can also be used in in my original issue, without any extra plugin.



  • …Alt numpad 09 tip…

    It may be worth pointing out that one can easily insert a tab character, without pressing Tab or using the numpad technique, from the ASCII Insertion Panel. Make that panel visible from the Edit menu by choosing Character Panel. Double-clicking any line in that panel inserts the clicked-on character. Useful for others besides tab obviously (although limited to “ASCII” characters).

    This panel is also a handy reference when you see “black boxed” characters in your (mostly text) file and you’re wanting to know their binary values (perhaps on your way to figuring out how/why they got into your file). You simply mentally note the text inside the black box and compare it to the Character column values on the panel…but let’s not go too far down this road as N++ is a text file editor, not a binary file editor.



  • @guy038

    your Python work-around isn’t completely useful, too. Indeed, as soon as you hit the Enter key, the default N++ behavior occurs and changes most of the space characters to tabulation chars :-(

    does not happen to me.
    If i hit enter the line stays as it was but if you refer to the next line, then yes,
    this might happen if you have autoindent enabled but this doesn’t make
    sense in this case, doesn’t it?



  • @Ekopalypse said:

    this might happen if you have autoindent enabled but this doesn’t make
    sense in this case,

    I’m going out on a limb to say that if one is coding, and autoindent is NOT turned on, N++ is too painful to use. :)



  • @Alan-Kilborn

    :-D, but if you like to insert spaces and tabs like YOU want, how should a program know this beforehand??



  • @Ekopalypse said:

    how should a program know this beforehand

    I’m not following this thread super-closely because in my now 3 decades of software development, the coding standard has been to never allow the use of actual tab characters in source files. But I would think it should replicate the indentation exactly of the line-above, but let the user then edit that and leave it the way the user changes it…but I am too dumb about it to continue talking… :)


Log in to reply