ubuntu,windows-10,bash,keyboard-shortcuts,emacs – Windows 10 Linux Bash Shell Ctrl+Space Doesn’t Set Mark in Emacs

bashemacskeyboard shortcutsUbuntuwindows 10

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.

Best Answer

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.

Related Question