The Eclipse Editor has a very cool feature named ‘Code Templates’: With such templates files are created with specific pre-filled content. For the templates, variables like ${user} for the user name can be used, see Custom C/C++ Headers with Eclipse:

As for the variables like ${date} or ${user}, they defined by the system on which Eclipse is running. For for ${user} it uses the user name I have used for the login. But that might not be what I want to have used for example in the header or source file.
The question is: how to change the content of the ${user} variable? For example I want to show my full name and not my login name:

Because it is derived from the system, it does not make sense to have a setting for it. But there is a trick to change it for Eclipse :-).
For this, locate the Eclipse startup .ini file. For example for the NXP MCUXpresso IDE, it is located in the same folder as the executable and named mcuxpressoide.ini.
Open that file with a text editor and then set the variable user.name with the desired name:

Restart Eclipse, and now it will use that custom value for ${user}.

Happy templating 🙂
The system-defined Java properties (including “user.name”) have values that other Eclipse plugins may be relying on. So I would advise caution in overwriting these values. Ref: https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
LikeLiked by 1 person
Hi John, yes, that’s a good point. But I did not see anything special relying on the user.name, or do know anything specific?
LikeLike
There are 5 direct references to the “user.name” property in the CDT sources. Most of these are used for logging or presentation only. However, this property will be used to pre-populate the “User” field in the Launch Terminal dialog for SSH terminals. Dereferencing of the “${user}” token is performed by a template variable resolver within JFace code that is common to many Eclipse/RCP products. We simply cannot predict how other plugins may choose to use these system properties and whether they rely on their documented default values.
LikeLiked by 1 person
Hi John,
OK, I see your point. And indeed, this could be problematic. Do you know any other way to change the code template variables or creating a new one? Sure one could write his own plugin, but that’s not ideal.
LikeLike