Ctrl+P and Ctrl+N for navigation in jupyter notebooks - jupyter-notebook

I'm used to Emacs navigation, in particular Ctrl+P, N, F, and B, but I'm also used to Jupyter notebooks by now. The general question is: how to enable those shortcuts in a notebook?
What tickles me is the fact that on Mac those keybindings are already in place in a standard Anaconda IPython. But it's perfectly understandable since most system and browser shortcuts are bound to Cmd instead of Ctrl.
Since I spend a lot of time in Ubuntu, I wanted to reproduce the same behaviour here. It soon became apparent that most browsers hold some of the keybindings very dearly, such as Ctrl+P for print or Ctrl+N for New window. Turning these off is a huge matter in itself, so I decided to use another browser solely for the Jupyter Notebook, and Vivaldi seems like a nice choice since all shortcuts are easily customizable there.
I believed that with browser shortcuts being turned off, the IPython syntax would kick in, but none such thing has happened. Next I tried one of many manuals on the Jupyter notebook shortcuts customization (such as this one http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Custom%20Keyboard%20Shortcuts.html) to bind the 4 shortcuts I need. It works only up to some extent and only in the Jupyter inline magic:
%%javascript
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('ctrl-p', 'jupyter-notebook:move-cursor-up')
What it does is that occasionally now the cursor in command mode does indeed move up when I press ctrl-p, but this behaviour is unstable. Moreover, after it moves, it immediately enters the edit mode in the cell above, which isn't happening if I simply press 'Up' arrow. As for the same trick for the edit mode:
%%javascript
Jupyter.keyboard_manager.edit_shortcuts.add_shortcut('ctrl-p', 'jupyter-notebook:move-cursor-up')
alas, it doesn't work at all.
Forgive me for the prolonged intro. The questions I have now are:
What is wrong with the key bindings I use in inline mode? Is it a silly mistake I made or a Jupyter glitch?
When I try to use these byndings through my custom.js file, they do not work. However, the file itself is recognized, e.g. the alert() commands work perfectly fine.
I've stumbled a few times on a emacs-bindings for the CodeMirror, however, as far as I understood, they are mostly used for copy-paste related matters rather than navigation, is it true? Would it help to use this set of bindings instead of pursuing the path with custom.js?
Thank you.
UPD
Installing emacs.js from CodeMirror and adding this code actually solved my problem. Just had to make sure that all conflicting browser keybindings were turned off.
require(["codemirror/keymap/emacs", "notebook/js/cell", "base/js/namespace"],
function(emacs_keymap, cell, IPython) {
cell.Cell.options_default.cm_config.keyMap = 'emacs';
var cells = IPython.notebook.get_cells();
for(var c=0; c< cells.length ; c++){
cells[c].code_mirror.setOption('keyMap', 'emacs');
}
}
);

Related

JupyterHub - how to debug UI issues?

We use jupyterhub cluster and without any noticeable change on our side, the notebook cells' height turned huge and static (attached a picture)
Tried to fix the issue looking at - How do I increase the cell width of the Jupyter/ipython notebook in my browser?
Managed to decrease the cells size but it's still static.
Any suggestion what has might caused the change? And how to fix this?
This is how our cells look today -
Potential fixes
My suggestion to uninstall your extensions one-by-one until the problem goes away may honestly be the fastest way to get a fix. If have a reasonably recent version of Jupyter you can list all of your installed extensions with:
jupyter nbextension list
You would then start by uninstalling any extension that relates to theme and/or styling of the notebook. It's possible that list will miss some things (eg an improperly installed extension, or issues with your own config files). The next step (after getting rid of at least all suspicious extensions) would be to go through all of the user-space data and config files that Jupyter sets up in the background. You can get the paths to all directories containing such files by running:
jupyter --paths
Small note, you can probably ignore all files in the runtime dir, these probably aren't the problem.
If a mass uninstall of your extensions makes you squeamish, another option would be to debug the CSS of a live notebook and figure out exactly where the styling of the code cells is getting screwed up.
Detailed instructions for debugging the CSS
The following instructions are for Chrome, but if you're using another browser you should be able to figure out an equivalent:
start up a notebook
right click on a code cell and select "Inspect"
this will bring up a view of the DOM node hierarchy and highlight the node representing the code cell (or some at least some part of it) that you just right clicked on
on the right side of the screen will be a window with a bunch of tabs at the top. Select "Computed", which contains the style that is actually displayed in the browser, as computed from the sum of the effects of all CSS selectors
in particular, pay careful attention to the width and height properties of the computed style. Walk up and/or down the DOM hierarchy until you find a node with a suspicious looking width or height
If a value is greyed out, that means that it's being set in a parent node
start with a suspicious looking value, then go up the hierarchy until the values seem normal again
on one side of that transition point, you should have the top-most node in your hierarchy with bad values. If you examine the "Computed" tab, you should be able to see exactly which files are setting the bad values
The identity of the files screwing up your notebook styling is the payoff here. Examining those files should help you a great deal in uncovering the real problem.

