As I wrote recently, I’ve had a difficult time finding a Linux word processor that meets my day to day needs and also allows me to easily use Emacs keybindings.
After that post, I finally bit the bullet and manually configured at least a few of the more commonly used Emacs keybindings in LibreOffice Writer. As I mentioned previously, this process is made painful by the need to remap numerous conflicting default shortcuts along the way, while avoiding the creation of new conflicts with the application and the desktop environment.
Now that it’s done, though, I figured I share the fruits of my labor. The final solution is far from elegant, but is better than any of my own previous attempts, and I’ve reduced the number of unresolved shortcut conflicts I found in other solutions around the web.
Here’s the saved shortcuts file, which can be imported as-is into LibreOffice, in the event it’s helpful to anyone else. For the sake of posterity, I should note that it was created using LibreOffice v22.214.171.124, and I’m providing it, as usual, with no warranty express or implied:
Note that there’s no need to unzip the file—LibreOffice expects this file format. To import it, download the file, open LibreOffice Writer, go to ‘Tools > Customize > Keyboard’ and click the ‘Load’ button. Select the file, click “Okay,” and you’re done.
Here, specifically, are the Emacs keybindings I implemented, along with where to find them under LibreOffice’s ‘Tools > Customize > Keyboard’ interface if you want to reset them or mess with them yourself:
C-f: forward one character (Navigate > Go Right)
C-b: back one character (Navigate > To Character Left)
C-n: next line (Navigate > To Line Below)
C-p: previous line (Navigate > To Top Line)
M-f: forward one word (Navigate > To Word Right)
M-b: back one word (Navigate > To Word Left)
C-a: beginning of logical line (Navigate > To Paragraph Begin)
C-e: end of logical line (Navigate > To Paragraph End)
C-v: next page (Navigate > Next Page)
M-v: previous page (Navigate > Previous Page)
M-d: kill rest of word (Edit > Delete to End of Word)
C-k: kill rest of logical line (Edit > Delete to End of Paragraph)
C-w: kill selection (Edit > Cut)
M-w: copy selection (Edit > Copy)
C-y: yank clipboard content (Edit > Paste)
Note that I opted for logical lines, not screen lines, when it came to keybindings like C-a, C-e, and C-k. This means that a line goes on until a carriage return, as opposed to ending each time the text wraps. It’s possible, though, to have it either way if you care to futz with the shortcut configurations.
As indicated, implementing the above keybindings meant remapping some of LibreOffice’s default shortcuts. Below are the new keybindings I gave to shortcuts that were overwritten by my new configuration:
Create New Document (Application > New)
Print Document (Documents > Print)
Close Document (Documents > Close)
Center Text (Format > Centered)
Make Text Bold (Format > Bold)
Select All (Edit > Select All)
Redo (Edit > Redo)
Now: C-Shift-Z (Common “redo” shortcut for other applications)
Paste (Edit > Paste)
Now: C-y (Another Emacs keybinding)
There is one still-broken keybinding. ‘M-w’ previously opened the “Window” dropdown menu, but is no longer mapped to this feature. I’m sure this is fixable, but I haven’t yet found the menu option or configuration file for remapping LibreOffice’s menu shortcuts.
Note that, while the above replacement bindings are verbose, making them so prevents a snowball of other shortcut conflicts that would likely end up being worse in the long run. And I tried to be consistent, so as to make the remappings easy to remember.
If, at any time, you want to undo these keybindings and go back to the LibreOffice defaults, you can use the ‘Tools > Customize > Keyboard’ interface in Libreoffice to change them back. This requires a lot of work by hand, however.
The simplest way to get back all the original LibreOffice keybindings is to close LibreOffice. Then, locate and delete the ‘registrymodifications.xcu’ file inside your LibreOffice settings folder (usually ‘~/.libreoffice’ or ‘~/.config/libreoffice’; and make a backup first, for the love of God—don’t just wipe it because I told you to), then restart LibreOffice. ‘registrymodifications.xcu’ houses the tweaks we’ve made, so deleting it gets rid of them instantly, and restarting LibreOffice will regenerate the deleted file with default settings. The downside of this, though, is that it has the potential to simultaneously destroy other customizations you may have made to LibreOffice. If you want to do more precise surgery on registrymodifications.xcu, check out this LibreOffice help forum thread, which gives instructions for excising keybinding modifications from the file.
In any case, please enjoy, and feel free to post your own fixes/improvements/solutions in the comments.