Reputation: 15814
After running cat -t
, I tested the following cases:
ctrl
+ tab
added only a tab
space
ctrl
+ /
added ^_
ctrl
+ `
added ^@
ctrl
+ shift
+ backspace
deleted to the left (same behaviour as backspace
).
On the other hand, the following key bindings remain consistent:
ctrl
+ n
adds ^N
ctrl
+ y
adds ^Y
All alphanumeric characters [a-zA-Z0-9]
add the corresponding alphanumeric character
Is there a way to remap the key combinations to a preferred output? For example, in my first four examples above, I would like to remap them to the following:
ctrl
+ tab
to <C-tab>
(instead of TAB
)
ctrl
+ /
to ^/
(instead of ^_
)
ctrl
+ `
to ^`
(instead of ^@
)
ctrl
+ shift
+ backspace
to <C-S-backspace>
(instead of DEL
)
Background (TLDR)
I would like to run emacs -nw
when editing on a remote machine, but I notice that several key combinations are not inconsistently detected between running emacs
and emacs -nw
. Here are a few of the inconsistent key mappings, which I have verified using C-h k <key-binding>
in Emacs:
ctrl
+ tab
is detected as <C-tab>
in emacs
, but detected as TAB
in emacs -nw
.
ctrl
+ /
is detected as C-/
in emacs
, but detected as C-_
in emacs -nw
.
ctrl
+ `
is detected as C-`
in emacs
, but detected as C-@
in emacs -nw
.
ctrl
+ shift
+ backspace
is detected as <C-S-backspace>
in emacs
, but detected as DEL
in emacs -nw
.
Any ideas about how to send the proper key combinations to my window-less emacs? All of the inconsistently detected key combinations involve the use of ctrl
, but not all key bindings with control are inconsistently detected. For example, C-n
is consistently detected.
I am using Ubuntu 14.04, but this problem persists with Debian Wheezy as well. For terminal info, I have the following on all my servers and local machines:
[lucas@server]/home/lucas/bin$ echo $TERM
screen
[lucas@server]/home/lucas/bin$ echo $SHELL
/bin/bash
I usually run my sessions in tmux
, but this problem persists regardless of whether I am in a tmux session.
Upvotes: 4
Views: 1949
Reputation: 4235
I suspect your encountering issues at more than just one level. This means that you need to tweak configurations at different points/levels.
One of the first things I need to do when setting up a new machine is go through and remove or change key bindings all over the place. The main reason is because I make extensive use of emacs and these days, lots of things 'steal' they key strokes before they get delivered to emacs.
Note that I rarely run emacs in the terminal. I almost exclusively run emacs in its own window and have my environment variables, such as EDITOR etc set to emacsclient. This means I can open an emacs frame faster than opening a terminal and running emacs. Currently, I'm running Ubuntu Gnome , but am seriously considering switching back to either Sawfish or Stumpwm.
If you are going to run emacs within a terminal under gnome, there are three 'layers' you need to look at with respect to key bindings.
layer 1: The session (gnome) layer. Many 'standard' emacs key bindings can be stolen by the wm. I usually go into the keyboard settings option and either disable shortcuts which conflict with bindings I want to use in emacs or re-bind them to another key.
layer 2: The terminal emulator. This can vary a bit depending on the terminal you are using. In general, things are a little more restricted at this level due to the way terminal emulators translate the key press events and send them to the application. The terminal can also steal some key events. There is also the problem that some terminal emulators will comply more with the traditional 'console' interface than others, in which case, some key combinations possible at the xsession layer are just not possible at the terminal layer. For the gnome terminal, you need to look at the settings under 'edit->keyborad shortcuts' and and the compatibility section under 'edit->profile preferences'.
layer 3: In some cases, you may need to tweak the key translation table in emacs so that it understands the key translations sent by the terminal.
Is there a particular reason you want to run emacs within a terminal rather than as a native X11 client? There are sometimes reasons to do this (such as collaboration with remote co-worker using tmux). However, if there is no strong case to run under the terminal, I would strongly recommend running in GUI mode. This will eliminate at least 1 layer. I also find that face settings seem much more consistent when running native than when running under a terminal and you avoid some of the problems you can experience with emacs in a terminal and running external interfacing features, such as with ssh, tramp, etc.
Upvotes: 2