How do I align/indent text to an inside column (using SHIFT-CTRL-ALT+ Left Click)
-
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.
-
@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.
-
@dail
Now that I’ve stopped laughing at your closing line: Your candor is admirable.
I thought I understood howBetterMultiSelection
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.)
-
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.
-
@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):
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.
-
@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:
- 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+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)
-
@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
thenCtrl+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 wouldCtrl+click
to start… but trying to line up more than a dozenCtrl+click
locations nearly always fails for me, so I switch to regex at that point. But now that I’ve been reminded ofCtrl+DEL
’s SCI_DELWORDRIGHT behavior, I’ll see if I can train myself to use that instead. -
@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. -
@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.
-
@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.- Insert a multi-selection after the exclamation point column.
Ctrl + Shift + End
to select to the end of each line.- Then
Ctrl + Shift + Arrow Left
to deselect up to the colon. - 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:
- Insert a multi-selection at column 55.
Ctrl + Shift + Arrow Right
to select the characters up to the colon. Repeat the action to add the colon to the selection.- 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. - Press
Shift + Alt + Click
after the exclamation point on the first line. - Press
Back-Space
to delete the selected and unwanted text.
That’s all. Hope you find this post useful.
-
@dail
Good suggestions, particularly about not getting hung up on all the ‘slave’ cursors, i.e., you practice playing scales before playing a concerto when learning to play the piano.I’m still trying to get caught up with all the tutorials @astrosofista posted, but this sounds like a good way to approach them.
-
@astrosofista
I couldn’t get your first example to work. And, I really, REALLY, don’t like the idea of changing preferences I don’t regularly modify and that seem to have a wide ranging effect on the editor configuration just to complete a single edit session. [Tab sizing is another issue and easy to verify what happens].However, the second example was right up my alley; a nice two step divide and conquer approach: take care of the irregular part then remove the remaining bulk to the left. Right along with the gist of @dail’s suggestion about not trying to view it as one big problem, instead solve the pieces.
Thank you for yet another helpful tutorial.
-
@artie-finkelstein said in How do I align/indent text to an inside column (using SHIFT-CTRL-ALT+ Left Click):
I really, REALLY, don’t like the idea of changing preferences I don’t regularly modify and that seem to have a wide ranging effect on the editor configuration just to complete a single edit session
I find that the “palatability” of such things is proportional to how much data I’m dealing with. If it is a lot of data and the technique is going to do the job for me, it is fine. Better to mod a preference temporarily than to do a large task manually. :-)
I too could not get the first example of @astrosofista to work. Here’s what it looked like after step 2, which I don’t think is correct vs. what was shown:
-
@gstavi
Incredible! Thank you! I’ve learned more in this one post…
awesomeness -
@artie-finkelstein, All:
Sorry, my bad. There is an error in the indications of the first selection. The correct action is
2. Shift + End to select to the end of each line
. Thanks for testing the example and letting me know the result.I understand if someone doesn’t want to change the preferences - as I am sometimes reluctant to change them myself - but if you want to use the multi-selection technique on a daily basis you will find that sometimes there is no other way to solve such a problem than to change the word delimiter. For example, in this post, for which I came up with that idea.
Of course, and as rightly stated in the post, the problem can be solved with regex or even scripting as well. But to users like the OP of the post, who don’t know anything about regex or scripting nor sadly want to learn, they could solve the problem with the multi-selection technique, which only requires basic notions of usage like scrolling through text using the keyboard and making selections. And in some cases it requires a change in preferences. I think the benefit far outweighs the cost.
Anyway, when choice is possible - which was not the case with the OP of the post -, it is reasonable for the user to choose the technique that best suits their tastes or needs. I have no objection to this.
Regarding the second and last example, I would just like to comment that it is possible to solve it in either direction, i.e., one can also start with the rectangular selection and then remove the irregular part. However, for the purposes of explanation, it seemed to me that the idea is better visualized if you leave the rectangular selection to the end.
That’s all. Thanks again for the feedback.
-
@Alan-Kilborn said in How do I align/indent text to an inside column (using SHIFT-CTRL-ALT+ Left Click):
I too could not get the first example of @astrosofista to work. Here’s what it looked like after step 2, which I don’t think is correct vs. what was shown:
Yes, my bad, sorry for that. Step 2 doesn’t need to use
Ctrl
, justShift
+End
.Thank you for the feedback.
-
This thread and specifically THIS POSTING brings great closure to THIS OTHER THREAD I started almost 4 years ago. Thanks again @gstavi !
-
@astrosofista
I tried again and again with your updated instructions. Then I went back and carefully re-read the original and entered " ," space comma (0x20 0x2C) in the word delimiter preferences and it worked nicely. (I’d only remembered the comma.) Further investigation leads me to believe:- The space character is mandatory for the proper left arrow movement
- The comma is mandatory for the initial area expansion
Now I have to expand my pattern recognition space …
Perhaps the old rubric:Some people, when confronted with a problem, think- "I know, I'll use regular expressions." Now they have two problems. --Jamie Zawinski
should be updated to
Some people, when confronted with a problem, think- "I know, I'll use 'BetterMultiSelection'." Now they have two problems (unless they are @astrosofista).
Thank you.
(I think I may have over reacted to the warnings in ‘Word character list’, but now I have to figure out how to make it easier to (re)select the default list after mucking about where only the wizards dare tread.)
-
This post is deleted! -
@gstavi Thanks . That works well.
Now I know the other usage of ctrl del in notepad++ hihi