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
Click For Summary

Discussion Overview

The discussion revolves around how to open a .py file in Sublime Text from a terminal console, with participants sharing their experiences and methods for achieving this on different operating systems.

Discussion Character

  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant initially expresses a desire to open a Python file using Sublime Text instead of gedit, seeking guidance on the terminal command.
  • Another participant suggests using the command "sublime hello.py" but notes it does not work.
  • A later reply clarifies that the correct command is "subl hello.py," indicating a common misunderstanding about the program name.
  • One participant mentions the general pattern of using " " in Unix-type systems, acknowledging variations like the program name being "subl" instead of "sublime."
  • Another participant shares a method for macOS users, using the "open" command to select the appropriate editor or viewer, and describes creating an alias for convenience.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a single method, as different commands and approaches are discussed, reflecting varying experiences and preferences.

Contextual Notes

Some methods are specific to certain operating systems, and there may be assumptions about familiarity with terminal commands and configurations that are not explicitly stated.

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?
 
Technology news on Phys.org
sublime hello.py doesn't work?
 
  • Like
Likes   Reactions: member 428835 and phyzguy
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>
 

Similar threads

  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 12 ·
Replies
12
Views
11K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 14 ·
Replies
14
Views
2K
Replies
35
Views
7K
  • · Replies 18 ·
Replies
18
Views
2K
Replies
1
Views
6K