You got an answer already. However, for your specific case, you don't need the system()
call, since you want an environment variable to be expanded. In that case you could simply use echo $EDITOR
or in case of a function call do:
function! GetEditor()
return $EDITOR
endfunction
Now, suppose you still need a system()
function call, because you need to return the output of a system specific command. If you know, the output will only have a simple line (e.g. only one single linebreak), you could simply return the output with the last byte (the linebreak) removed:
return system("yes |head -1")[:-2]
which uses the expr[] syntax to strip the last byte from the output.
Alternatively, you could make use of the systemlist() function
which automatically converts the output of the system command into a vim list, so you do not have to take care of those trailing linebreaks:
return systemlist("echo $EDITOR")
See also the similar answer on superuser