How do I align/indent text to an inside column (using SHIFT-CTRL-ALT+ Left Click)
Chris Tanguay 0 last edited by
Hi, all! Please take a look at this example.
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!
- 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.
astrosofista last edited by astrosofista
I would do it as follows:
How it works? First off, open Preferences -> Editing, and enable the Multi-Editing Settings. It also requires the
BetterMultiSelection pluginactivated, which you can download and install via Plugins Admin.
Then, do as the movie shows:
In the second line, place the caret at the left of the USER ID column.
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.
Press Shift + End to select till the end of each line.
Then press Shift + Control + Arrow Left to just select the spaces you want to delete.
Lastly, press delete.
You’re done. Hope you like it.
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
BetterMultiSelectionfor 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
BetterMultiSelectionnor reverting to the Npp 8.11 .exe had any effect on the incorrect behavior.
Thank you for any insight you may offer.
guy038 last edited by guy038
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 :
So, as you want to align the second field, right under the
Uletter of USER_ID header, =>
N = 8. Thus, the practical regex is :
Of course, you must select the
Regular expressionsearch mode, tick the
Wrap aroundoption and click once on the
Replace All( Do not use the
Replacebutton ! )
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.
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 characteris 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.
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:
As we did before, make a multi-selection at the left of the USER ID column. Then
Type in a space and step back pressing the Arrow Left.
Press Shift + Control + Arrow Right to just select the spaces and the first words.
Press Shift + Control + Arrow Left to deselect words and to select spaces.
Press delete to align the USER ID column.
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. ;)
Chris Tanguay 0 last edited by
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!
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.
dail last edited by
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
BetterMultiSelectionplugin 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 (
leftmoves each one left,
endmoves 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.
Now that I’ve stopped laughing at your closing line: Your candor is admirable.
I thought I understood how
BetterMultiSelectionworked, 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.)
gstavi last edited by
One more optimization, using ctrl-delete. Not requiring a plugin.
- Select the column to which you want to align with alt-shift-down arrow (or alt-shift-mouse).
- Add ‘space’ to the entire column.
- Select the space you just added with shift-alt-left arrow.
- Use ctrl-delete to delete the space you added and any extra space afterward.
Unfortunately adding a video is beyond my abilities.
Alan Kilborn last edited by
One more optimization, using ctrl-delete
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):
Then, (skipping steps 2 and 3), press Ctrl+Del (step 4) to obtain:
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.
dail last edited by dail
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:
- Just focus on one cursor at a time.
- 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”)
- 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)
- Once you refine your assumptions (it requires at least one space…I can manually add in an extra space first), press
Ctrl+Zseveral 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)
PeterJones last edited by
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+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+clickto start… but trying to line up more than a dozen
Ctrl+clicklocations 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.
gstavi last edited by gstavi
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.
Alan Kilborn last edited by Alan Kilborn
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.
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.
- Insert a multi-selection after the exclamation point column.
Ctrl + Shift + Endto select to the end of each line.
Ctrl + Shift + Arrow Leftto deselect up to the colon.
- Finally, delete the selected and unwanted text, pressing
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:
- Insert a multi-selection at column 55.
Ctrl + Shift + Arrow Rightto select the characters up to the colon. Repeat the action to add the colon to the selection.
Back-Spaceto 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.
Shift + Alt + Clickafter the exclamation point on the first line.
Back-Spaceto delete the selected and unwanted text.
That’s all. Hope you find this post useful.