Normally it is possible in jupyter or iPython notebooks to show lines number for a cell, however I don't see where in Google Colaboratory (Colab).
Yep, the shortcut (Ctrl + M + L) works,
other option is use the bar menu, at tool -> preference -> show line numbers
Update:
new path: Tools -> Settings -> Editor -> show line numbers
Holding Ctrl and pressing ML (one by one) switches on/off line numbers in the cells containing code.
I see it under Tools->Settings->Editor (as on On 1//1/2020)
Related
The vs code terminal I'm aiming is something like the Fireship's terminal. In this example, Fireship (content-creator in youtube) made a rust program, but in my case I'm trying to make it out with python 3.x. My mainly goal with this is making reading terminal easier and more intuitive.
Fireship's VsCode Terminal
My VsCode terminal
You can change the colors yourself if you want in the workbench settings.json
Steps:
Open Settings (Ctrl + ,)
Search for workbench color
Click on edit in settings.json
You can find out about the different settings you can change here
An example of how you can change your terminal:
"workbench.colorCustomizations": {
"terminal.background":"#131212",
"terminal.foreground":"#dddad6",
"terminal.ansiBlack":"#1D2021",
"terminal.ansiBrightBlack":"#665C54",
"terminal.ansiBrightBlue":"#0D6678",
"terminal.ansiBrightCyan":"#8BA59B",
"terminal.ansiBrightGreen":"#237e02",
"terminal.ansiBrightMagenta":"#8F4673",
"terminal.ansiBrightRed":"#FB543F",
"terminal.ansiBrightWhite":"#FDF4C1",
"terminal.ansiBrightYellow":"#FAC03B",
"terminal.ansiBlue":"#00a1f9",
"terminal.ansiCyan":"#8BA59B",
"terminal.ansiGreen":"#95C085",
"terminal.ansiMagenta":"#8F4673",
"terminal.ansiRed":"#FB543F",
"terminal.ansiWhite":"#A89984",
"terminal.ansiYellow":"#FAC03B"
},
In the normal Jupyter notebooks, we can add line numbers by pressing the L key after selecting the cell. All the subsequent cells for that notebook will have line numbers automatically.
But this is missing in VSCode. Every time a new cell is created, we need to select the cell and press the L key to enable the numbering for that cell which is very tiresome.
Is there a way to automatically enable line numbering for all the cells in the VSCode Jupyter notebook instead of manually pressing the L key for each and every cell?
Thank you.
In VS Code Jupyter Notebook, you can toggle line numbers by pressing L. The trick is to select the current cell first.
You could select your cell by clicking in the blank area on the left margin of the cell (when it's selected the bar on the left turns blue). Now if you press L on your keyboard, you would be able to turn the line numbers on/off.
In order to toggle on/off showing the line number for all the cells(code):
Click on the blank area (left side of the cell).
Press Shift + L.
As of 2021-01-04, this is sadly not possible.
Subscribe to the GitHub issue (Feature Request) Line Numbers - All Cells #1593 for updates.
Related: Line numbers should be enabled for current cell and subsequent cells when turned on #1659
Adding to this as still comes out the top result for the problem without a proper solution.
Assuming you have the Jupyter Notebook extensions installed for VSCode, in version 1.62.3, you can go into the Settings (Ctrl+,) search for "line numbers" and find the option for "Notebook:Line Numbers" and toggle this on.
This will show line numbers for all code cells in the Notebook by default so no need to keep pressing L
screen shot of Notebook line number toggle option
I always try any combination with modifiers keys.
Found out that pressing Shift + L enables the lines number for all the notebook at once
There is an unbound command to toggle line numbers:
notebook.cell.toggleLineNumbers
BTW, beginning in v1.75 the setting
notebook.lineNumbers can show relative line numbers
VS Code can now use all editor line number options when notebook.lineNumbers is turned on. For example, with "notebook.lineNumbers": "on" and "editor.lineNumbers": "relative", relative line numbers are displayed in cell editor.
from v1.75 Release Notes: Cell Editor Polish
You can now temporarily toggle the line numbers of a cell in the
current session from the cell toolbar, or change the visibility of
line numbers for all notebooks through the notebook.lineNumbers
setting.
Under the ... in the floating menu is a line number toggle. [The gif is too large for SO.]
I tried CTRL + A (outside cells): select all cells and right clicked "show cell line number". It displayed line number for every cell.
As for 2022:
In the upper left corner, select the config-weel.
One of the options you can choose is 'Show Notebook Line Numbers'
Sweet and easy.enter image description here
Adds example for #mark answer, you can enable for current work space using:
Make new folder name .vscode
Make a setting file inside that folder called settings.json
Copy paste code in the bottom of this post.
{
// other setting can be placed here
"notebook.lineNumbers": "on"
}
Edit:
To open settings.json without manually creating the file is by opening workspace or user settings:
open Command Palette (Ctrl+Shift+P)
Type Preferences: Open User Settings (JSON) or Preferences: Open Default Settings (JSON)
Copy paste the snippet setting.
Enter empty space on Jupiter notebook .ipynb file
Click:
F1
Then write:
Show Cell File Numbers
I trying to interact with libreoffice with Python, which integrated in Libreoffice installation. And I didn't found anywhere how can I set margins in PageStyle, to set optimal height of row and prind few copies of document. Or, maybe, I can write macro in Libreoffice and run it from python. Code below is not working.
pageStyle = document.getStyleFamilies().getByName("PageStyles")
page = pageStyle.getByName("Default")
page.LeftMargin = 500
P.S. Sorry for my english.
In most versions of LibreOffice, the name of the default style is "Default Style". In Apache OpenOffice, it is named "Default" instead.
Here is the complete code. For example, name the file change_settings.py.
import uno
def set_page_style_margins():
document = XSCRIPTCONTEXT.getDocument()
pageStyle = document.getStyleFamilies().getByName("PageStyles")
page = pageStyle.getByName("Default Style")
page.LeftMargin = 500
g_exportedScripts = set_page_style_margins,
On my Windows 10 system, this script is located under the directory C:\Users\<your username>\AppData\Roaming\LibreOffice\4\user\Scripts\python. You will need to create the last two directories, and case must match.
Now, in LibreOffice Writer, go to Tools -> Macros -> Run Macro. Expand to My Macros -> change_settings and select the macro name set_page_style_margins.
For a full introduction to Python with LibreOffice:
https://wiki.openoffice.org/wiki/Python/Transfer_from_Basic_to_Python
http://christopher5106.github.io/office/2015/12/06/openoffice-libreoffice-automate-your-office-tasks-with-python-macros.html
I am using PyCharm on Windows and want to change the settings to limit the maximum line length to 79 characters, as opposed to the default limit of 120 characters.
Where can I change the maximum amount of characters per line in PyCharm?
Here is screenshot of my Pycharm. Required settings is in following path: File -> Settings -> Editor -> Code Style -> General: Right margin (columns)
For PyCharm 2018.1 on Mac:
Preferences (⌘+,), then Editor -> Code Style:
For PyCharm 2018.3 on Windows:
File -> Settings (Ctrl+Alt+S), then Editor -> Code Style:
To follow PEP-8 set Hard wrap at to 80.
For PyCharm 4
File >> Settings >> Editor >> Code Style: Right margin (columns)
suggestion: Take a look at other options in that tab, they're very helpful
For anyone, or myself if I reload my machine, who this is not working for when you do a code reformat there is an additional option to check under editor->code style->python : ensure right margin is not exceeded. Once this was selected the reformat would work.
You can even set a separate right margin for HTML. Under the specified path:
File >> Settings >> Editor >> Code Style >> HTML >> Other Tab >> Right margin (columns)
This is very useful because generally HTML and JS may be usually long in one line than Python. :)
For PyCharm 2019.3.1, I see this.
For PyCharm 2021.x this did the trick for python:
For PyCharm 2017
We can follow below:
File >> Settings >> Editor >> Code Style.
Then provide values for Hard Wrap & Visual Guides
for wrapping while typing, tick the checkbox.
NB: look at other tabs as well, viz. Python, HTML, JSON etc.
In recent versions of MATLAB, one can execute a code region between two lines starting with %% using Ctrl-Enter. Such region is called a code cell, and it allows for fast code testing and debugging.
E.g.
%% This is the beginning of the 1st cell
a = 5;
%% This is the end of the 1st cell and beginning of the 2nd cell
% This is just a comment
b = 6;
%% This is the end of the 2nd cell
Are there any python editors that support a similar feature?
EDIT: I just found that Spyderlib supports "block" execution (code regions separated with blank lines) with F9, but as the this thread mentions, this feature is still not very robust (in particular in combination with loops).
The Interactive Editor for Python IEP has a Matlab-style cell notation to mark code sections (by starting a line with '##'), and the shortcut by default is also Ctrl+Enter:
## Cell one
"""
A cell is everything between two commands starting with '##'
"""
a = 3
b = 4
print('The answer is ' + str(a+b))
## Cell two
print('Hello World')
Spyder3 defines a cell as all code between lines starting with #%%.
Run a cell with Ctrl+Enter, or run a cell and advance with Shift+Enter.
Spyder3 & PyCharm: #%% or # %%
Spyder3: Ctrl+Enter: to run current cell, Shift+Enter: to run current cell and advance.
PyCharm: Ctrl+Enter: to run and advance
# %%
print('You are in cell 1')
# %%
print('You are in cell 2')
# %%
print('You are in cell 3')
enter image description here
I have written a vim plugin in which cells are delimited by ## . It sends cells to an ipython interpreter running in tmux. You can define key mappings to execute the current cell, execute current cell and move to next or execute the current line :
https://github.com/julienr/vim-cellmode
I recently started working on a similar plugin for Intellij PyCharm. It can send the cell to either the internal python console (which has some issues with plots) or to an ipython interpreter running in tmux :
https://github.com/julienr/pycharm-cellmode
Pyscripter supports block execution. But it's Win only. And it's limited to select code block - > run it(Ctrl+F7). No notion of cells.
IDLE with IdleX has support for Matlab-like and Sage-like cells using SubCodes. Code in between '##' markers can be executed with Ctrl+Return. It also allows for indented markers so that indented code can be executed.
There is Sage that offers something like this. It is meant to be a python alternative to Matlab, you should take a look.
In a sage notebook, you write python commands within blocks that are pretty similar to matlab's cell.