Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Qt editing keybindings #496

wants to merge 1 commit into from

3 participants

Martin Spacek Evan Patterson Fernando Perez
Martin Spacek

Add Ctrl+Backspace and Ctrl+Del keybindings to delete to start and end of current word. This is what most people (or at least I) expect in a normal text widget. For some reason, Alt+Backspace and Alt+D are the current keybindings for this, which I find a bit strange. Anyone know why? I've left those as they are.

Also, on my local branch, I use Ctrl+D to quickly close the window, ala a normal terminal. Not sure how others would feel about this. Currently, Ctrl+D is bound to QtCore.Qt.Key_Delete.

I don't suppose keybindings will be user configurable in the near future, will they?

Evan Patterson

The bindings we have currently were chosen specifically because they are the standard bash keybindings. Since the Qt console is first and foremost a console widget, we would like to keep those as the defaults.

That said, having user configurable keybindings would be a great enhancement. Unfortunately, I don't think that's likely to be done in the near future. At least, I don't have the spare cycles for it.

You are, of course, welcome to take a stab at this yourself. If you'd like some guidance, just ask. Otherwise, feel free to open a feature request issue, and hopefully it will get picked up eventually.

Martin Spacek

Hm, I don't exactly have lots of spare time, but I think I could actually see myself getting this done fairly quickly. I'm pretty comfortable with Qt and its keybindings from working on my own code.

I would need some guidance though. I guess this would require giving official names to each action, and some kind of dictionary mapping config key names into proper Qt key names. Maybe someone can propose a couple of keybinding examples, like how to designate in a config file (*.py ?) the key command for delete_previous_word, to establish a convention that I could simply extend to all the existing actions.

Fernando Perez

It seems to me the right way to do this is to wait for #492 to get merged (almost ready). At that point, the Qt console will have a proper config file support, and it will be much easier to experiment.

This is, for example, the format used by LyX:

\bind "C-e" "line-end"
\bind "C-a" "line-begin"
\bind "C-d" "char-delete-forward"
\bind "C-i" "font-emph"
\bind "C-S-t" "buffer-update pdf2"

which follows how Emacs describes keybindings as well.

I don't think the \bind syntax looks particularly nice, but the key descriptions seem fine, and it's just a matter for us of sorting out how to describe actions.

But it seems to me that this should become a separate issue, since your pull request here can be reviewed/merged on its own merits as an existing improvement. So I suggest we clear this PR as-is, and if you're interested in tackling this one, perhaps open an issue for the design discussion, from which you can then link to a PR once you have code ready.

You're also welcome to ping for more feedback on the -dev list, as always (sometimes people don't respond to open issues right away).

Martin Spacek

OK, I've opened up issue #502 for configuring qt key bindings.

Fernando Perez

Since #502 will be far more work than simply adding these few lines that will likely make the console more usable for many folks who don't come from Emacs, I'm in favor of merging this for now, so that the 0.11 experience out of the box is as good as possible. Later we'll work on a more generic framework for this.

Evan Patterson

That's fine by me.

Fernando Perez

Thanks, @epatters! I'll then go ahead and merge this one now.

Fernando Perez

Merged; rebased to avoid a long merge handle for just one commit. Thanks for the code!

Fernando Perez fperez closed this
Martin Spacek

Great, thanks for the merge!

Damián Avila damianavila referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 1, 2011
  1. Martin Spacek
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 0 deletions.
  1. +6 −0 IPython/frontend/qt/console/
6 IPython/frontend/qt/console/
@@ -988,6 +988,12 @@ def _event_filter_console_keypress(self, event):
intercepted = True
elif key in (QtCore.Qt.Key_Backspace, QtCore.Qt.Key_Delete):
+ if key == QtCore.Qt.Key_Backspace:
+ cursor = self._get_word_start_cursor(position)
+ else: # key == QtCore.Qt.Key_Delete
+ cursor = self._get_word_end_cursor(position)
+ cursor.setPosition(position, QtGui.QTextCursor.KeepAnchor)
+ self._kill_ring.kill_cursor(cursor)
intercepted = True
elif key in (QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal):
Something went wrong with that request. Please try again.