Sort case insensitive on 64 bit?
-
sorry, I missed the insensitive part.
No, there is no builtin function other then converting the lines prior to sorting it. -
I wonder why there isn’t a case insensitive sort?
It seems only a slight step beyond a normal sort.
Any idea? -
Sorry, I don’t know.
Maybe it’s just a “my day has 24 hours only too” problem. -
@Alan-Kilborn and @Ekopalypse I’m not surprised that it’s not a native function. What surprises me is that no one has made a plugin for something that I’d think would be quite common.
-
well, there is, more or less a plugin which can do it.
It’s called pythonscript. If you want to go this way, then
I can provide a script which should do what you want. -
@Ekopalypse that would be helpful! Thank you!
I may try and relearn c++ (it’s been about a decade) and see if I can write a proper one at some point though.
-
after you installed pythonscript plugin from Plugin Admin,
click on new script in the plugin menu. Give it a meaningful name
and put this line into it.editor.setText('\r\n'.join(sorted(editor.getText().splitlines(), key=str.lower)))
Save it. Done.
To run it, go to plugins->pythonscript->scripts->your_script
-
@Corey-Keller said in Sort case insensitive on 64 bit?:
Is there any way to sort lines case insensitively on 64 bit Notepad++?
I believe another way is possible without using pythonscript (or other external plugins) etc. However it will mean the file will grow to twice the size initially before it shrinks again.
I’m suggesting using a regex to copy the entire line, and paste another “capitalised” version of it in front, followed by a number of special characters so it can easily be removed later in the process.
So the Replace function would be
Find What:(?-s)^(.+)$
Replace With:\U\1\E ## \1
Use the "Replace All button with wraparound also pre-selected.So this captures each line, it then replaces the line with first a capitalised version, followed by a space, two hashes and another space and then the original line. Note I’ve used the hash
#
, but any other combination will work. Just bear in mind some characters such as@*$^*!
have special meanings, so you may need to play with the combinations.At this point perform a normal lexicographical sort. Then we’d need to remove the first portion by using the following Replace regex.
Find what:(?-s)(.+? ## )
Replace With: nothing in this fieldYou now have it sorted as if every character was capitalised.
Terry
-
After supplying the answer in the previous post I realised it might be possible to combine all these steps into a macro, thus creating a “one-click” wonder. OK, well actually 2 clicks.
So if you feel up to the challenge you can edit a file called shortcuts.xml. Depending on how your Notepad++ is running it might be in one of several locations. in my case I open a File Explorer window, then type %appdata% in the top location field and press enter. At this point it should open a folder showing several other folders, you want the Notepad++ folder, shortcuts.xml is contained within.
This file can be edited within Notepad++, however (and very important) make this the ONLY file you edit in a Notepad++ session. If unsure, then close and re-open Notepad++ before opening this file.
The lines below can be inserted within this file (at the appropriate line) and then the file can be saved and closed. Exit Notepad++ again and re-open and you should now have the Macro entry (under Macro in top menu) “Upper-sort”. This macro combines all the steps my previous post alluded to.
You might want to change the name and the special characters I used " ## " before inserting the following lines into shortcuts.xml, feel free to do so.
Good luck
Terry<Macro name="Upper-sort" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s)^(.+)$" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="\U\1\E ## \1" /> <Action type="3" message="1702" wParam="0" lParam="768" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> <Action type="2" message="0" wParam="42059" lParam="0" sParam="" /> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s)^(.+? ## )" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1702" wParam="0" lParam="768" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> </Macro>
-
Hello, @corey-keller, @ekopalypse, @alan-kilborn, @terry-r and All,
Ah… yes, Terry, useful macro, indeed !
Two other possible regex syntaxes for the S/R, before sort :
SEARCH
(?-s)^.+
REPLACE
\U$0\E##$0
OR
SEARCH
^(?=(.+))
REPLACE
\U\1##
Note that I did not add
space
characters before and after the##
string
For people whose their language has accentuated characters, look that post, too :
https://community.notepad-plus-plus.org/post/55362
Best Regards
guy038
-
Nice one, Terry!
One suggestion, though: Why not name the macro to “Sort Ignoring Case”? -
-
Hi @guy038 @Alan-Kilborn @Corey-Keller
I had to come up with a quick name. I’m certainly not going to stop anyone creating a better one. Actually in the meantime I think I may have a better name although it is a bit long winded. Its:
Caseless Ranked Ascending Patterning
or
C.R.A.P. for short.Terry
-
@Terry-R said in Sort case insensitive on 64 bit?:
C.R.A.P. for short.
I may sue for copyleft infringement :-)
CRAPPS (Cisco Router Action Performing Perl Script)
Seriously, it’s a thing (the CRAPPS that is, not the suing for copyleft infringement)
Cheers.
-
Hey! Those don’t should like sh!tty names!
They seem like backronyms to me though. :-)