Reputation: 3
I'm new to VS Code and am setting up Python (which I'm also learning). I set up everything you need for python and opened a previous python file I was working on and everything went smoothly. I tried creating a new file in vscode and it opened as a txt file so I switched it to a python file however, to get it to run without f5 I need to manually add '.py' to the end of the file name. Is there any way I can default it to whenever I make a new file it'll be a python file?
Upvotes: 0
Views: 8585
Reputation: 28663
You can create a command and a keybinding to create a new file and set the languageID to Python.
Use the following extensions:
Add this to your settings.json
"multiCommand.commands": [
{
"command": "multiCommand.newPythonFile",
"sequence": [
"workbench.action.files.newUntitledFile",
{ "command": "changeLanguageMode.change", "args": "python" }
]
}
]
You can run this command with the command palette: Multi Command: Execute multi command
Or you can set up a key binding in keybindings.json
{
"key": "ctrl+i ctrl+n", // or any other key combo
"command": "multiCommand.newPythonFile"
}
Upvotes: 1
Reputation: 633
Like the others said, all you need to is create a file with the .py extension in Visual Studio Code, since it's just a fancy version of TextEdit. There are also Python IDEs that have more features.
Upvotes: 0
Reputation: 188
Good question! Whenever you want to make a new python file, like the others have said is to just add ".py" to it. For python IDEs (Integrated Development Environment) Atom (https://atom.io/) and Pycharm (https://www.jetbrains.com/pycharm/) are great. Atom is free and Pycharm has a sick free version and the premium is free for students.
Upvotes: 0
Reputation: 216
VS Code is just a text editor. When it opens a brand new file, it can be of any programming language, like C, Java, Go, etc. This means that it cannot really just automatically assume that the new file you make is going to be a Python file, you would have to rename your file to have a .py
extension.
You might want to look into an IDE such as PyCharm, it provides a ton of features that a raw text editor does not, and it does have the support to create a new Python file without having to manually rename the extension.
Upvotes: 1