Using Sublime Text as the terminal $EDITOR
Whether it be writing a commit message using git commit, or editing a Kubernetes Deployment using kubectl edit, the convention for terminal applications when needing the user to edit a file, is to open said file in the application set in the $EDITOR environment variable.
Common default $EDITOR values found on many systems are vi and nano, which don’t always provide the best UX, especially if they’re not your go-to text editors usually.
To use Sublime Text in these situations instead, simply set the following in your ~/.zshrc:
export EDITOR="subl -wn"
The -w/--wait flag ensures that the subl program does not exit immediately, instead blocking until the open file is closed.
The -n/--new-window flag forces a new Sublime window to be opened, instead of just opening a new tab in the current one. This can be useful to avoid having the new open file from being lost amongst an existing open project.
The full list of Sublime CLI flags can be found here.
As part of setting up Sublime, the subl binary should already be available on the $PATH. However if it’s not, it can be added like so to ~/.zshrc (note: this filepath is macOS specific):
export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"