Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text: run code in a new file without saving to disk and the default language setting for a new file

I am using Sublime Text Editor for Python development. If I create a new file by Ctrl + N, the default language setting for this file is Plain Text, so how to change the default language setting for the new file to be Python ?

Another question :If I write some code in the new file and have not save it to disk, it is impossible to run it and get the running result, is there a solution to remove this restriction so that we can run code in the new file without saving it to disk first?

like image 364
iMath Avatar asked Sep 27 '22 08:09

iMath


2 Answers

There are several packages available for setting the default syntax for new files. One, as mentioned in the comments, is Default File Type, but I actually prefer ApplySyntax. It automagically detects what the syntax of a file should be, based on a bunch of (user-configurable, of course) rules, and also sets the default syntax for new files.

The only way to run unsaved code in Sublime is to install the excellent SublimeREPL plugin. Among many other features, you can highlight and transfer code to a running REPL, or just enter the code directly in the REPL.

like image 124
MattDMo Avatar answered Sep 29 '22 06:09

MattDMo


The second question about running without saving to hard disk:

1-press ctrl + shift + p

2- write install package and install it

3- write "auto save" and install it

4- go to preferences> package settings> Auto-save> Settings Default and copy all the code

5- go to preferences> package settings> Auto-save> Settings user and past it and change the first code from: "auto_save_on_modified": false, to "auto_save_on_modified": true,

good luck

like image 44
Chami M Avatar answered Sep 29 '22 06:09

Chami M