I have a mapping to remove trailing whitespace, defined like this: nnoremap <silent> <F6> :%s/\s\+$//<CR>''. It works fine, except that if I press Esc before pressing F6, instead of doing what it should it seems to do ~(switch case for character) for a bunch of characters where the cursor is placed.

How can I prevent that from happening?


I'm on Arch Linux latest updates as of 2017-04-28 with Vim 8.0, running in gnome-terminal. It's the same on all systems I've tested, but it's worth noting that I'm on a Swedish keyboard layout (EDIT: Just tested, and it's the same on en_US layout for me).


I've narrowed it down some. While F1–F4 are caught by my terminal (so can't say anything there), F5 produces 5 characters to switch case, F6 produces 7 characters to switch, F7 does 8 and F8 does 9. I've tried disabling my .vimrc, and that fixes the problem. I'll search through the config and report back when I find what caused it.


If I remove my .vimrc, Vi does it but Vim does not. What does that mean?

EDIT 4, major finding:

So I've found the line in my config that causes it. It's noremap <Esc><Esc> :noh<CR>. Still don't understand why, though. :/

  • Could you add info with what terminal you use, OS, if you use tmux/screen etc?
    – grodzik
    Apr 28, 2017 at 9:37

2 Answers 2


The issue is caused by the line nnoremap <Esc><Esc> :noh<CR>, and can be fixed by changing it to nnoremap <Esc>a :noh<CR> or some other regular character instead of Esc. No idea why though.

Also, nvim seems to deal with <Esc> in the correct way.


Granted that I am running nvim and use Terminator, but for the very same purpose as described above I use: nnoremap <silent> <F5> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>. In order to isolate the matter I created a new .vimrc and added only the aforementioned line to the file. With both nvim (0.1.7) and Vim (8.0) I get the expected behavior (white space at end of line eliminated) and no characters changes case.

Edit: I changed to gnome-terminal, and the same appears there (i.e. everything work as expected).

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.