Create a shortcut to run a Python file in VScode on your terminal

The terminal here refers to the terminal that starts up with shift + control + @ in vscode. Also, cwd in that terminal is the directory directly above the file being edited in the editor area.

Note): This article is just for improving debugging efficiency. Since this is my first time writing an article, I would like you to comment on points that should be improved in terms of writing and opinions that I should have created such a shortcut.

procedure

  1. Install Python extension
  2. Add shortcut

I will write only about 2. Just add the code below.

keybindings.json


    {
        "key": "cmd+r",
        "command": "python.execInTerminal",
        "when": "editorTextFocus"
    },

Please change the "key" to your liking! It is recommended to set the when expression as well. (Because another command was set by default and I was likely to negotiate with it.)

With this, the purpose of this time has been achieved. (Smiley) You saved yourself the trouble of moving to the terminal and typing commands! If you want to debug partially, there is also a command like "Select a part and execute", so that is also good. (In my case, I just wanted to create a short test file and execute it, so I will omit it this time.) However, it is not enough that it can be used only for Python ... If possible, even with c or cpp

gcc -o file file.cpp


$: ./file
```I want a shortcut that will do???

# I want to generalize
 You can open the shortcut list with a shortcut by pressing cmd + K cmd + S. (Complicated)
 If you type run file etc., the following screen will be displayed. Of course, the display result will change depending on the extension you have installed.
 <img width="1060" alt="スクリーンショット 2019-12-19 13.28.32.png " src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/517924/4f86c5c4-b4e9-6d6a-00f3-eaf3790481b0.png ">
 There

#### **`workbench.action.terminal.There is a clearly generalized command called runActiveFile...`**

So when I run it with this, the following error occurs.

bash: cwd/file.py: Permission denied



#### **`I want to solve this...Maybe it's a problem that the pass doesn't pass or something like that...`**

result

I couldn't read English and gave up. (Miscellaneous fish) I would like experts to comment on how to set it so that it can be applied to other languages ...

Recommended Posts

Create a shortcut to run a Python file in VScode on your terminal
How to create a JSON file in Python
Create a plugin to run Python Doctest in Vim (2)
Create a plugin to run Python Doctest in Vim (1)
A memorandum to run a python script in a bat file
Create a binary file in Python
Create a python environment on your Mac
[GPS] Create a kml file in Python
Create a shell script to run the python file multiple times
Create a GIF file using Pillow in Python
I want to create a window in Python
Create a MIDI file in Python using pretty_midi
I want to randomly sample a file in Python
Create your first GDSII file in Python using gdspy
Python script to create a JSON file from a CSV file
Run a Python file with relative import in PyCharm
Create a function in Python
Create a dictionary in Python
Create a list in Python with all followers on twitter
How to run a Python file at a Windows 10 command prompt
Change the standard output destination to a file in Python
How to import a file anywhere you like in Python
Create a tool to check scraping rules (robots.txt) in Python
I made a script in Python to convert a text file for JSON (for vscode user snippet)
Create a DI Container in Python
Create a Python environment on Mac (2017/4)
Create a python environment on centos
Create a Kubernetes Operator in Python
5 Ways to Create a Python Chatbot
Run a simple algorithm in Python
Create a random string in Python
How to create a config file
Create a Python environment for professionals in VS Code on Windows
How to install OpenCV on Cloud9 and run it in Python
A game to go on an adventure in python interactive mode
How to create a heatmap with an arbitrary domain in Python
Try to log in to Netflix automatically using python on your PC
Python vba to create a date string for creating a file name
Try adding a wall to your IFC file with IfcOpenShell python
Run the output code on the local web server as "A, pretending to be B" in python
[Python] Create a program to delete line breaks in the clipboard + Register as a shortcut with windows
Create your own Linux commands in Python
[LLDB] Create your own command in Python
Create a simple GUI app in Python
Run the Matrix to your boss's terminal!
Convert psd file to png in Python
Create a JSON object mapper in Python
Run AzureKinect in Python on Christmas Eve.
Run the Python interpreter in a script
How to get a stacktrace in python
Create a deb file from a python package
Run Python code on A2019 Community Edition
Script to create a Mac dictionary file
[Python] A progress bar on the terminal
Run Python in C ++ on Visual Studio 2017
Add a Python virtual environment to VSCode
How to run a Maya Python script
Run a Python file inside a Docker container on a remote Raspbian via PyCharm
Steps to create a Python virtual environment with VS Code on Windows
[Python] Create a linebot to write a name and age on an image
Test & Debug Tips: Create a file of the specified size in Python