Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
LemonWiki共筆
Search
Search
Appearance
Log in
Personal tools
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Open Files in a GUI Editor from the Terminal
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
How to open files with your favorite editor from the terminal? __TOC__ == How to open files with your favorite editor from the terminal on macOS == 1. Open your shell config file: <pre> vi ~/.zshrc # for zsh vi ~/.bashrc # for bash </pre> 2. Add an alias for your editor: <pre> # 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" </pre> The name must exactly match the `.app` filename in `/Applications/` (without the `.app` extension). 3. Reload your config: <pre> source ~/.zshrc # for zsh source ~/.bashrc # for bash </pre> One-liner shortcut: <pre> # 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" </pre> example usage * [[Sublime_text#How_to_open_existing_text_files_with_Sublime_Text_from_terminal? | How to open existing text files with Sublime Text from terminal?]] == How to open files with your favorite editor from the terminal on Ubuntu == Most GUI editors on Ubuntu install a CLI command automatically, so you can often skip straight to using them: <pre> code . # VS Code cursor . # Cursor zed . # Zed subl . # Sublime Text </pre> If the command isn't found, follow the steps below. 1. Find the editor's executable path: <pre> which code # or find /usr/bin /usr/local/bin /snap/bin -name "code" 2>/dev/null </pre> 2. Open your shell config file: <pre> vi ~/.bashrc # for bash vi ~/.zshrc # for zsh </pre> 3. Add an alias pointing to the executable: <pre> alias code="/usr/bin/code" alias cursor="/usr/local/bin/cursor" </pre> 4. Reload your config: <pre> source ~/.bashrc # for bash source ~/.zshrc # for zsh </pre> One-liner shortcut: <pre> # Detect current shell and set the corresponding config file RC_FILE="$HOME/.$(basename $SHELL)rc" # Append the alias (replace the path with your actual executable path) echo 'alias code="/usr/bin/code"' >> "$RC_FILE" # Reload the config file so the alias takes effect immediately source "$RC_FILE" </pre> Tip: Snap-installed editors (common on Ubuntu) are usually found under <code>/snap/bin/</code>. Run <code>ls /snap/bin/</code> to check. == How to open files with your favorite editor from the terminal on Windows == On Windows, you can launch GUI editors from the terminal using either '''Command Prompt''' or '''PowerShell'''. Most modern editors (VS Code, Cursor) install a CLI command automatically during setup. <pre> code . # VS Code cursor . # Cursor zed . # Zed subl . # Sublime Text </pre> If the command isn't found, follow the steps below. 1. Find the editor's executable path: Open File Explorer and look under common install locations: <pre> C:\Users\<YourName>\AppData\Local\Programs\ C:\Program Files\ C:\Program Files (x86)\ </pre> Or search from PowerShell: <pre> Get-Command code -ErrorAction SilentlyContinue # or where.exe code </pre> 2. Add the executable to your PATH (recommended): # Open '''Start''' → search '''Environment Variables''' → click '''Edit the system environment variables''' # Click '''Environment Variables...''' # Under '''User variables''', select '''Path''' → click '''Edit''' # Click '''New''' and paste the folder path containing the editor's <code>.exe</code> # Click OK to save, then restart your terminal 3. (Optional) Add a PowerShell alias: Open your PowerShell profile: <pre> notepad $PROFILE </pre> If the file doesn't exist yet, create it first: <pre> New-Item -ItemType File -Path $PROFILE -Force </pre> Add an alias: <pre> function code { & "C:\Users\<YourName>\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd" @args } </pre> Save and reload: <pre> . $PROFILE </pre> One-liner shortcut (PowerShell): <pre> # Append alias to your PowerShell profile and reload it Add-Content $PROFILE 'function code { & "C:\Users\<YourName>\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd" @args }' . $PROFILE </pre> Tip: Using '''Windows Terminal''' + '''PowerShell 7''' is recommended for the best developer experience on Windows. Install both from the Microsoft Store. [[Category: Software]] [[Category: Text editor]] [[Category: Revised with LLMs]] [[Category: Developer environment]]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki共筆:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)