Answer a question

In JupyterLab you can run code in many different ways. And I often use the option to run the active line (where the mouse pointer is) using Run > Run Selected text or current line in console with a keyboard shortcut. After doing this, the pointer jumps to the next line, and you can keep going.

Can the same thing be done using VSCode?


And just to be clear, the following is not what I'm looking for:

  1. Ctrl+Enter will run the whole cell.

  2. Shift+Enter when highlighting a line or or other parts of the code will run that part.

  3. Shift+Enter with no highlighted code runs the whole cell and inserts a new cell below the active cell.

So, how can I run only the active line without highlighting it?

A similar question has been asked here: How to run the select code in VScode?, but that sends code to the Terminal and does not provide the answer I'm looking for.

Answers

Go to file > preferences > keyboard shortcuts, search for Run Selection / Line in interactive window and assign your desired keyboard shortcut. And make sure that there are not conflicts. I found out that several tasks had Shift + Enter assigned to it, and that's what had me confused in the first place.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