WSL: Arrow keys don't work in vim while using bash from Cmder.
I discovered an issue when using Vim. It does not allow me to use the arrow keys at all and gives me an error in vim. This issue only occurs when you use bash from within Cmder. I’m using Cmder which uses ConEmu version 160914 [64].
Reproduce using the following steps:
- Start Cmder.
- Type in
bash(unless it’s your default shell). - Open a file in vim with
vim <filename>. - Type in anything and try to move around with the arrows.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 16
- Comments: 18 (3 by maintainers)
This worked for me
echo ':set term=builtin_ansi' >> ~/.vimrcIt took me some time and many unsuccessful attempts, but finally I managed to fix the issue while not breaking colors or any other things!
Instead of changing terminals and modes, I focused on key codes generated by the cursor keys and what Vim has mapped to the cursor movement.
TL;DR
To fix the cursor movement using the arrow keys, add the following commands into the
.vimrcfile:Tested in Vim 8.0 under Ubuntu 18.04 bash executed in ConEmu 191012 on Windows 10 Enterprise version 1809.
Note
Unfortunately, the key codes generated by the keyboard are different under Windows Console (e.g.
^[OA) and ConEmu (e.g.^[[A) so it may not work in both at the same time.Explanation
My goal was to find out what actual key codes the arrow keys are generating on my system and what key codes has Vim mapped to its cursor movement actions.
Key codes assigned to cursor movement actions
In Vim, execute
:set <key-name>?to print a key code currently mapped to a specific key name. You can find the key names in this list or by switching Vim to the Insert mode and pressing <kbd>Ctrl</kbd>+<kbd>K</kbd> followed by the actual key. For example for the <kbd>Left</kbd> arrow key, the name is<Left>, so I executed the command:set <Left>?to get the following output:That means, the key named
<Left>, which meanscursor-left, is mapped to the terminal optiont_kland has assigned the key code^[O*D.Key codes generated by keyboard
To get the actual key codes generated by the keyboard, switch to the Insert mode, press <kbd>Ctrl</kbd>+<kbd>V</kbd> and then the key. For example, for the <kbd>Left</kbd> arrow key, it prints the code
^[[Don my system, which is clearly different from the key code^[O*Dassigned to the key name<Left>.Fix
So what’s needed is simply to map Vim’s key names to the same key codes as generated by the keyboard:
The easiest way to configure your keys is:
.vimrcin Vimset <Up>=The final product should look similar to the following:
Now, the cursor keys work in all Vim modes. At least for me 😃
Credits
It was this answer on the Stack Exchange’s Q&A site Vi and Vim which greatly helped me to figure the things out.
worked for me too. Just has to be
~/.vimrcI’m going to close this, as it’s a conemu/cmder problem, and not a WSL/conhost one
See https://github.com/cmderdev/cmder/issues/901 and this ConEmu release for a solution.
This worked for me as well. I use ConEmu.
set nocompatibleon both.vimrcand.xhrcdid not work. I only added:set term=builtin_ansiin.vimrcand now the arrow key works as I expected.I wouldn’t expect any more improvements in the coming release in terms of supporting conemu/cmder. It’s on our radar, but it’s not going to make it for this release.
Yes you need -cur_console:p
@dsouzadyn The arrow keys are bound to diff escape sequences. You need to use a special mode in cmder or conemu. This is a bug in their software (not detecting that terminal processing is enabled).