I would like to format my code by myself so it is easier for me to read the code, rather than having SharePoint formatting my code automatically, and it is hard to read.
Just use a decent development tool like Visual Studio. To use the browser for developing is like using scissors for mowing you lawn
Hint: a very good, free and lightweigt Development Tool for SharePoint Development on the Server is Visual Studio "Code": https://code.visualstudio.com/
Another one is Notepad++: https://notepad-plus-plus.org/
If you are talking about Code within sharepoint: It is the same here: Just don't! Create content editor Webparts and include the code into external files (which you edit with a proper development tool).
Alas, You can't, get used to it (in the comments section) is NOT the 100% correct answer...
View Formatted HTML source
In Interner Explorer you can change the default viewer to any application you want.
So View Source can look like:
BUT.. you can only View, not edit
Edit SharePoint files in other application
Most SharePoint pages and files are in document libraries you can Open With Eplorer (can only be done with IE)
you can open and save those with any application you want.
Note that those applications will not deal with Check-In/Out situations like SP Designer can.
(I usually turn Check-In/Out off on the
Style Library and
_catalogs/masterpage when I am doing major work)
You can map document libraries as Network Share:
Once mapped the connection is persistent and you do need to work with IE.
I only use IE to establish such connections (required about once a week) and primarily work with other file Editors
Since SP2013 you only have to deal with HTML files for MasterPages and DisplayTemplates (they are created automatically by SP)
(as I am a Frontend Dev) I prefer developing in Adobe Brackets, I hardly ever open SharePoint Designer.
I am so not used to putting code INSIDE webparts I mis-read the question
Putting code inside WebParts is not a good practice as it hides your code all over the place, is only accesible with the SharePoint UI and can't be reused. If you link CEWPs to files its all a lot easier.
Now to answer the question
You CAN format that code if you install some extra software which turns the
TEXTAREA into a decent editor.
It just takes some work:
- Create a BookMarklet or GreaseMonkey script to change the TEXTAREA
(same concept but with a local install)