Windows 10 linux bash shell ctrl+space doesn't set mark in Emacs

7,007

Solution 1

There are no solutions to this, in terms of making Ctrl-Space pass through the Bash terminal, at the time of this writing (1 Sep 2016)—but there is a workaround that may be sufficient for many users: use PuTTY to connect via SSH, which forces handling of Ctrl-Space. (In tty mode, it's impossible to distinguish Ctrl-Space from Ctrl-@, because they are the same character code, but that shouldn't be an issue, as by default Emacs is set up to handle set-mark-command that way.)

  1. Install the OpenSSH server with sudo apt-get install openssh-server. If it was already installed, remove it (sudo apt-get remove openssh-server) and then reinstall it to get the config files reset.
  2. Edit the /etc/ssh/sshd_config file (with sudo), as follows:

    • If there is an uncommented line setting PermitRootLogin, comment it out. Add a line PermitRootLogin no.
    • Add a line AllowUsers USERNAME, replacing USERNAME with your Linux username (if you don't know what that is, run the command whoami at your Bash prompt).
    • Ideally you should set up passwordless authentication using SSH keys, but how to do that is out of the scope of this question (there are many guides available; search the web for "passwordless ssh-keygen"). In the meantime, add or uncomment the line PasswordAuthentication yes.
    • Set UsePrivilegeSeparation no; likely you will find a line in the file saying UsePrivilegeSeparation yes; just change the yes to no and save the /etc/ssh/sshd_config file.

    If something goes wrong here, you can restore the file by repeating step #1.

  3. Startup the SSH server with the command sudo service ssh --full-restart.
  4. Using PuTTY (download here), login with localhost in the Hostname field, everything else left as default. You'll be asked to enter your Linux username and your password.
  5. Run emacs. Ctrl-space will set the mark as desired.

(Note that the steps above will not, by themselves, make your system able to accept SSH connections from other hosts. To do that, you will also have to change your Windows firewall rules to allow inbound TCP port 22.)

In another answer you said, "but putty is not a local terminal." I'm not sure if you weren't aware that you could use localhost in this way, or if you were dismissing PuTTY because of the greater overhead versus a local terminal. If the latter, I wouldn't worry, an interactive SSH session is an extremely lightweight load. (It's certainly much less load than running an X Window System so you can run a GUI Emacs or an xterm!)

The only real disadvantage to running this way versus a straight terminal is that paste events are sent letter-by-letter, as if you typed the contents of the clipboard very fast, which may cause electric pairs, indention, snippet expansion, etc. to fire. (Paste should not cause key-chord commands to fire, as there's logic to detect an in-progress paste and disable key-chords until the paste is finished.)

And there's at least one very big advantage over the standard Bash terminal, too: mouse events are supported by PuTTY in a form that Emacs can respond to, so, ironically, you can move the point with the mouse in PuTTY even if you can't with the local terminal.

Solution 2

I use ConEmu. There is no elegant way, but it can be solved using the macro.

  1. Open "Settings" (Click on the icon on the top).
  2. Click on "Keys & Macros".
  3. On the right hand side, scroll down till you see "Macro 01" .. "Macro 32" options, and pick any one that is available (does not matter).
    Let's take Macro 01 for this example.
  4. Select "Space" in 1st dropdown menu.
  5. Select "Ctrl" in 2nd dropdown menu. Leave the remaining 2 dropdown menus untouched.
  6. Paste below in the GUI Macro field:

    keys("\e");keys("x");keys("s");keys("e");keys("t");keys("-");keys("m");keys("a");keys("r");keys("k");keys("-");keys("c");keys("o");keys("m");keys("m");keys("a");keys("n");keys("d");keys("\n")
    
  7. Above basically sends M-x select-mark-command string to emacs. Now click "Save settings".


It should look like this in the end:

enter image description here

Solution 3

This project allows you to use MinTTY as an alternative terminal: https://github.com/mintty/wsltty. It's derived from PuTTY, but doesn't require SSH. And like PuTTY, it handles Ctrl-space just fine.

Solution 4

When running showkey -a in windows/ubuntu-bash console it shows that ctrl+space just sending a plain space.

And it's the same issue with ssh session to any other linux machine ctrl + space is sent as plain space.

The same behavior is with any other windows based terminal ( conemu, consolez, MobaXTerm ) - except putty can handle this well but putty is not a local terminal.

I think Windows terminals doesn't have mappings for some sequences. The same problem is with other combinations like ctrl+1 ctrl+2 .. etc. Here required is terminal which can handle the keyboard mappings for it self like putty for example.

I believe this issue should be fixed in future releases of the windows bash terminal.

Solution 5

This issue is now fixed in Windows 10 build 14965. Check:

[Environment]::OSVersion

And install updates if you haven't!

Share:
7,007

Related videos on Youtube

Pawel Wodzicki
Author by

Pawel Wodzicki

Updated on September 18, 2022

Comments

  • Pawel Wodzicki
    Pawel Wodzicki over 1 year

    In Windows 10 I installed Subsystem for Linux Bash. But I have a problem with shortcut in Emacs Ctrl+space doesn't set mark point.

    What i tried and didn't help:

    • I tried to uncheck "enable Ctrl key shortcuts" in properties menu for windows console

    • I tried to use different terminal ConEmu without success.

    I wonder if this is somehow related to ubuntu which has similar problems with ctrl + space , and windows linux bash is using ubuntu repositories.

  • Jim Hunziker
    Jim Hunziker over 7 years
    Even worse, it doesn't seem to pass ctrl-@, either, which is the other binding for set-mark. If someone's in a real bind, they can use M-x set-mark-command. The right thing to do for now, probably, is to set a key binding to something else.
  • Trey
    Trey over 7 years
    @JimHunziker Given that set-mark-command is probably the most-frequently-used command in Emacs (aside from self-insert-command), retraining one's fingers for that is a really, really steep ask—especially if you've been using Emacs for 25+ years like me.
  • Pawel Wodzicki
    Pawel Wodzicki over 7 years
    @Trey added another answer, if you don't mind running xming on windows
  • Trey
    Trey over 7 years
    @PawelDubiel See my answer just added. (I gave more detailed instructions than required for you to help later readers.) You dismissed PuTTY for some reason, but didn't say what that reason is. It's certainly an option that puts much less load on the system than xming + an X terminal.
  • Trey
    Trey over 7 years
    Why is this a superior workaround to using PuTTY? If you were going to run Emacs in GUI mode, I'd understand it, but your use of -nw makes it run in a terminal, just like it would with PuTTY, except you're now having to run an entire second windowing system—from my quick test, that's going to cost you almost 500 MB of memory beyond running an sshd and PuTTY and will have a similarly higher CPU cost.
  • Pawel Wodzicki
    Pawel Wodzicki over 7 years
    @trey 500MB are you sure? on my system is exactly 5mb
  • Trey
    Trey over 7 years
    Ah, I misread the units, you're right. But the comparable sshd + PuTTY number is about 25% of the other number, whatever it is ;-)
  • chriskelly
    chriskelly about 7 years
    works like charm. Fantastic!
  • djsmiley2kStaysInside
    djsmiley2kStaysInside about 7 years
    Please add more detail to your answer - the link may stop working at some point at which your answer becomes useless.
  • fakedad
    fakedad almost 3 years
    The comments on that GitHub issue and my own experience suggest that, unfortunately, the bug is back.