0

I have the following mappings:

nnoremap <C-,> :tabe ~/.config/nvim/init.vim<cr>
nnoremap <C-/> gcc

Neither of these mappings is working - they both do nothing. I have a plugin called vim-tmux-navigator that defines mappings <C-h/j/k/l> to navigate [neo]vim splits and tmux panes, and those mappings work. But no Ctrl mappings that I put in my init.vim work. This is true both inside and outside of tmux. I am using wsl on windows 10, but the mappings also don't work in the regular windows console or conemu, so it's not a wsl or tmux issue.

Update:

I just tested it again and other Ctrl + [letter] mappings, such as <C-h> or <C-b> do work, just not <C-/> or <C-,>. Not sure what the deal is.

8
  • I don't think vim recognizes Control-, (probably because so many terminals don't). Can't find the right help page though
    – D. Ben Knoble
    Commented May 11, 2020 at 23:02
  • 1
    I didn't see your other posts here so: Welcome to our site :) Here is a complete answer I made to help users debug their mapping issues by themselves, could you have a read and edit your questions with have you have tried to find the issue please?
    – statox
    Commented May 11, 2020 at 23:08
  • @statox I have read the information at the link you suggested. Wsltty does support ctrl mappings, because the mapping for copy in wsltty is ctrl+insert. However, wsltty intercepting the mapping doesn't make sense either, because pressing it outside of vim does nothin. Plus, this isn't the only ctrl mapping that doesn't work. None of them do. Commented May 12, 2020 at 15:44
  • Actually, I appologize, I misspoke. I have the vim-tmux-navigation plugin, and it uses ctrl-h/j/k/l to move between vim splits and tmux splits. Those mappings do work. But I also have a mapping <C-/> to toggle comment (nnoremap <C-/> gcc), and it doesn't work either. Commented May 12, 2020 at 15:47
  • I'm not familiar with this terminal and never used the vim-tmux-navigation plugin but here are a few things which come to my mind: If none of your mapping work then the problem probably doesn't come from vim: Is it possible that tmux is intercepting the mappings? (Maybe a messy leader key or something). I think your best bet is to run vim outside of tmux in another terminal and make one mapping work. This should help you to pinpoint which element is causing the issue.
    – statox
    Commented May 12, 2020 at 16:31

1 Answer 1

3

In order for a mapping to work, Vim has to recognise the keycodes that your terminal is sending. To find out what your terminal is sending, try typing the following to enter insert mode and insert the keycode into the current buffer:

iCtrl-VCtrl-,

If a regular comma is inserted, then this is what your terminal is sending to Vim, and there is no way to map <C-,> separately without reconfiguring your terminal to send something else instead.

If some other sequence of characters is inserted, then you can create a mapping by using the same Ctrl-VCtrl-, keystrokes to enter this sequence of characters as the lhs of your mapping (in place of the <C-,> you tried.

If nothing is inserted, then your terminal isn't sending anything to Vim when you press Ctrl-,. Again, you will need to reconfigure your terminal in order to use this key combination in Vim.

Further Details

If you are wondering why your terminal might send a comma when you Ctrl-,, you need to understand how the Ctrl key actually works within terminals.

Historically, the Ctrl key was used to enter the Control Characters that make up the first column of an ASCII table. It worked by clearing the 6th and 7th bits of the keycode generated by the key normally. So pressing the Ctrl key when you press L converts binary 11 01100 into binary 00 01100 or an FF (form feed).

However, take a look at the other entries in the same row as FF and <C-l>. Clearing the 6th & 7th bits of these will also result in a FF. So <C-L> is identical to <C-S-L> and, notably for your purposes, <C-,>.

It's not especially useful to have three separate keychords all map to the same control character, so, when pressing Ctrl along with a character in the second column — such as the comma — most terminal emulators either send the character unmodified, or map it to some other sequence of characters.

4
  • Thanks for the answer, however it's not working for me. i<C-v><C-,> adds nothing to the buffer - not a comma, not a raw character, nothing. i<C-v> backspace adds <BS>, i<C-v><C-/> adds ^_, but i<C-v><C-,> does nothing. Commented May 15, 2020 at 15:12
  • @ThaddaeusMarkle That means your terminal isn't sending anything to Vim when you press <C-,> If Vim doesn't get any event, it can't possibly map the event to anything! You'll have to reconfigure your terminal in order to use that key combination in Vim, I'm afraid.
    – Rich
    Commented May 15, 2020 at 16:32
  • ok. I'm using wsltty, and I didn't see anywhere in the settings that let me change anything to do with a <C-,> keybinding. Do you know anything else about this? Commented May 16, 2020 at 22:20
  • btw, wsltty is just mintty for wsl, so the config options, at least pertaining to keybiding options should be similar or identical. Commented May 16, 2020 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.