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

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


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.


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.