Community
    • Login

    8.7 How to set tab width -- NOT indent?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 5 Posters 1.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Frank PeeloF
      Frank Peelo
      last edited by

      In Notepad++ 8.7, how do I set how the tab character is displayed?

      There’s indentation, but I’m not asking about indentation. Tab and indentation are very different. Indentation is what happens before the first visible character, and I never want a tab there, I want 2 or 4 spaces depending on whether it’s C or Python, and that works fine.

      But a tab character can also happen, often after the first displayed character, and it should be every 8 characters (or whatever I would set in preferences) and NOT replaced by spaces. That used to work, but I can’t see how to set it in 8.7.

      Alan KilbornA mkupperM CoisesC 3 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Frank Peelo
        last edited by

        @Frank-Peelo

        The notions of “indentation” and “tab” are bound up together. It has always been this way in Notepad++.

        There have been users that have requested “tab-indent-space-align”, but I don’t recall anyone asking for the opposite, which is kind-of what you seem to be wanting.

        Anyway, there’s no reasonably easy way to achieve what you want.

        1 Reply Last reply Reply Quote 1
        • mkupperM
          mkupper @Frank Peelo
          last edited by

          @Frank-Peelo, while Notepad++'s settings panel that configures how tabs are handled and displayed is called “Indent Settings” the same settings panel also controls what happens when tabs are used to align data. I suspect the settings panel should be called something like Tab handling and display as tabs are used for more than just indenting.

          Prior to Notepad++ v8.7 the “Indent Settings” panel was on the Languages section of the settings. Starting with v8.7 the “Indent Settings” panel was moved to a new settings section called Indentation. It’s the same panel as before. The available settings and Notepad++'s behavior has not changed.

          The “Indent Settings” panel has a set of default tab related settings. You can override those defaults for each language such as C, Python, etc.

          I would experiment with the tab settings, either for a specific language, or the defaults to see if you can get Notepad++ do to what you desire.

          1 Reply Last reply Reply Quote 0
          • CoisesC
            Coises @Frank Peelo
            last edited by

            @Frank-Peelo said in 8.7 How to set tab width -- NOT indent?:

            Indentation is what happens before the first visible character, and I never want a tab there, I want 2 or 4 spaces depending on whether it’s C or Python, and that works fine.

            But a tab character can also happen, often after the first displayed character, and it should be every 8 characters (or whatever I would set in preferences) and NOT replaced by spaces. That used to work, but I can’t see how to set it in 8.7.

            My solution to this is to set:
            Settings | Preferences… | Indentation | Indent Settings | Indent using:
            to: Space character(s)
            but also go to Settings | Shortcut Mapper | Scintilla commands: SCI_TAB
            and remove the Tab key as a shortcut.

            Space character(s) ensures that when Notepad++ (actually, the underlying Scintilla control) generates indentation, it will always be made up of spaces only. Removing the SCI_TAB shortcut ensures that the Tab key will always generate a tab character; it will never be converted to spaces.

            Aside from the location of the Preferences setting, though, I don’t think this has changed recently.

            Alan KilbornA 1 Reply Last reply Reply Quote 2
            • Alan KilbornA
              Alan Kilborn @Coises
              last edited by

              @Coises

              But doesn’t that mean that if you are, say, coding in Python with 4 space indentation, you’d have to press the space bar four times each time you want to increase the indent level of a line of code? I’d go insane…

              But in reality, with Python recently getting smart-indent in Notepad++, as well as the newly-add “backspace unindents” feature (gee, both of those were added to Notepad++ by me!), maybe deassigning the Tab key from its default functionality wouldn’t make one go mad after all.

              One would still need a new keycombo assignment for the Edit > Indent > … stuff (but I’m done experimenting with this, as something I’d never need).


              My overall feeling is that tab characters, as formatting for source code at least, are and always have been a poor design choice. After a 32 year career where tab characters were always banned from source code by company coding standards (but sometimes crept into code by poor tool enforcement of this policy), I’m certainly not alone in how I feel. …But, to each his own.

              CoisesC 1 Reply Last reply Reply Quote 1
              • CoisesC
                Coises @Alan Kilborn
                last edited by

                @Alan-Kilborn said in 8.7 How to set tab width -- NOT indent?:

                But doesn’t that mean that if you are, say, coding in Python with 4 space indentation, you’d have to press the space bar four times each time you want to increase the indent level of a line of code?

                Yes. Unfortunately, there is no “tab key enters a tab character except when I don’t want that” setting.

                I still toy with the idea of writing plugin code (either a new plugin or an option in Columns++) to make tab and indent handling more intelligent… but there are so many permutations of what people could want that I fear in the end I’d struggle and struggle with it only to conclude that what everyone really wants is a setting that makes Notepad++ read their minds.

                1 Reply Last reply Reply Quote 5
                • guy038G
                  guy038
                  last edited by guy038

                  Hello, @frank-peelo, @alan-kilborn, @mkupper, @coises and All,

                  Of course, as @alan-kilborn said :

                  The notions of “indentation” and “tab” are bound up together. It has always been this way in Notepad++

                  However, @frank-peelo, I’d like to show you a way to simulate what you’re trying to achieve !


                  • Firstly, in Settings > Preferences... > Indentation, set [Default] of the Indent Settings to value 8, select below the Space character(s) option and check the Backspace key unindents instead of removing single space option

                  • Secondly, create a new macro to type in a tabulation char, anywhere, each time you’ll press the Alt + T shortcut

                          <Macro name="Insertion 1 TABULATION" Ctrl="no" Alt="yes" Shift="no" Key="84">
                              <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x0009;" />
                          </Macro>
                  
                  • Thirdly, create an other macro to reduce the leading indentation by two, each time you’ll press the Alt + I shortcut
                          <Macro name="Indentation divided by 2" Ctrl="no" Alt="yes" Shift="no" Key="73">
                              <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                              <Action type="3" message="1601" wParam="0" lParam="0" sParam="^(\x20+)\1" />
                              <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                              <Action type="3" message="1602" wParam="0" lParam="0" sParam="$1" />
                              <Action type="3" message="1702" wParam="0" lParam="640" sParam="" />
                              <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                          </Macro>
                  

                  Now, let’s imagine you’re working on a Python script. Of course, each time you hit the TAB key, eight space characters are inserted

                  But, after some non-blank characters, you’ll be able, at any location, to insert a true TAB of eight chars, in current line, using the ALT + T shortcut of the macro.

                  #00000000111111111222222222233333333334444444444555555555566666666667777777777
                  #23456789012345678901234567890123456789012345678901234567890123456789012345678
                  # This is	an   example	to see	how it works	
                          # This is	an   example	to see	how it works	
                                  # This is	an   example	to see	how it works	
                  ...
                  
                  • Click on the View > Show Symbol > Show All Characters option to easily see the tabulations

                  As you can verify, each Tab character always ends, as expected, at position 8 × k, whatever the value of the integer k

                  At any moment, if you want to get the true indentation of your Python script :

                  • Select ALL the part of text, not already modified

                  • Press the Alt + I shortcut, once only

                  Thus, the above example becomes :

                  #00000000111111111222222222233333333334444444444555555555566666666667777777777
                  #23456789012345678901234567890123456789012345678901234567890123456789012345678
                  # This is	an   example	to see	how it works	
                      # This is	an   example	to see	how it works	
                          # This is	an   example	to see	how it works	
                  ...
                  

                  And, indeed, the leading indentation is, now, always equal to 4 × n, whatever the value of the integer n

                  However, the inserted tabulations remain tabs every 8 chars !


                  If we suppose that, instead, you’re working on a C-like program. Again, each time you’ll hit the TAB key, eight space characters will be inserted

                  But, after some non-blank characters, you’ll be able, at any location, to insert a true TAB of eight chars, in current line, using the ALT + T shortcut of the macro.

                  //0000000111111111222222222233333333334444444444555555555566666666667777777777
                  //3456789012345678901234567890123456789012345678901234567890123456789012345678
                  // This is	an   example	to see	how it works	
                          // This is	an   example	to see	how it works	
                                  // This is	an   example	to see	how it works	
                  ...
                  

                  Again, each Tab character always ends, as expected, at position 8 × k, whatever the value of the integer k

                  At any moment, if you want to get the true indentation of your C-like program :

                  • Select ALL the part of text, not already modified

                  • Press the Alt + I shortcut twice ( So Alt + I, Alt + I )

                  Then , the above example becomes :

                  //0000000111111111222222222233333333334444444444555555555566666666667777777777
                  //3456789012345678901234567890123456789012345678901234567890123456789012345678
                  // This is	an   example	to see	how it works	
                    // This is	an   example	to see	how it works	
                      // This is	an   example	to see	how it works	
                  ...
                  

                  And, indeed, the leading indentation is, now, always equal to 2 × n, whatever the value of the integer n

                  However, the inserted tabulations remain tabs every 8 chars !


                  To summarize, it’s rather a tricky work-around. However, it’s a semi-automatic way to get, at the same time :

                  • The correct leading indentation for your C-like programs and Python scripts

                  • The correct insertion of a true TAB character of eight characters size, at any position, after the leading indentation

                  That you expect to ! Just experiment ;-))

                  Best Regards,

                  guy038

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors