Emacs n00b here, I’ve fiddled a bit with it in graphical mode and so far I’ve found it great. I wanted to give the terminal version a try and found out that there’s a few annoying behaviour differences, in particular with shift-selection.
In graphical mode I can combine shift selection (ie holding shift to set a mark) with the arrow keys, the control key (to select whole words) or the origin or end keys (to select the whole/a large part of a line).
In terminal mode the keys work fine on their own (I can select regions while holding shift and moving with the arrow keys*, C-left/right allows me to jump whole words, origin and end bring me where I want to go) but I can’t combine them (can’t select whole words by holding shift and C-arrowing, or select the remaining part of a line with shift-end or shift-origin).
I also found that C-backspace didn’t work (ie didn’t erase the whole word) in console while it does in window mode, though I read about M-backspace after looking for a solution.
I searched as thoroughly as I could but could not find how to get the terminal version to behave like the graphical version… Lots of people seem to ask questions about Emacs’s shift selection but none of them have quite the same problem… Can someone explain where those behaviour differences come from?
Thanks in advance.
*Though, holding shift, if I go down (with the arrow key) to select whole lines, I can’t go up again to unselect them (” is undefined”).
[edit /] Okay, so obviously this comes from the fact that my terminal doesn’t have the same shortcuts as graphical Emacs does. Fair enough. I see a couple of solutions here:
- getting used to default Emacs shortcuts
- filling my .emacs with global-set-key’s. Although I tried
(fset 'select-to-end [(kbd "C-
<spc><end>")]) (global-set-key (kbd "S-<end>") 'select-to-end)
but it doesn’t work as I intend it to -_-
The short answer is “if you’re happy using different keystrokes, that might be easier”. Personally, I’m a little neurotic about my keybindings and configuration, so I rarely go with this one; in particular, it’s frustrating when emacs modes override your bindings. (I don’t know if you’ve yet discovered that
global-set-keyreally means “let anyone in the universe stamp on my keybinding”.)The longer answer to your question is “someone along the chain is ignoring your control characters, so you need to figure out who it is, fix it, and then repeat”. For the keybindings you’re talking about here —
C-S-<arrows>— you can definitely get this to work; if you want something like\C-~, you’re going to have a much harder time. (The issue is that some bindings didn’t make sense in legacy terminals, so you basically have to use a nonstandard set of control codes to transmit the key combination, and then teach each program to recognize it. This is usually where a termcap comes in, since it’s a common language for teaching programs about key events.)Here are the steps I usually take:
\C-vand then hit a key to insert the literal keystroke (at least in bash) — start by doing this with C-left, S-left, and C-S-left. Confirm that you’re getting three different control codes.TERMisxterm, the termcap should be fine. I don’t know what terminal program you’re using, but it may have its own key configuration. (For instance, I use a mac and use iTerm2, which is usually my first stop.) If you’re going to be spending time at a terminal anyway, you should definitely take the time to read the readline manual and play with your.inputrca bit.\C-qin emacs to do the same thing\C-vdoes in bash, or use\C-h kto find out what the default bindings are. Again, start by making sure emacs sees distinct key events for the combinations you’re interested in. If not, you’ll probably want to start by looking atterm/xterm.elin yoursite-lispdirectory and modifying it to your liking.If you’re using
tmuxorscreen, they also get a hand in this, and can usually be tamed. The process for finding those problems is the same as bash — use\C-vandman tmuxto figure out how to get your extra keybindings.