There's a method for using characters that get read but not shown by the game. It involves editing a font file or two. There's a tutorial for it somewhere on this site, and it does work. I used it to turn the "@" invisible. It doesn't display a space like if you were to enter a space in the name. It can also be used anywhere in the unit name, and since it is read by the game, it also helps sorting units of the same name. I'm not sure if using Steph's or Quintillus's editors has the issue where units with the same name aren't group sorted by the game. Whereas editing the font file does allow the game to group sort units of the same name, although you still have to figure out which one is the last/first in the group, since they all will appear the same.
Example, you have 10 units that are all named Swordsman. But you have two types of Swordsman. In the editor, the units are named "Swordsman" and "Swordsman@" but in the game it's just "Swordsman" for both units, with no spaces after the last letter, even if you have a unit "Swordsman@@@@@@@" which would be 7 spaces if you did the spacebar trick, rendering the goofy issue where in certain menus it messes with text boxes.
So let's say out of those 10 Swordsman units, you have 3 "Swordsman" and 7 "Swordsman@"
The game will then sort it so all 3 units that are "Swordsman" will be at the top, and all 7 "Swordsman@" will be sorted after the first 3 units. It's a great trick. The downside is you have to sacrifice a font character. "@" is easy for me, because I don't care about email addresses in my civilopedia. This method is also great for using it as a sorting method to separate units of the same name that are in different eras.
Another useful tool for this is to bypass the character limit in the unit name in the official editor. Let's say you have a very long unit name, but want to create several versions of that unit with the same name. Well you can insert the invisible character, in my case, "@" anywhere in the unit name. So for example, "Main Universal Tank" already takes up much of the character limit in the unit name, so you don't have too many more spaces to add "@" after the last letter. Well, if you don't mind the game sorting the unit weirdly in game, then you can do something like "Main Un@iversal Tank" for example. This is nice if you want every single foot unit in your game, no matter the era, to be called "Infantry" but you have several hundred types.
Here's the tutorial, but if I remember correctly, I had to do a little guess work as the tutorial is incomplete. It's been so long since I did this, I don't remember exactly what I did or what program I used;
https://forums.civfanatics.com/threads/two-units-with-the-same-name.203187/
I am using this method in my current mod (in production), AGON. It works great.