mbl
mbl

Reputation: 925

How to rebind ctrl-space in vim running inside Windows Terminal Preview?

So it seems like ctrl-space is being incorectly translated into ctrl-@ by the Windows Terminal and I was wondering if there's any workaround for this? I've seen answers to this similar problem for other terminals but they don't seem to work.

Upvotes: 1

Views: 1332

Answers (2)

leaf
leaf

Reputation: 1764

Autohotkey is a good company for vim in Windows. It can map ctrl-space to any other keys and send them to vim by running scripts.

https://www.autohotkey.com/docs/Hotkeys.htm#Intro

AHKscript like(not tested)

^Space::
send {Ctrl}g
return

Then in vimrc

nnoremap <c-g> ...

Upvotes: 0

bk2204
bk2204

Reputation: 76794

This is fundamentally a limitation of the way that most Unix terminals work. The control keys map onto a limited set of characters, so Ctrl-@, Ctrl-Space, and Ctrl-` all map to the same thing and work the same way. This occurs in terminal emulators and the VT running on real Linux systems as well.

It is possible that other terminal emulators have an option for this, but the Windows Terminal attempts to emulate the xterm-256color terminal type, which implements the behavior you're noticing. Even if other terminal emulators do support it, that doesn't mean that programs running in them do; they might receive such a sequence and not know what to do with it, especially if TERM is set to a terminal type that doesn't support the distinction.

According to the Windows Terminal issue tracker, they are aware of this and there is a possibility they may pass these keys in the future using some xterm-specific sequences, but currently this doesn't work. I'm not sure that even if they did implement it that it would work as you expect in Vim, although it's possible it might.

You can either remap Ctrl-@ if you aren't using the existing functionality or just use another key.

Upvotes: 1

Related Questions