Startup triggers Vim to switch to replace mode

Feedback


Solution 1:

Encountering a similar issue within tmux, I discovered that launching vi (also known as vim) would unintentionally place me in REPLACE mode. Upon investigation, I traced the source of the problem to the TERMCAP definitions of the xterm-256color TERM that I had been utilizing.

After modifying the TERM setting, vi (vim) started functioning properly. Even when set to “ansi”, it exhibited improved behavior.

After trying out different settings, I found that the “screen-256color-s” TERM setting meets my requirements perfectly.

Fun with TERMCAP definitions.


Solution 2:


To prevent odd behavior, it’s advisable to refrain from mapping the Esc key.

  • Learn how to assign the key combination < Esc > to exit vim. Doing so will enable vim to terminate instantly upon opening, provided it’s mapped to the command :q< CR >.
  • The use of < esc > in vimrc results in strange arrow movements.

As per the recommendation in “Coming Home to Vim,” I have adopted

<leader><space>

to turn off highlighting. Perhaps, you could give it a try and adjust to it.


Solution 3:


To solve the identical issue, I appended the subsequent code to my file labeled

vimrc

.

" Terminal fixes
"
" These originate from some linux distribution's system vimrc. I can't say
" that I understand the details what's going on here, but without these
" settings, I've had problems like vim starting in REPLACE mode for
" TERM=xterm-256color (neovim is fine)
if &term =~? 'xterm'
    let s:myterm = 'xterm'
else
    let s:myterm =  &term
endif
let s:myterm = substitute(s:myterm, 'cons[0-9][0-9].*$',  'linux', '')
let s:myterm = substitute(s:myterm, 'vt1[0-9][0-9].*$',   'vt100', '')
let s:myterm = substitute(s:myterm, 'vt2[0-9][0-9].*$',   'vt220', '')
let s:myterm = substitute(s:myterm, '\([^-]*\)[_-].*$', '\1',   '')
" Here we define the keys of the NumLock in keyboard transmit mode of xterm
" which misses or hasn't activated Alt/NumLock Modifiers.  Often not defined
" within termcap/terminfo and we should map the character printed on the keys.
if s:myterm ==? 'xterm' || s:myterm ==? 'kvt' || s:myterm ==? 'gnome'
    " keys in insert/command mode.
    map! Oo  :
    map! Oj  *
    map! Om  -
    map! Ok  +
    map! Ol  ,
    map! OM  
    map! Ow  7
    map! Ox  8
    map! Oy  9
    map! Ot  4
    map! Ou  5
    map! Ov  6
    map! Oq  1
    map! Or  2
    map! Os  3
    map! Op  0
    map! On  .
    " keys in normal mode
    map Oo  :
    map Oj  *
    map Om  -
    map Ok  +
    map Ol  ,
    map OM  
    map Ow  7
    map Ox  8
    map Oy  9
    map Ot  4
    map Ou  5
    map Ov  6
    map Oq  1
    map Or  2
    map Os  3
    map Op  0
    map On  .
endif

Additional settings similar to those mentioned can be found at https://gist.github.com/goerz/36015f27c2a5423c64a5f9dc03865f2c, which may also prove useful. The underlying issue appears to stem from an error in the termcap/terminfo.

Frequently Asked Questions

Posted in Vim