Sublime Forum

Opening a file through terminal

#1

How to open a sublime file for text editing a .c file. I have already tried: subl file.c and I get
zsh: command not found: subl

When I try: subl .c I get
zsh: no such file or directory: file

So if I can get any insight on this that would be much appreciated I am pretty new to Mac’s native terminal.

0 Likes

#2

https://www.sublimetext.com/docs/command_line.html

0 Likes

#3

So I’m not sure if it is because I am using the M1 Max Chip but when I run the command for the “zsh” I literally get nothing like I’ll run the command then try to use “subl” and it cannot recognize the command. Also when trying to run “/Download/Sublime Text.app/Contents/SharedSupport/bin” I get “zsh: no such file or directory: /Downloads/Sublime”. Is this because of the white space between Sublime and Text?

0 Likes

#4

Sublime Text works the same on x86 and arm. Yes, when a path has a space in it you need to quote that path - just like is done in the documentation I linked.

0 Likes

#5

Interesting yeah whenever I run the Zsh command and I copy paste it over from the documentation you provided nothing happens. I go back to my .c file and it still won’t recognize “subl”.

0 Likes

#6

You need to start a new zsh session for those changes to take effect.

0 Likes

#7

Did that and still can’t get it to work. It’s not the end of the world or anything I can always just open the .c file through Sublime itself.

0 Likes

#8

Can you run echo $PATH?

0 Likes

#9

Yes and when I do I get “/Downloads/Sublime Text.app/Contents/SharedSupport/bin:” but multiply that by like 15.

0 Likes

#10

Sounds like you ran the command from the documentation multiple times, I’d suggest cleaning up your ~/.zprofile after you’ve got this working. Can you run ls "/Downloads/Sublime Text.app/Contents/SharedSupport/bin/*"?

0 Likes

#11

Yes when I run that exact same command it says that there is no such file or directory.

0 Likes

#12

Then the path is wrong. Do you have the Sublime Text application in your downloads folder?

0 Likes

#13

Actually the path would be wrong anyway, as /Downloads isn’t a directory. It’s ~/Downloads.

0 Likes

#14

So in this screenshot you will see me locating Sublime in downloads then running the command and it still not working.Ignore the scribbly lines of me crossing my name out lol.

0 Likes

#15

Could be a zsh thing that * doesn’t work in that context. Try setting the PATH in the zprofile using ~/Downloads.

0 Likes

#16

Now I am getting a permission denied error which literally makes no sense. Because I have downloads open for reading and writing for my profile.

0 Likes

#17

I FINALLY GOT IT I moved Sublime from Downloads to Applications then ran the command again and it opened the file I need help clearing the zprofile like you mentioned above though.

0 Likes

#18

Great! Now that Sublime works from command line, type:

subl ~/.zprofile to open the editor.

At the bottom of the file you should see all the extra statements:

export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"

Delete all but one of them and save the file.

0 Likes