How to copy cells in Visual Studio Code when using Jupyter? - visual-studio-code

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.?

I'm a developer on this extension, and I have a bit of a two part answer for you.
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.
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.

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.

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.

Related

Run / execute a section of a notebook in vscode

In vscode notebooks, you can add markdown headers to divide your notebook into sections which can be collapsed / folded. Is there a way to execute all cells within such collapsed section, without unfolding it and running all the cells manually one by one?
There is a feature request in the vscode repo describing precisely this and it's marked as completed, so the functionality should be there. However, using the usual Shift+Enter or Ctrl+Enter on a markdown header does not run anything in vscode 1.68.1. I also cannot see it mentioned in the docs anywhere and the issue is locked, so one cannot ask there.

Visual Studio Code reload file to erase control Z and control Y

I switched from notepad++ to visual studio code but notepad++ had an interesting feature which was to reload the file
In this way the changes with control z and control y were eliminated.
And you started the editor again from 0.
It was very useful to me.
Now in visual studio code there is no option.
How could I get it?
Edited I found a way to do it but it has a problem.
Edit this shortcut by removing the developer option from it.
But the problem is that if you have multiple files it updates them all.
What you want is for it to reload only the file you have open in the foreground.
Same thing notepad++ does when you hit the reload from disk button.

How to Format Jupyter notebook in VSCode?

We can format python code in the jupyter notebook in the browser. After I change to VSCode and use the Microsoft extension, I find I can not format Jupyter notebook any more. Does anyone know how to solve this?
As Kyle Carow stated in their answer to Ian Huff: Formatting of notebooks is available by now.
MacOS: Option+Shift+F
Windows: Alt+Shift+F
Pressing these keys will either trigger a formatting of the active cell or the notebook as a whole if no cell is active.
Windows: Shift+Alt+F
Is what worked for me with Black formatter set up on VS Code Version: 1.64.2
Or right click "Format Notebook" to format entire notebook.
Format Notebook
I do not think VS Code support formatting of code cells, but if you use the black code formatter, then you can use the blackcellmagic %%black to format the code in a cell.
You need to have pip install black and blackcellmagic, details here: https://github.com/csurfer/blackcellmagic
I'm not exactly sure what is being asked here. But currently in VS Code the notebook editor and interactive window do not support formatting python code.
However we are moving to a new UI for those features which will support all the formatting features of VS Code in .py files. If you try out VS Code - Insiders now you should see this support and can try it out. This new UI will eventually be rolling out to VS Code stable.
Edit: The new UI which supports formatting in cells is now out by default for stable users.
If you have a Jupyter notebook open in VS Code with the Jupyter notebook extension, it should be possible to format code cells with Ctrl+ Shift+ I.
I'm not sure if this shortcut differs between operating systems, you can check what the shortcut is yourself by hitting Ctrl+ Shift+ P and then searching for "Format cell". The shortcut should be displayed then.

How to highlight cells in vscode?

Hello,
I have been using vscode (Visual Studio Code) text editor for couple of days. I have come from Spyder IDE for python. I am developing a great likeness towards vscode. It encompasses all of my needs to python programming with also being lightweight.
However, one thing that I am missing and wish it were here in vscode is cell highlighting. Though the editor has feature to segment the code into several cells by typing # %% before a block, it lacks the feature to highlight the cell where mouse pointer is hovered on.
Maybe, there is an option there in settings.json but i don't know where it is in particular. Though it is not a great lack or causes major issues but i like to enable this feature in my vscode editor.
Below pictures illustrate my point.
Previous image is the visual studio code editor and the below one is for Spyder IDE.
It seems it is supported now.
Bellow there's a screenshot for the current version of VSCode using Microsoft's Python extension.
If this answers the question, please, inform as answer.

How do I remap the `Alt+Click` action in visual studio code?

according to the documentation here I can add multiple cursors in visual studio code by using alt+Click in the editor. Sadly alt+drag is already used by the window manager to move the window around, so visual-studio-code does not get any key events. So how do I change that keyboard configuration in visual studio code? I could not find anything in the default key combinations file.
I am not looking for solution that changes my window manager, I really like that behavior and use it very frequently already for a very long time.
The easiest way in my opinion is:
From the top-level menu, click on
Selection -> Switch to Ctrl+Click for Multi-Cursor
Then you can use Ctrl+Click rather than Alt+Click.
You can see where this is in this screenshot:
My VSCode version is 1.24.1
There is currently no way to do this but already an open issue on GitHub which addresses that.