Emacs cua-mode Keybinding Problems

By Xah Lee. Date: . Last updated: .

few weeks ago we covered Emacs: Python Shift Indent. For example, you can press 【Ctrl+c <】 to move a block of code to the left. However, if the keys don't work for you, that's because you have cua-mode on. (thx to boostjam for finding the cause)

cua-mode is great, in that it makes emacs usable for a whole class of people. However, deep is the problem of hacking over emacs keys. (emacs uses 【Ctrl+c】 as the starting key sequence for mode-specific commands.) When you have text selection, the 【Ctrl+c】 key will do copy. Otherwise, it waits for you to type other keys to send to emacs.

this solves a lot problem, but not all. The python indentation keys is a example. The command requires text selection. So, when you have selection then press 【Ctrl+c <】, but cua-mode will catch the 【Ctrl+c】 part and do copy and deactivates your text selection, then the < is inserted.

the other solution provided by cua-mode is to press the complete key sequence in 0.2 second. Press 【Ctrl+c <】 in 0.2 second is hard. You can adjust the timing, but that introduce other problems.

the third work-around is holding down Shift, for example, 【Ctrl+Shift+c Shift+<】, but this solution won't work if emacs is running in terminal.

I've thought about solving this in the context of ErgoEmacs keybinding over the years, but everytime after some great idea false starts, it ultimately came to this: you just can't make one key do 2 things without getting into the realm of hack.

Another workaround with the copy paste keys is using ErgoEmacs keybinding but turn off the “cua-mode”. This means, the cut copy keys is still {x, c}, but you need to press Alt instead of Ctrl.

In ErgoEmacs (the emacs distro), “cua-mode” is on by default. I really wanted to turn it off, but turning it off means people won't be able to use 【Ctrl+c】 for copy, and that defeats one of the principle purpose of letting anyone use it without thinking.

of course, i can turn it off, then add in documentation or in a message, saying things like “you can press Alt+c for copy, or you can turn on cua-mode and but and …”. blab blab blab. That's what the geeks wont to do. By the time you finished explanation, the user's already gone.

Emacs keys, is the number one inducer of Repetitive Strain Injury. About every month, you see people discussing it on tech sites such as StackOverflow, Reddit, …, and for decades before, was on mailing lists and newsgroups. Emacs's keys is not just RSI risk , but it's also the most inefficient, not much better than random key set.

If we can change the keys, all things would be solved. But no, we can't. There's a pride and identity issue. Emacs was here first!

(thx to Matthew Fidler)

ergoemacs-mode Solves The Problem

Matthew Fidler has solved the problem, by not requiring cua-mode, but ergoemacs-mode dive deep into emacs to remap the keys. You can config it so that:

For detail, see the doc: https://ergoemacs.github.io/cua-conflict.html

(much thx to Matthew Fidler for his incredible great work.)

Like it? Buy Xah Emacs Tutorial.