Key escape sequences not working for tmux - vim

I have been using iTerm2 and vim for a while. I have experienced some issues when I needed to use key combinations such as CTRL-F10 and SHIFT-F10 inside a vim session running inside iTerm2. It is straight forward to define key bindings such as <C-F10> and <S-F10> for the GUI version of MacVim. No problems there.
However, it proved to be difficult to get the same key combinations in the terminal version of MacVim. I have solved this by using iTerm2's Send Escape Sequence functionality. Once I have defined CTRL-F10 as [21;5~ and SHIFT-F10 as [21;2~ in my iTerm2 profile, those were now working inside the terminal MacVim without any issues.
Recently, I have hit a new wall, when I decided to add tmux to the equation. I have noticed that those escape sequences are no longer working for a terminal MacVim running inside a tmux pane. That is my problem.
I have been focusing on the Send Hex Code option, which seems to be working. I tested it with some known hex codes such as 0x04 which is Ctrl-d and it works. The problem is that I could not find the hex codes for CTRL-F10 and SHIFT-F10.
So the solution is either make tmux receive my escape codes coming from iTerm2 or find the hex codes for the keys that I need to be working inside tmux.

Related

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.
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.
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> ...

Vimwiki C-Enter or S-Enter does not work in Gnome Terminal

I am trying out VimWiki. So far so good, but on Ubuntu 18.04, the Shift-Enter and Ctrl-Enter do not work [1]. Search on the net says Gnome Terminal interprets these key combos as the regular Enter key. So I believe I have to remap these keys to something else or find another terminal program. I have tried Terminator, but it works the same as Gnome Terminal.
[1] https://github.com/vimwiki/vimwiki
You can change the key mappings, or you can run Vim as a graphical application (gvim). You may have to install the relevant distribution package (such as vim-gtk3), it is sometimes split from the pure terminal application.
I suspect the author of this extension is using Vim as a GUI application because I don't think there are many terminals which preserve these key combinations.

gVim escape key does not work on windows 10

I recently started working with a windows machine and installed gVim, but somehow the escape key does not work - rendering gVim practically useless.
Is it possible that my computer sends out an unusual character for the escape key? Is there any way to test this hypothesis?
Or is it a common Windows (10) issue, that escape does not work as on other devices? Did anyone else encounter this strange behaviour?
I tried on linux4windows terminal and there it had the same result yesterday, but now the escape key works fine.
I know this is an old question, but I've been suffering this and finally found some time to dedicate to it.
The answer seems to be (for me at least), that if you hit Win to open the Start Menu and then type gvim, the first option is actually gVim Easy not gVim.
The difference is 'gVim Easy' starts with the -y switch:
-y Easy mode (like "evim", modeless)
If you launch gVim (as opposed to gVim Easy) then ESC works as expected.
I guess the "modeless" in 'Easy Mode' means there aren't normal (command) or insert modes, so there's no need to use ESC to switch between them.
I had the same issue with gVim 8.0. I updated to 8.1 and left all default settings (no remapping etc..). Now the escape key works again.

vim mapping ctrl-` or <c-`> to <c-w>w

I tried
inoremap <c-`> <c-w>w
and various combination, but nothing seems to work. Is cntrl-` already mapped?
Using Lubuntu 64 bit 16.04 : lxterminal
Attempted cntrl-v cntrl-` to find the character but nothing shows up.
FYI: I am attempting to make sure I can do same thing with my VSCode editor.
In a typical terminal, control` is an ASCII NUL (zero), which vim will not map. Using cat -v to make the result visible, you'd likely see
^#
which is a single character...
You'd have the same behavior for a few other keys which typically produce a NUL, e.g., controlspace, or control# (really!)
You can't map anything to Ctrl-Backtick because Vim won't recognize it no matter what you do.
Find another key combination.
As #romainl and #Thomas Dickey pointed out, you can't do this in terminal vim.
If you want this is in VSCode, just add this to keybindings.json and add this to the editable pane.
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "ctrl+`", "command": "workbench.action.navigateEditorGroups" },
]
This will work as VSCode doesn't have the same problem of interpreting ctrl` as your terminal.
Also, it might not be a good idea to use ctrl` as it is already being used for toggling integrated terminal
⌃` Toggle Integrated Terminal workbench.action.terminal.toggleTerminal
How to modify keybinding for VSCode
Is cntrl-` already mapped?
No. Even if a key combination is mapped, you can override it in vim.
Attempted cntrl-v cntrl-` to find the character but nothing shows up.
Now you know why
Well, as two other answers indicated. I could NOT find the key combo & I do NOT think I will; however, when using nyaoVim the key combos do work. So, it's just terminal issue.
A bit of pain to install but now everything pretty much works!

Mapping control keys in GVim without <c-> and i_ctrl_v

I've got a problem that I've already solved on the X-server level (BTW: I'm running Ubuntu 12.04) but not in GVim.
I have a German keyboard layout with the letters ö and ä where [ and ] are on a qwerty keyboard. But now I want to change vim's normal mode mappings so I can type ö and Ctrl+ö as if it were [ and CTRL+[, respectively. So I created an xmodmap file and mapped Ctrl+ö to CTRL+[. Now the xserver exhibits the right response (e.g. when I map Ctrl+ö to Ctrl+u I can erase the current line in xterm).
But somehow this doesn't work in gVim, and as far as I understand the gVim help it handles escape sequences like Ctrl+something in a special way (e.g. Ctrl+ö in insert mode yields a plain ö in contrast to the behavior in xterm). But I don't understand how to solve this. Can anyone help me?
EDIT:
I've noticed that it does work when I run Vim in my terminal emulator (which is guake), but not in GVim (which I want to get working).
If I understand you correctly try to use the langmap option like this:
:set langmap=ö[,ä]

Resources