When using an interactive shell, and then using sudo
to execute a command, such as nano
, the current user's settings in application specific configuration files are not sourced. So, in this case, ~/.nanorc
is not sourced, and the settings are not read.
The same condition occurs when the user uses su
to switch to another user, including root
. In both cases the new, or effective, user's settings are loaded instead. So using sudo nano
, or using su
to become root
and then executing nano
, will source the /root/.nanorc
for user settings. The settings in the global configuration file, such as /etc/nanorc
, affect all users on the system and should only be used to set global settings, which the user's file may override anyway.
To cause the effect you are looking for you need to apply the specialized setting to /root/.nanorc
. Then when you sudo nano
the settings for root
will be applied rather than the settings found in ~/.nanorc
.
nano
through the mechanism ofsudo
none of your personalized settings are applied because it is not you executingnano
, rather it is the superuser. Try setting the desired setting in/root/.nanorc
instead./etc/nanorc
. I don't edit/root/.nanorc
even if it exists./etc/nanorc
affects all users of the computer. You should take it into account in a multi-user environment./root/.nanorc
move it somewhere else to see what happens:sudo mv /root/.nanorc{,.bk}