• Login
Community
  • Login

How do I align/indent text to an inside column (using SHIFT-CTRL-ALT+ Left Click)

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
33 Posts 10 Posters 14.2k 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.
  • C
    Chris Tanguay 0
    last edited by Aug 6, 2021, 4:50 PM

    Hi, all! Please take a look at this example.
    column.jpg
    So, I’m using (SHIFT-CTRL-ALT + Left Click) to set this inside column (temporary column blinking cursor from top to bottom).
    How can I indent (aka backspace) all the text on each row, to the right of the blinking column, so it left aligns to this inside column I’ve selected. Is there a way to do this within NP++ itself, or do I need a plugin? I’ve been fiddling with Column Tools plugin, but no luck so far.
    I have a feeling I’m missing something obvious.
    Thanks in advance!

    A 1 Reply Last reply Aug 6, 2021, 8:27 PM Reply Quote 0
    • A
      artie-finkelstein
      last edited by Aug 6, 2021, 5:33 PM

      I’d probably:

      • use \Edit\Column Editor… to insert row numbers into the document at the left most edge
      • use the NppColumnSort plugin to sort on the USER ID column
      • use regular column mode editing to remove the leading space(s) from the IDs
      • resort the file based on the index numbers added to the left most edge
      • use regular column mode editing to remove the leading index numbers
      • yell at the original programmer for not sanitizing the data before storing it <grin>

      NppColumnSort is not in the Plugin Manager and is available as separate 32 bit or 64 bit releases. The plugin uses an intermediate ‘template’ to select the sorting column(s); this allows for multiple levels of sorting, but an entry must be made into the template area, even for a single level of sorting.

      1 Reply Last reply Reply Quote 3
      • A
        astrosofista @Chris Tanguay 0
        last edited by astrosofista Aug 6, 2021, 8:28 PM Aug 6, 2021, 8:27 PM

        @Chris-Tanguay-0, @artie-finkelstein,

        I would do it as follows:

        Giphy

        How it works? First off, open Preferences -> Editing, and enable the Multi-Editing Settings. It also requires the BetterMultiSelection plugin activated, which you can download and install via Plugins Admin.

        Then, do as the movie shows:

        1. In the second line, place the caret at the left of the USER ID column.

        2. Press Shift + Alt and move the caret from the top line until the bottom of the list with the arrow down — you will get a giant caret blinking along 14 lines with no characters selected.

        3. Press Shift + End to select till the end of each line.

        4. Then press Shift + Control + Arrow Left to just select the spaces you want to delete.

        5. Lastly, press delete.

        You’re done. Hope you like it.

        A M 2 Replies Last reply Aug 6, 2021, 10:42 PM Reply Quote 4
        • A
          artie-finkelstein @astrosofista
          last edited by Aug 6, 2021, 10:42 PM

          @astrosofista

          I like the simplicity of this approach. Much nicer than my brute force scheme. Please note that success seems to be a bit dependent on the format/content of the data being lined up.

          I tried using a random sample of data, but I kept getting side effects on the last one or two entries, such as removal of the EOL on the second to last line, thus joining the last two lines. Eventually, I tracked the anomalous behavior to having a comma at the end of any row. No comma suffixes, no problems.

          FYI: The random sample was a comma separated list turned into columnar data with two of the entries given an additional indent to offset the column.

          	.REG, .VBS, .CPP, .VB, .CS, .CSS, .BAT, .CMD
          

          I doubt the tab before .REG makes it through the board software, but it has no effect on the outcome (although it does limit setting the initial multi-column selection).

          The reason for this long winded answer: I really, really like the approach, but the side effect with the commas is worrisome to me. You appear to have used BetterMultiSelection for much more radical cases of text editing than I have, so is this an issue with BetterMultiSelection, a limitation of ‘Multi-Editing’ or do I have an unexpected interaction with editor preferences other than the required enabling of the ‘Multi-Editing’?

          I’m using Win7 Pro x64, Npp 8.13rc 32 bit, however, neither removing all plugins other than BetterMultiSelection nor reverting to the Npp 8.11 .exe had any effect on the incorrect behavior.

          Thank you for any insight you may offer.

          A 1 Reply Last reply Aug 7, 2021, 5:09 AM Reply Quote 0
          • G
            guy038
            last edited by guy038 Aug 6, 2021, 11:21 PM Aug 6, 2021, 11:20 PM

            Hello, @Chris-Tanguay-0 and All,

            If your file contains space chars only, a third solution is use a regex S/R. To align a field, right after the column N, use the generic regex, below :

            (?-s)^.{N}\K\x20+

            So, as you want to align the second field, right under the U letter of USER_ID header, => N = 8. Thus, the practical regex is :

            SEARCH (?-s)^.{8}\K\x20+

            REPLACE Leave EMPTY

            Of course, you must select the Regular expression search mode, tick the Wrap around option and click once on the Replace All ( Do not use the Replace button ! )

            Best Regards,

            guy038

            1 Reply Last reply Reply Quote 1
            • A
              astrosofista @artie-finkelstein
              last edited by Aug 7, 2021, 5:09 AM

              @artie-finkelstein

              I’m not sure if I understood the example, maybe a more detailed presentation, or a video, could help me to understand the problem and eventually offer you some kind of solution.

              One preference that can affect multi-editing is Preferences -> Delimiter, so check if there are any characters added to the word delimiter.

              That’s all I can think of for now.

              A 1 Reply Last reply Aug 7, 2021, 4:24 PM Reply Quote 0
              • A
                artie-finkelstein @astrosofista
                last edited by Aug 7, 2021, 4:24 PM

                @astrosofista
                Thank you. I’m using the ‘default Word character list as it is’ setting, but that was the clue.

                I discovered that the problem only shows up if a word boundary character (i.e., non-alphanumeric and not an underscore) is present in the desired column in the Shift-End ‘expanded’ selection area. If I use a series of Ctrl-Shift-right key presses to expand the selection area to the end of column of interest AND NO FURTHER and then use a series of Ctrl-Shift-left key presses to change the selection to only the ‘undesired’ white space, it works as desired. It does not matter where the word boundary character is in the column of interest, that somehow forces a misalignment. The same misalignment occurs if there is an embedded space in the column of interest.

                Given these ‘gottchas’, I’ll stick with my brute force approach after all, as it is content insensitive. I do note that your approach is fully applicable to the OPs question as presented.

                Again, thank you for providing the key insight.

                A 1 Reply Last reply Aug 8, 2021, 12:37 AM Reply Quote 2
                • A
                  astrosofista @artie-finkelstein
                  last edited by Aug 8, 2021, 12:37 AM

                  @artie-finkelstein

                  You’re welcome. In case the column to be aligned has blank spaces, commas at the end of the line, or any other non-alphanumeric character, you can proceed in this other way:

                  Giphy

                  As we did before, make a multi-selection at the left of the USER ID column. Then

                  1. Type in a space and step back pressing the Arrow Left.

                  2. Press Shift + Control + Arrow Right to just select the spaces and the first words.

                  3. Press Shift + Control + Arrow Left to deselect words and to select spaces.

                  4. Press delete to align the USER ID column.

                  That’s all.

                  A G A 3 Replies Last reply Aug 8, 2021, 3:51 PM Reply Quote 4
                  • A
                    artie-finkelstein @astrosofista
                    last edited by Aug 8, 2021, 3:51 PM

                    @astrosofista
                    Cool. Thanks for the tip.

                    It’s a shame such a powerful plugin does not have any published documentation for it’s “advanced” features. Your mini-tutorials are quite helpful, but unfortunately, I haven’t been able to discern the underlying logic to assist me in creating new solutions in future editing sessions.

                    Please keep providing these tutorials, maybe something will eventually click in my head. ;)

                    A 1 Reply Last reply Aug 9, 2021, 8:20 PM Reply Quote 1
                    • C
                      Chris Tanguay 0
                      last edited by Aug 9, 2021, 2:03 PM

                      Thank you for all of this! I used the BetterMultiSelection as my first try and worked with my data, but I also am logging the Brute force way, which I’m sure will be needed on some set of data I deal with!

                      1 Reply Last reply Reply Quote 0
                      • A
                        artie-finkelstein @artie-finkelstein
                        last edited by Aug 9, 2021, 8:20 PM

                        For any other users that may wish some sort of documentation on the non-obvious features of BetterMultiSelection- I found this January 2021 post by @astrosofista containing links to some of his earlier tutorials. Many are helpful, some are sublime, all seem to illustrate the secret philosophy practiced by programmers world wide: “You want comments? You want documentation? It was hard to write, it should be hard to figure out how to use it.” <grin>

                        Again, thanks to @astrosofista for shedding light on it’s hidden depths. I find the ‘add a space and backup before expanding’ trick very helpful when cleaning up lists with ragged alignment. It sure beats doing it segment by segment and changing anchors as spacing changes.

                        D 1 Reply Last reply Aug 10, 2021, 12:25 PM Reply Quote 3
                        • D
                          dail @artie-finkelstein
                          last edited by Aug 10, 2021, 12:25 PM

                          @artie-finkelstein said in How do I align/indent text to an inside column (using SHIFT-CTRL-ALT+ Left Click):

                          You want comments? You want documentation? It was hard to write, it should be hard to figure out how to use it.

                          As the author of the BetterMultiSelection plugin I certainly don’t want this plugin to be ‘hard to figure out’…though I will be the first to admit that documentation is rarely fun to write :)

                          The whole purpose of this plugin (which several other editors do) is treat each cursor independently (left moves each one left, end moves each one to the end of the line, etc, etc)…and thats it. With this basic enhancement, it does certainly create some ‘hidden depths’ that even I’m not aware of. I can’t say I’ve ever seen it used this way to line up columns, but after watching the demo it makes perfect sense. Several of the other examples you linked proves I don’t know the depths that this can provide.

                          It seems I have created a hammer that I can swing; @astrosofista can use it to build a house.

                          A 1 Reply Last reply Aug 11, 2021, 5:22 AM Reply Quote 8
                          • A
                            artie-finkelstein @dail
                            last edited by Aug 11, 2021, 5:22 AM

                            @dail
                            Now that I’ve stopped laughing at your closing line: Your candor is admirable.
                            I thought I understood how BetterMultiSelection worked, exactly as you described: it ganged up the cursors (a basic feature I use every day). I had no idea that the techniques @astrosofista was demonstrating were ‘not designed in’. My comment about possibly missing documentation was based on a very incorrect assumption. I apologize if offense was received.

                            Your statement: ‘but after watching the demo it makes perfect sense’ is very beguiling. How does it make sense? Where should I look to understand the seeds that lead to the ‘a ha’ moment? (Please don’t tell me I need to grok the Scintilla source code <wry smile>, but if that’s the answer, that’s the answer.)

                            D 1 Reply Last reply Aug 11, 2021, 1:24 PM Reply Quote 1
                            • G
                              gstavi @astrosofista
                              last edited by Aug 11, 2021, 12:39 PM

                              One more optimization, using ctrl-delete. Not requiring a plugin.

                              1. Select the column to which you want to align with alt-shift-down arrow (or alt-shift-mouse).
                              2. Add ‘space’ to the entire column.
                              3. Select the space you just added with shift-alt-left arrow.
                              4. Use ctrl-delete to delete the space you added and any extra space afterward.

                              Unfortunately adding a video is beyond my abilities.

                              A C A 3 Replies Last reply Aug 11, 2021, 1:04 PM Reply Quote 8
                              • A
                                Alan Kilborn @gstavi
                                last edited by Aug 11, 2021, 1:04 PM

                                @gstavi said in How do I align/indent text to an inside column (using SHIFT-CTRL-ALT+ Left Click):

                                One more optimization, using ctrl-delete

                                Nice one!
                                This will become my “go to technique” for this alignment operation.

                                Note that you can avoid steps 2 and 3 if you already have some whitespace to the left of your closest-to-caret “ragged” text; example (picking up after @gstavi 's step 1):

                                Imgur

                                Then, (skipping steps 2 and 3), press Ctrl+Del (step 4) to obtain:

                                Imgur

                                At that point, if you need to move the now-aligned text block to the right, simply press the space bar any number of times.

                                G 1 Reply Last reply Aug 12, 2021, 12:34 PM Reply Quote 4
                                • D
                                  dail @artie-finkelstein
                                  last edited by dail Aug 11, 2021, 1:30 PM Aug 11, 2021, 1:24 PM

                                  @artie-finkelstein said in How do I align/indent text to an inside column (using SHIFT-CTRL-ALT+ Left Click):

                                  I apologize if offense was received.

                                  Nope none at all :)

                                  Where should I look to understand the seeds that lead to the ‘a ha’ moment? (Please don’t tell me I need to grok the Scintilla source code <wry smile>, but if that’s the answer, that’s the answer.)

                                  This is beyond Scintilla, more of just problem solving with some (or more than some) trial and error. There’s no real key here but some suggestions to get your mind wrapped around better utilizing the plugin:

                                  1. Just focus on one cursor at a time.
                                  2. Try to solve the problem for just one line of text. (In this case the problem would be roughly “given my cursor is at a desired location, remove all whitespace after it”)
                                  3. If it didn’t work in all cases, identify why (e.g. for some lines there’s no whitespace after the cursor; it deletes the first character of the non-whitespace characters)
                                  4. Once you refine your assumptions (it requires at least one space…I can manually add in an extra space first), press Ctrl+Z several times and start at step #1

                                  I think it’s safe to assume @astrosofista did some trial and error the first time :)

                                  I think the hardest part in all this is looking at a problem and coming to the conclusion “Oh…I can (possibly) use BetterMultiSelection for this”

                                  There’s been times I try to use the plugin to solve a problem…and it’s just not the right tool and I end up using regex or macros (or a combination of all 3)

                                  PeterJonesP A A 3 Replies Last reply Aug 11, 2021, 1:40 PM Reply Quote 5
                                  • PeterJonesP
                                    PeterJones @dail
                                    last edited by Aug 11, 2021, 1:40 PM

                                    @dail said in How do I align/indent text to an inside column (using SHIFT-CTRL-ALT+ Left Click):

                                    Try to solve the problem for just one line of text. (In this case the problem would be roughly “given my cursor is at a desired location, remove all whitespace after it”)

                                    The problem is that sometimes, my go-to solution for a single line of text doesn’t work in the column select mode. In this case, I usually use the more-keystroke-solution of Ctrl+RightArrow then Ctrl+LeftArrow – which takes you from whatever space my cursor is at to the end of the next word, then back to the beginning of that word. That same situation works in multi-select mode (Ctrl+click), but not in column-select. In the past, when I’ve had a dozen or fewer lines to do, I would Ctrl+click to start… but trying to line up more than a dozen Ctrl+click locations nearly always fails for me, so I switch to regex at that point. But now that I’ve been reminded of Ctrl+DEL’s SCI_DELWORDRIGHT behavior, I’ll see if I can train myself to use that instead.

                                    1 Reply Last reply Reply Quote 0
                                    • G
                                      gstavi @Alan Kilborn
                                      last edited by gstavi Aug 12, 2021, 12:37 PM Aug 12, 2021, 12:34 PM

                                      @Alan-Kilborn said:

                                      if you already have some whitespace

                                      Sure but if you align a long column and one line is missing a space you will be deleting some word by mistake.
                                      A nice thing would be to put steps 2-4 into a macro but it doesn’t work for some reason.

                                      A 1 Reply Last reply Aug 12, 2021, 5:37 PM Reply Quote 2
                                      • A
                                        Alan Kilborn @gstavi
                                        last edited by Alan Kilborn Aug 12, 2021, 5:38 PM Aug 12, 2021, 5:37 PM

                                        @gstavi said in How do I align/indent text to an inside column (using SHIFT-CTRL-ALT+ Left Click):

                                        A nice thing would be to put steps 2-4 into a macro but it doesn’t work for some reason.

                                        What seems to happen in the macro is that when step 2 is played-back it only inserts a space on the line with the main caret.

                                        This is usually the bottom-most line of the zero-width column selection, but it can be the top-most line for those of us that select from higher line numbers to lower line numbers.

                                        So, yea, making a macro out of it doesn’t work.

                                        but if you align a long column and one line is missing a space you will be deleting some word by mistake.

                                        I still like my suggestion of putting the zero-width column block somewhat to the left of the column with the closest data. Sure, you have to be careful, but you have to be careful in any text editing operation.

                                        1 Reply Last reply Reply Quote 0
                                        • A
                                          astrosofista @dail
                                          last edited by Aug 13, 2021, 1:06 AM

                                          @dail, @artie-finkelstein, all :

                                          Thanks to both of you for your comments, although I think you exaggerate. And also thanks to @dail for having developed this plugin, I use it daily and am very satisfied with its performance.

                                          You are right, using this tool requires a problem-solving approach, and it certainly takes a little or quite a bit of trial and error. Especially when one gets started.

                                          However, as it happens in other cases -in regex, for example-, I think the most important thing is to look for patterns. Of course, the relevant patterns are those that can be described in the terms that the tool defines. In general, the patterns useful for regex are not the same as for the BMS plugin.

                                          This plugin recognizes two kinds of elements: words - made up of letters, numbers, and the underscore - and delimiters, lots of delimiters. It is perhaps more appropriate to focus on the latter.

                                          And unless the pattern is ultra-regular, I don’t think it’s a good idea to fixate on a single line. Rather, I think it’s best to count the delimiters on several lines in search of a regularity that can be exploited.

                                          Another feature of the plugin is that it lacks error controls. There is only visual user control. BMS does what the user requests without giving any feedback. Errors may pass unnoticed.

                                          For this very reason, and unless it is a text with a known regularity or regimented, I tend to choose the plugin -rather than regex or a script- when the text to be processed enters the screen, so I always have it under my control. Another criterion of choice, almost obvious, is that the selection can be continuous.

                                          Let’s see an example to illustrate these ideas, copied from this post:

                                          PoznamkaSlov!Prvé sväté prijímanie dňa: bez záznamu v, obci: Dolná Súča,
                                          PoznamkaSlov!Prvé sväté prijímanie dňa: 08.06.1969 v obci: Trenčín,
                                          PoznamkaSlov!Prvé sväté prijímanie dňa: 01.09.1999 v obci: Trenčín,
                                          PoznamkaSlov!Birmovaný dňa: 25.06.1972, Zapísané na RKFÚ: Soblahov
                                          PoznamkaSlov!Birmovaný dňa: 21.09.1973, Zapísané na RKFÚ: Hlohovec
                                          PoznamkaSlov!Birmovaný dňa: 17.4.2010, Zapísané na RKFÚ: Trenčín
                                          

                                          OP wanted to remove the text between the exclamation point in column 13 and the last colon, whose position varies in almost every line. There is no regular pattern of spaces, since the lines have between 5 and 7 spaces, nor is the distribution of delimiters after the colon regular. Thus, it is not possible to advance from column 13 or from the end of the line. The only interesting regularity is the exclamation point column.

                                          Another approach is needed. My first idea was to take into account a resource I mentioned in a previous message and that is to modify the word delimiter, in the preferences. If you add " ," in the corresponding field, it becomes possible to easily select the text to delete.

                                          Giphy

                                          1. Insert a multi-selection after the exclamation point column.
                                          2. Ctrl + Shift + End to select to the end of each line.
                                          3. Then Ctrl + Shift + Arrow Left to deselect up to the colon.
                                          4. Finally, delete the selected and unwanted text, pressing Back-Space.

                                          BTW, don’t forget to reset the word delimiter, or unexpected things may happen.

                                          The second idea, which came to me afterwards, turned out to be simpler - it does not require changing preferences - and is therefore better. While you can begin from the exclamation point column, for the sake of variation I’m going to start at the other end. I’m going to select column 55, that is, two characters before the colon in the last column. The idea is to remove all the unwanted characters to the right of column 55, because this creates the conditions to make a rectangular selection and easily delete the remaining text:

                                          Giphy

                                          1. Insert a multi-selection at column 55.
                                          2. Ctrl + Shift + Arrow Right to select the characters up to the colon. Repeat the action to add the colon to the selection.
                                          3. Press Back-Space to delete the selected text. We are left with a straight right margin and since the left margin is also straight, we are able to make a rectangular selection.
                                          4. Press Shift + Alt + Click after the exclamation point on the first line.
                                          5. Press Back-Space to delete the selected and unwanted text.

                                          That’s all. Hope you find this post useful.

                                          A 1 Reply Last reply Aug 14, 2021, 2:21 AM Reply Quote 6
                                          5 out of 33
                                          • First post
                                            5/33
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors