Question

I am trying to use org-mode and whenever I press Crtl+return emacs does C-J instead. I know this because when I use c-h k and then press crtl+return, emacs shows: "It is bound to C-j." Is there anyway I can make it register ctrl+return so I can insert headings?

I am using emacs23 through the terminal on ubuntu 12.04 x64. When I do this on my windows machine it does insert a new heading.

Was it helpful?

Solution

Possibly. As @phils says, C-Enter is usually not a valid sequence for the vast majority of terminal emulators. This is because when you press a key, or key combination, the terminal sends a sequence of characters to the relevant application. Pressing a sends a, whereas Enter sends CR - carriage return (otherwise known as ^M, \r or \015).

What sequences are actually implemented in modern terminals is mostly just a hang-over from the earlier, physical, terminals that they emulate (notably the VT-100). These machines didn't allow the use of Ctrl in conjunction with every key, such as the function keys, for example, so C-F1 was not possible and didn't have an escape sequence defined. Similarly, there is no control sequence for C-Enter, so when you press it, the terminal ignores the Ctrl and just sees the Enter.

You may, however, be able to define your own escape sequences in your terminal, which you can then bind to the correct key combinations in emacs. See here, for example. I was able to use this method to be able to use C-Enter. Unfortunately, this is still a bit of a pain, as it requires a lot of configuration and you may still be unable to use some sequences (C-M-% doesn't work in konsole for me). As with @phils, I've taken to using the GUI, but I'd love to have better integration with my terminal.

OTHER TIPS

That's not a valid sequence for most terminals, I'm afraid, so they simply can't send it to Emacs.

If you run GUI Emacs instead, the key bindings will work.

Thomas Dickey's xterm is the only terminal software I know of which can (I think) support all the normal Emacs bindings. If you're okay with compiling that, then you could try it with the following .Xdefaults-(hostname) (or .Xresources if you re-merge after editing) to get basic support working:

XTerm*metaSendsEscape: true
XTerm*modifier: meta
XTerm*modifyOtherKeys: 1

You actually need XTerm*modifyOtherKeys: 2 to fully extend the sequences (otherwise you still can't type the likes of C-M-%), but by default that setting will break most key sequences, and right now I couldn't tell you how to configure things correctly for that setting (the only example I've seen -- xterm-extras.el as mentioned on the wiki and available in the easymacs download -- didn't work for me).

I mostly use GUI Emacs, but I'd love to get this working properly, so if anyone has had success with xterm-extras.el or similar, please do speak up.

If you're willing to install an Emacs package and configure your terminal, I wrote an Emacs package which can teach Emacs and terminals how to properly recognize all PC keyboard keys and modifier key combinations:

https://github.com/CyberShadow/term-keys

Its default configuration enables encoding the CtrlReturn combination, which allows Emacs to distinguish it from CtrlJ.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top