Editing system files in Linux (as root) with GUI and CLI text editors
It's good form to return non-zero on error.  The not-optional option is a little ugly and an environment variable may work better.

Some extraneous syntax can go:


1 before &gt;&amp;2 is implied
{} around unsubstituted dereferences doesn't add anything
echo is an alias for printf "%s\n"
testing for error instead of success allows test &amp;&amp; echo &amp;&amp; return without braces
command -v tests validity for you; no need to test again
you've moved the complexity into a function already; reward yourself by using aliases to invoke it


sudoedit_internal()
{
    [ $# -lt 2 ] &amp;&amp; echo "sudoedit_internal(): Invalid number of arguments." &gt;&amp;2 &amp;&amp; return 1
    ! command -v "$1" &gt;/dev/null &amp;&amp; echo "sudoedit_internal(): The editor $1 does not exist on this system." &gt;&amp;2 &amp;&amp; return 1
    editor="$1"; shift 
    SUDO_EDITOR="$editor $opt" sudoedit "$@"
}

for ed in vi nano       ; do alias su$ed="opt=   sudoedit_internal $ed"; done
for ed in code subl xed ; do alias su$ed="opt=-w sudoedit_internal $ed"; done