For the longest time I used the Hostbuddy for Mac app to edit my hosts fiel and flush my local DNS cache. I still recommend the app to anyone who wants to edit their hosts file on Apples operating system using a GUI. However, I have recently started using the command line in conjunction with VS Code.

To edit the hosts file on macOS I added the following commands to my .zshrc file:

alias hostsedit='sudo code /etc/hosts'
alias hostsflush='sudo killall -HUP mDNSResponder; echo DNS Cache Reset'

These two commands let me edit and flush my hosts file's modifications to my local machines DNS without much effort.

Resources

The Visual Studio Code command-line options
Visual Studio Code command-line options (switches).
Running Visual Studio Code on macOS
Get Visual Studio Code up and running on Mac (macOS).
Oh My Zsh - a delightful & open source framework for Zsh
Oh-My-Zsh is a delightful, open source, community-driven framework for managing your ZSH configuration. It comes bundled with several helpful functions, helpers, plugins, themes, and a few things that make you shout... OH MY ZSH!
Hostbuddy for Mac
Hostbuddy is a powerful way to edit and manage your Mac’s /etc/hosts file.