-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] Reverse line order #9837
Comments
Sorry about duplicate pull requests. While trying to implement this, I came across I considered just using that function, adding it to Shortcut Mapper and Line Operations menu directly; but I don't know if there is still any benefit to adding |
The Boost regex engine is what doesn't support variable-length lookbehind. The workaround for that is to use the Example: |
I considered that, after seeing it mentioned here, but in my case it wasn't of much help. It only helps match the first items; for the next items, since it doesn't do a lookbehind it is not able to match, so it just moves to the next title and its first item. It of course then matches the second items if I click "Replace" again, but I didn't want to click "Replace" hundreds of times! Reversing line orders and then doing a lookahead solved the issue nicely. In any case, that's probably a rather niche use case for this feature, and normally it would be used for actually reversing the line order, rather than as a temporary step for a workaround. I just mentioned it as it was specifically my use case this week, which is what urged me to write the code for this pull request. But I guess you mentioned it to be helpful in case I need to do it again, so thank you! I would of course prefer to do it in a single regex even if the feature is added to Notepad++, but I couldn't figure out a way. (Actually, I did figure out one way: Since in this case my titles were of fixed length (just the items weren't), I added the titles to the start and end of every item, and thus on every next item I was able make a lookbehind, so I could replace everything on one go; and then remove titles from the ends of items in a second regex. But that's an even uglier and more convoluted workaround than reversing lines, and wouldn't work if my titles weren't of fixed length.) |
Notepad++ can sort lines in various ways, including the reverse of each sort option. But there is no way to reverse the existing order of lines. This Super User question from 10 years ago, with 117 upvotes, has a suggested workaround of inserting line numbers, sorting in descending order, and deleting line numbers, which is a quite convoluted and inconvenient way of achieving this result.
I am hoping that the usefulness of this feature would be evident to most that I don't need to list many reasons; at any rate I am sure that 77 thousand people who viewed that question had many more use cases than I can think of and list. In my case, I needed this feature because Notepad++ Regex replace didn't support variable-length lookbehind. I wanted to replace
with
which required variable-length lookbehind to get the previous title for every line. My simple workaround was reversing lines, doing a variable-length lookahead, and reversing the lines again. But I had to use an external solution to reverse line orders (which also meant that it wasn't macro-able), it would be much simpler with a Notepad++ command. This is a fairly technical use case, but I would assume that more casual users desire this feature, as they simply want to invert their lists for whatever reason. I also have some lists that being able to easily reverse them occasionally would come in handy.
Finally, I would use @sasumner's reason in [Feature Request] Sort lines randomly (i.e., shuffle lines) (#8682) (whose pull request is what I used as a model to code mine): "We have
ranDOm CasE
, why not haveSort lines randomly
?" -> "We haveiNVERT cASE
, why note haveReverse line order
?".For consistency with the Convert Case menu, I placed the proposed "Reverse line order" item just above the "Sort lines randomly" item.
The text was updated successfully, but these errors were encountered: