Here's a way to avoid running TextEdit as root:
EDITOR='open -Wne' sudo -e /etc/apache2/httpd.conf
You will need to quit the copy of TextEdit after editing the file.
sudo -e, sometimes known as
sudoedit but not on OS X, makes a temporary copy of the file with write permission for the current user, invokes an editor on it in the usual Unix fashion, and then copies it back.
The options to
-W waits for TextEdit to quit, so
sudo knows when to copy the file back.
-n ensures that it's waiting on a separate instance of TextEdit, not one you already have open which you might not want to quit. You can also substitute
-t instead of
-e if you have a favorite text editor other than TextEdit.
If you already have an
EDITOR variable set to use a graphical editor with its own wait-capable command line tool (such as TextMate or BBEdit), then you don't need any of these tricks and can just use
sudo -e <file> directly.