36

Is there a way to set Emacs-like keyboard shortcuts (at least the subset mentioned below) for the whole OS? This is possible in some apps such as the terminal, Emacs (go figure :) and additionally through special plugins in some other apps (Eclipse), but I got so used to C-f-ing through text and never having to jump to arrows that I'd like to be able to do this system-wide so that I can do it whenever I'm typing - e.g. searching for songs in Rhythmbox, typing stuff into the dash or the HUD, writing mails in Thunderbird or Gmail... The combos I'm most interested in are:

  • C-f - forward
  • C-b - backwards
  • C-a - home
  • C-e - end
  • C-d - delete
  • C-k - delete line

(note for non-emacs users - C means Ctrl)

metakermit
  • 2,600
  • 3
  • 28
  • 34

4 Answers4

25

Based on: https://superuser.com/a/516847/205010

  1. Install gnome-tweak-tool: sudo apt-get install gnome-tweak-tool

  2. Open it: gnome-tweak-tool

  3. Go to Keyboard and Mouse and change Key Theme to Emacs

Eyal Levin
  • 541
  • 7
  • 13
  • 1
    this is pretty cool, but lots of stuff doesn't work, i.e. C-b, C-k etc. the solution is probably pulling everything into emacs, i.e. browser, email etc. rather than trying to push the key bindings out beyond emacs – bph Feb 18 '16 at 09:11
  • Where does it not working? In my case it works most of the time pretty well. – Eyal Levin Feb 21 '16 at 09:48
  • It seems that if an app implements an equivalent shortcut then that takes precedence. Which is awkward – bph Feb 21 '16 at 19:34
  • 1
    I don't think it happens for all apps. I encountered in Chrome a few times that the global Emacs shortcuts took precedence over the specific web app shortcuts. – Eyal Levin Feb 22 '16 at 10:21
  • my test case was using yahoo mail and gmail in a firefox browser. in both cases C-a C-e C-f C-p C-n worked as expected, but C-b toggled bold font, and C-k brought up a link dialog. So for my particular application it is a bit hit and miss - i'll have to give chrome a try and see if its any different – bph Feb 22 '16 at 11:12
  • @bph: you can unmap default FF keybindings using the https://addons.mozilla.org/en-US/firefox/addon/s3menu-wizard/ add-in. This has enabled me to unmap the default FF bindings for CTRL+U and CTRL+K so I can erase the content of the search field without loosing the clipboard! – sxc731 Aug 16 '16 at 09:40
  • This will not work if your running `emacs -nw` – Pedro Luz Oct 01 '18 at 16:36
  • 2022: in "Tweaks" it's under "Keyboard" and called "Emacs Input", second in a short list of toggles/controls. – Williams Apr 29 '22 at 21:21
17

I managed to solve the problem by using AutoKey, as recommended in this answer. Some of my phrases are:

content                     |   hotkey             |   description
---------------------------------------------------------------
<ctrl>+f                    |   <ctrl>+<alt>+f     | replace the find operation
<home>                      |   <ctrl>+a           | begining of line
<end>                       |   <ctrl>+e           | end of line
<left>                      |   <ctrl>+b           | back one letter
<right>                     |   <ctrl>+f           | forward one letter
<delete>                    |   <ctrl>+d           | delete one letter
<home><shift>+<end><delete> |   <ctrl>+k           | kill line

(yeah, the kill line combo was nasty to find :)

You could go on replacing stuff, but I don't want the mental remap to grow to large (e.g. ctrl+n doesn't open a new window, but goes to next line). All in all AutoKey is a cool app!

Anyway, now I've got the emacs ergonomy of never having to leave the "letter keys" throughout Ubuntu - in every text box I am editing. Yeiii!

Update: as I got deeper into playing with AutoKey to fine-tune everything, I made quite some changes. You can see my complete AutoKey Ubuntu-Emacs configuration (and install it) in my dotfiles git repo.

metakermit
  • 2,600
  • 3
  • 28
  • 34
  • So I tried the forward one word +f but it kept clashing with opening a file in emacs. Did you face that problem? how did you solved it? – Sambatyon Jan 16 '18 at 19:27
6

There is another solution not involving third-party apps posted here emacs keybindings in ubuntu 12.04

Ev Dolzhenko
  • 4,259
  • 1
  • 14
  • 5
  • Using this method will not work in applications such as Thunderbird, where Ctrl+F will be interpreted as "Find String" rather than "Move Cursor Forward". – holocronweaver Jan 10 '14 at 23:45
  • @holocronweaver true indeed, I have given up on getting Emacs keys working in Thunderbird sadly, but most of the other inputs (notably in Chrome) almost work. I can't help but feel that the AutoKey solution is road to never ending fiddling and frustration too :) That said have you tried the solution proposed by kermit666 and if so - did it work for you? – Ev Dolzhenko Jan 12 '14 at 22:20
  • After a bit of editing to make it suit my tastes, the AutoKey solution has worked fairly well in Firefox and Thunderbird on Ubuntu 14.04. Still more testing to do. – holocronweaver Jan 13 '14 at 02:55
0

gnome-tweak-tool has been replaced with gnome-tweaks:

  1. Install gnome-tweaks: sudo apt-get install gnome-tweaks.

  2. Open it: gnome-tweaks.

  3. Go to Keyboard & Mouse and switch Emacs Input on.

Evgeny Mikhaylov
  • 129
  • 1
  • 10