R.Studio: Lost my code changes while zooming out using "ctrl" + "-" in Rstudio source editor

I was using ctrl + - to make the code font smaller (or zooming out) in the R studio source editor and I got the pop up window (picture attached).
I think I pressed OK by mistake and I lost a huge chunk of code. How can I recover that?
Also. it makes me bit skeptical of using Rstudio. Pop out message
ctrl + z is the undo command (Windows)
For other shortcuts:
https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts
From a beginner standpoint, I find rstudio to be one of the most user friendly dedicated IDE's available for any programming language.
If you are on Windows, a JSON file with your code is available at
C:\Users[your user]\AppData\Local\RStudio-Desktop\sources
Follow instructions as:
https://stackoverflow.com/a/51433764/3142205
This is a terrible bug that RStudio has. I have never seen a code editor that every time you change the zoom level you lose your code! It is a terrible issue that makes me wonder if I should go back to Notepad++. I have never lost a file using Notepad++.
Updated: This issue has been solved in RStudio 1.2.1335 "Allow changing zoom level without reloading (#2125)".
In this case I immediately press ctrl + z. If this is not recovering your code try with history tab -> go to history tab:
Use ctrl with + on the right keyboard, don't use key.
may the shortcut of Zoom Source Editor with Ctrl+Shift+1 is a substitute plan.
It’s a pity that Rstudio doesn't provides a support to ctrl + +/-(mouse scroll)

important hotkeys don't work anymore after RStudio update to 0.99.878

I recently updated RStudio for Windows via download link mainly due to interest in the new features of the most recent version 0.99.878. Unfortunaly after the installation some important hotkeys behave different in the source editor, while they still work in the Console. I.e.
Ctrl+S starts an "isearch"
Ctrl+V jumps to the end of the document
When I enter Ctrl+X+(S or V) the hotkeys work as they should. The hotkeys can be customized, however when I open the Keyboard Shortcuts dialog it shows me the settings for the hotkeys. Also the cursor has turned to a shiny green rectangle (insert isn't activated).
The problems remains after switching the project. Also reinstalling Rstudio 0.99.878 didn't work out. I've seen a similar issue here, but think mine is different as it is installation related. I might have accidentally activated a special editor setting but couldn't find any.
It sounds like you may have (accidentally?) activated Emacs keybindings. If you go to Tools -> Global Options..., you can reset the preference here:

clicking or scrolling on terminal outputs text

this is driving me crazy. Everytime I click on the terminal, I get text output but the click does not happen. I can't select anything, scroll on the terminal or perform any mouse operations.
For example, if I click I get things like "TB#TB", which is "TB" when I click and "#TB" when I release the click. If I scroll I get 'UC'` for every scroll of the wheel. Total rubbish.
I'm using cygwin to connect to a redhat machine and it happens only for this one machine. If I connect to a different one, also running redhat, it doesn't happen, so I think the issue is on the remote machine's side. It's also independent of what shell I'm using.
Any ideas?
EDIT: I discovered that pressing shift returns all the usual mouse functionality. I wonder why.
This is more like a "come down to your machine and solve problem"
You must have save default setting for that particular machine to direct it to shift option. As you said shift solves the problem.
You should reset the settings.
go here.
Putty configuration>windows>selection>click on shift overrides application's use of mouse
hope this helps

Switching focus between editor and terminal in Kate

When working in Unix with various programming languages I often use Kate as my primary editor.
It has a really nice function of being able to open a built-in terminal window which is quite useful.
The problem is that switching back and forth to the terminal view using a mouse is quite a pain and I can't find any shortcuts for this. The only shortcut I could find is for closing the entire terminal (not just changing the focus). This is a bit annoying as it causes the text in the terminal window to get truncated (I think it's a known Kate bug).
Does anyone know a better shortcut?
Note that the Kate bug has been fixed. The correct answer to this question is now F4.
There's a "Focus Terminal" shortcut in the "Configure shortcuts"
There you can set it up. F4 didn't work by default in my case and Shift+Tab worked only in one direction.
this is a bug in kate. possible workarounds: a) shift back by pressing Shift+Tab, b) try another shortcut (some do work). see also Bug 157496: Alt+[Key] shortcuts for menu items do not work.
Today (Kate v 22.08.2), it's
Settings > Configure Keyboard Shortcuts > Type "terminal" in Search box >
edit shortcut for "Focus Terminal Panel".
For me, the default was Ctrl+Shift+ F4, while F4 hid the terminal.
I swapped them because it's more convenient for me.
The focus shift is only visible by appearance of the cursor changing slightly.

Resources