Open Files in a GUI Editor from the Terminal
Jump to navigation
Jump to search
How to open files with your favorite editor from the terminal?
1. Open your shell config file:
vi ~/.zshrc # for zsh vi ~/.bashrc # for bash
2. Add an alias for your editor:
# VS Code alias code="open -a 'Visual Studio Code'" <pre> Tip: Not sure of the exact app name? Run this to find it: <pre> ls /Applications/ | grep -i "visual\|cursor\|zed\|sublime"
The name must exactly match the `.app` filename in `/Applications/` (without the `.app` extension).
3. Reload your config:
source ~/.zshrc # for zsh source ~/.bashrc # for bash
One-liner shortcut:
# Detect current shell and set the corresponding config file RC_FILE="$HOME/.$(basename $SHELL)rc" # Append the alias to the config file (>> appends without overwriting) echo 'alias code="open -a Visual\ Studio\ Code"' >> "$RC_FILE" # Reload the config file so the alias takes effect immediately source "$RC_FILE"