Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with this mapping? Vim starts in -- REPLACE -- mode

Tags:

vim

I am having a weird bug in my .vimrc since I last updated it.

Every time I start vim it starts in -- REPLACE -- mode which is really annoying.

I managed to find out that it is this line in my .vimrc that is causing the problem.

" Disable search highlighting temporally
nnoremap <esc> :nohl<cr>

The problem goes away when I comment this line out.

I am really confused about what is wrong with the mapping. It works as it should but causes vim to enter -- REPLACE -- mode on startup.

I currently have no plugins enabled at all.

like image 317
wefwefa3 Avatar asked Jul 27 '15 11:07

wefwefa3


People also ask

Why is vim opening in replace mode?

Flag t_u7 is set by default and so vim will request cursor position and get a bad reply from the ssh client. Workaround: Adding set t_u7= or set ambw=double to your vimrc should fix the problem. set t_u7= will disable requesting cursor position and ambw=double will set the ambiguous characters mode to double.

How to go back to normal mode Vim?

By default, Vim starts in “normal” mode. Normal mode can be accessed from other modes by pressing Esc or <C-[> .

How to change from replace to insert on Vim?

You can press R and you'll get into the REPLACE mode. Shift+R, actually. Pressing just R key (as you would do to type r ) allows to replace just one letter and then goes back to NORMAL mode. Possibly that's why he put R and not r.


2 Answers

I had this same problem, though it was inside of tmux, when I started vi (aka vim), it would launch in REPLACE mode. The culprit seems to be the TERMCAP definitions for the TERM I have been using: xterm-256color.

Once I set TERM to something different, vi (vim) worked correctly. Even a TERM setting of "ansi" behaved better.

I settled on a TERM setting of "screen-256color-s" which works as I need.

Fun with TERMCAP definitions.

like image 130
John Bolding Avatar answered Oct 05 '22 11:10

John Bolding


It is better to avoid mapping the Esc key, as it is known to cause strange behavior:

  • How to map < Esc > to quit vim - vim quits immediately after opening if mapped to :q< CR >
  • Mapping < esc > in vimrc causes bizzare arrow behaviour

I have been using <leader><space> for disabling the highlighting, as suggested by "Coming Home to Vim", maybe you could get used to it too.

like image 42
mMontu Avatar answered Oct 05 '22 13:10

mMontu