[IPython-dev] Change the "Ctrl+k" keyboard shortcut

Paul Ivanov pi at berkeley.edu
Tue Apr 22 21:36:26 EDT 2014

darcamo at gmail.com, on 2014-04-22 22:07,  wrote:
> IPython 2.0 is awesome and I started using it even before the official
> release. However, there is one thing that keeps biting me: the "Ctrl+k"
> keyboard shortcut.
> For me this is a very important browser shortcut that I use often and I
> start using it some years ago. In Firefox it puts the cursor in the
> search bar, while in Chrome it puts the cursor in the address bar, but
> preceded by a "?" character to indicate that a search will be made.
> The problem is that this shortcut is set in the notebook to move the
> cell up. I'm often working in a notebook and then I want to search for
> something in the Internet. Due to muscle memory I type Ctrl+k and start
> typing but since the notebook captured this shortcut then all kinds of
> weird stuff can happen with my notebook (due to me "writing" what I
> wanted to search). In the end I can lose a lot of time fixing any
> possible problems.
> How can I change this shortcut (maybe to Ctrl+K)? I could not find the
> correct way in http://ipython.org/ipython-doc/stable/notebook/index.html

To remove the shortcut, add this to your custom.js:


There's also a similar add_shortcut method which you can use to
put the functionality back. It occured to me that a very common
scenario is one of wanting to remap keyboard shortcuts from their
defaults to something else, and we currently do not make this
easy. I have opened https://github.com/ipython/ipython/issues/5702 
to help us keep track of this.

Note that even without this, ctrl-k works in the usual browser
manner when you are in edit mode - it's a ugly workaround, but if
you find yourself on someone else's machine, that little factoid
can help

(if you need help locating your custom.js, I covered that in this
post: http://pirsquared.org/blog/notebook-blink.html)

                  / \
                A*   \^   -
             ,./   _.`\\ / \
            / ,--.S    \/   \
           /  `"~,_     \    \
     __o           ?
   _ \<,_         /:\
--(_)/-(_)----.../ | \
Paul Ivanov

More information about the IPython-dev mailing list