13

When I open a file with vim, I always start in replace mode.

I figured out, that when I remove this line from my .vimrc, I open files in normal mode again:

nnoremap <esc> :noh<return><esc>

If I exchange <esc> against a different key combination it also works as expected. I don't understand what is going on here.

Here is my complete .vimrc. I use termite, in case that could be a problem.

Natjo
  • 2,005
  • 29
  • 75
  • Thanks, I found the answer somewhere in a discussion in your linked question! – Natjo Jul 17 '18 at 19:21
  • The question you linked is about the same topic, but the accepted answer to it did not solve my problem, that's why I added an answer here as well, stating the proper solution. – Natjo Jul 17 '18 at 19:26

2 Answers2

12

It was some internal problem, what solved the problem was adding this line:

nnoremap <esc>^[ <esc>^[

Here you can find some details about this solution.

Natjo
  • 2,005
  • 29
  • 75
  • 2
    Duh, how is this answer not the accepted one? Works perfectly for me on WSL1 and properly keeps arrow keys working. – kubanczyk Sep 24 '20 at 12:03
  • 1
    Thanks for the feedback! I answered myself here, but it didn't feel like an adequate solution. But if it helped you, too, I guess it should be the accepted answer. – Natjo Sep 24 '20 at 13:09
7

This happened to me connecting to a cray from wsl. My .vimrc is pretty much empty; the distro has a default looking vimrc (no special nohl keymapping).

" FIX: ssh from wsl starting with REPLACE mode
" https://stackoverflow.com/a/11940894
if $TERM =~ 'xterm-256color'
  set noek
endif

Add this to vimrc and it no longer starts in REPLACE mode.

See https://stackoverflow.com/a/11940894 (same thread Jonas mentioned).

Yu Feng
  • 239
  • 3
  • 3
  • 1
    this resets "nocompatible" for me with the effect that I cannot use backspace or arrow keys in insert mode (it just inserts ABCD etc. -- it is a known problem in vimwiki). Any solution for combining the both? – niid Sep 05 '20 at 21:38