Sublime Forum

New user - does OneDrive Desktop impact sublime text capabilities?

#1

Hi everyone!

I just began learning about python and utilizing sublime text (ST) so thank you in advanced for your patience.

The context of this request is that I’m trying to run a simple code in ST - print(‘hello world’).

However, when I try to save it as a python file on my desktop (by scrolling on the file type after save-file-as, and manually clicking it), it doesn’t save it as a .py file. The syntax highlighting doesn’t come up and when I try to run the program in CMD, it doesn’t work.

When I manually save it as a .py file by typing in .py at the end of the file name, then ST recognizes it as a python file. I can then run the program in CMD.

Is this something I need to be worried about?
I “think” this is because I’m on my work laptop, and they made our desktops all virtual (OneDrive).
I just switched work laptops and on my old one, I was able to locate the local desktop directory but for the new laptop, I can’t seem to find it and have confirmed with my IT that they prohibited users from accessing it.

To summarize, my questions are:

  1. Can I designate a different folder so that ST saves files as PY when I scroll down to select the file type?
  2. Is there a way to locate the local desktop directory?
  3. Should I just continue to manually type in .py at the end of every file?
0 Likes

#2

You can save files to wherever you like; the location of a file and it’s extension aren’t tied together. For organizational reasons you might want to do something like create a specific folder on your desktop to store your code in, or maybe create a folder in your Documents folder for this. Or one folder per project, etc.

I can’t really answer this one; there’s definitely a way to do it but I find OneDrive incredibly annoying in how it works, so I don’t use it. Someone else may be able to help with that though.

Short answer: yes.

Longer answer:

The extension is used by Sublime and by the system at large to know what type of file a file is, so as you’ve noticed an extension is required for various things to work. In the case of Sublime, it only knows a file is a Python file if it has an appropriate extension (i.e. it doesn’t try to analyze the content of the file to see if it looks “Python-y”).

When the Save dialog opens, the selector at the bottom of the dialog says what the file type is expected to be. If that’s set to Python, then Windows will add the .py extension onto the name for you automatically when you save. If it’s set to All Files, then no extension is applied because nobody knows what the file type is except you.

So, you need to either manually type the extension on the file, or change the drop down to the type of file you want to save so that it will happen automatically. While both work, it’s faster to type .py than it is to noodle around in the dropdown trying to find the right thing.

Sublime will actually set that to Python for you in the save dialog automatically, IF it knows that you’re trying to save a Python file. The catch-22 here is that until you save the file with a .py extension, it doesn’t know that you intend for it to be a Python file.

As an experiment, try this: Create a new tab, and before you type anything or save anything, open the command palette and enter synpy, then select Set Syntax: Python from the list of commands.

Note that in the bottom right of the window, instead of Plain Text it now says Python. If you start typing Python code you get syntax highlighting right away, and if you try to save the file the Save dialog will have the file type selector defaulted to Python because Sublime knows what kind of file it is, which means you can save without typing an extension and it will be set correctly.

0 Likes

#3

This is super helpful. I thought local desktop directory would make a difference but thank you for clarifying.

So I was curious to see whether it would work and typed in the actual one drive file path in cmd and it worked! it reads the virtual desktop now! :smile:

This is super helpful and makes sense. I tried your suggestion for the synpy and it worked! I’m assuming if I work with other files (not sure what extensions I may end up working with in the future), I’d just have to revert this setting back in command palette?

Thank you very much!

0 Likes

#4

It will indeed work for other types of files; though if you have a file with a specific extension the file type will be automatically inferred. You can change that association if you need to inside of Sublime though.

This video covers some of the more common questions regarding Syntaxes and covers these and a couple of other things that you may find helpful.

0 Likes