Nick T
Nick T

Reputation: 683

How to copy cells in Visual Studio Code when using Jupyter?

I'm working with a Jupyter notebook. How would you copy cells in Visual Studio Code? C to copy and V to Paste did not work for me as it would online.

Also, Visual Studio doesn't seem to offer right click options when working in the notebook. Is there a extension that would give me some options such as Cut, Copy, Paste, Delete Cell, Etc.?

Upvotes: 10

Views: 19792

Answers (4)

Mahmoud Maghrabi
Mahmoud Maghrabi

Reputation: 1021

  1. Press the mouse key anywhere inside the cell of interest.
  2. Press Ctrl + A to selelct the whole text in the cell
  3. Press Ctrl + C to Copy the code.
  4. Press Ctrl + V to paste your code anywhere.

Upvotes: 0

JOHN EDWARD BINAY
JOHN EDWARD BINAY

Reputation: 161

As of 2021-01-14, you can now select the cells, right click on any single one of the cells you selected (this will select them as a group if you select more than one) and have the option to press COPY. Or you can simply ctrl+C as a keyboard shortcut. The key here is when you copy and paste the cells to another notebook, your cursor needs to be outside any cells; that is you need to press somewhere outside the cell before pasting. In COLAB notebook, even if your cursor is on a cell, the copy and pasting method works. BUT here if you do that you will be pasting all of the codes inside the cell where your cursor is active; it will not paste the actual cells you copied.

Hope this wasn't too confusing.

Upvotes: 0

liedji
liedji

Reputation: 789

The new version of the visual studio Jupyter Notebook extension support all the standard operations for one or multiple cells of the jupyter notebook. For example, the following list shows some tested shutcuts:

  • To copy a selected cell(s) use: ctrl+c
  • To paste a selected cell(s) use: ctrl+v
  • To cut a selected cell(s) use: ctrl+x
  • To delete a selected cell(s) use: ctrl+x
  • etc.

Note that, as usual, to select multiples cells one should hold the ctrl button before selecting.

Upvotes: 0

Ian Huff
Ian Huff

Reputation: 3097

I'm a developer on this extension, and I have a bit of a two part answer for you.

  1. In the current (as of 2/16/21) stable release version of the extension notebook UI is done by a hosted webview, it was the only supported option at the time. As such it is lacking features both of Jupyter and of VS Code editor instances. It does not currently support cutting, copying and pasting of cells.
  2. We are currently in the process of moving over to VS Code's new notebook UI that they provide. This allows better UI both for matching Jupyter and supporting more VS Code editor features. This current UI does allow for copying / cutting / pasting cells with the familiar Jupyter commands.

This support will not be added to the old editors, but currently the new UI is available if you use the extension with VS Code - Insiders and will soon start rolling out to VS Code Stable.

https://devblogs.microsoft.com/python/notebooks-are-getting-revamped/

Short answer: Supported with VS Code - Insiders now, and will be supported on stable VS Code in the future.

Upvotes: 5

Related Questions