How to open a .py file in sublime from a terminal console?

  • Context: Python 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    File
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
5 replies · 1K views
member 428835
Hi PF!

To open hello.py in the past I've used gedit hello.py but this opens the file in text editor. I would prefer to use sublime since it has features that are appealing to me. So my question is, how do I open hello.py in sublime from the terminal?
 
Physics news on Phys.org
PeterDonis said:
sublime hello.py doesn't work?
Didn't realize it was this simple; thanks! (it's actually subl hello.py, but thanks)
 
joshmccraney said:
Didn't realize it was this simple

On Unix-type systems it's a pretty general pattern that <program-name> <filename> at the shell opens the program operating on that file. Of course you still get curve balls like the program name being "subl" instead of "sublime". :wink:
 
  • Like
Likes   Reactions: member 428835
Got it! Fortunately tab kinda takes care of this :)
 
On mac machine you can say:
Bash:
$$ open <filename>
and it will select the proper editor or viewer or to be selective:
Bash:
$$ open -a /Applications/MyFavoriteTextEditor.app <filename>
where MyfavoriteTextEditor is a subfolder in the /Applications folder.

I even added an alias like:
Bash:
$$ alias ted=open -a /Applications/MyFavoriteTextEditor.app <filename>

$$ ted <filename>