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

Darlan Cavalcante Moreira darcamo at gmail.com
Tue Apr 22 21:54:18 EDT 2014

pi at berkeley.edu writes:

> 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:
>     IPython.keyboard_manager.command_shortcuts.remove_shortcut('ctrl-k')
> 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)
> best,

Thank you Paul, I'll remap the shortcut.

I actually kind of knew that Ctrl+k worked in edit mode and most of the
time I'm in edit mode. What I din't know before is that IPython uses the
"Ctrl+k" shortcut to move cells and only after having problems with
cells in wrong places is that I found out this shortcut in IPython.

Darlan Cavalcante Moreira
darcamo at gmail.com

More information about the IPython-dev mailing list