3
votes

I may have accidentally changed some setting but now I can't figure out what it is.

Behavior:

  • Whenever I edit an existing file, Vim starts in replace (R) mode. This is new as of this week.
  • Whenever I do vim nonExistantFile.txt, Vim starts in normal mode

Steps so far to diagnose:

  1. /etc/vimrc has nothing relevant, and specifically does not contain startreplace
  2. /home/<myuser>/.vimrc has nothing relevant, and specifically does not contain startreplace
  3. alias shows nothing vim related

Platform info:

  • Vim version 7.3.1314
  • Windows 7 64-Bit
  • 32 Bit Cygwin and Vim binary

Other potentially relevant information:

  • Some time ago (before this started happening) I copied /etc/vimrc from my CentOS 6.4 machine into the Cygwin /etc/vimrc
  • I edited some binary files recently

I'm pretty stumped, I can't think of anything else to try.

Update:

  • I have narrowed the problem down to this /etc/vimrc snippet
  • Oddly commenting out EITHER of these two commands solves the problem

Vimrc snippet (note: this does have unix line endings):

" Only do this part when compiled with support for autocommands
if has("autocmd")
  "<snip>
  " When editing a file, always jump to the last cursor position
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  \   exe "normal! g'\"" |
  \ endif
  " don't write swapfile on most commonly used directories for NFS mounts or USB sticks
  autocmd BufNewFile,BufReadPre /media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
  "<snip>
endif
4
Just a thought, the centos newline might not be compatible with win. Can you grab another vimrc?KevinDTimm
Try to delete your .viminfo file. I had a similar problem once and it solved it. My theory is that .viminfo contained some rogue command which was executed at startup.EyalAr
@KevinDTimm You may be on to somethingdurron597
@KevinDTimm nope I used unix2dos on the file and it chokeddurron597

4 Answers

7
votes

I mapped nnoremap <ESC> :nohlsearch<CR> in my .vimrc and that caused this behaviour.

Mapping this to <Enter> solved the problem for me.

0
votes

check ~/.exrc files for initial settings, there must be a flag setting your vi into REPLACE mode at startup!

http://alvinalexander.com/unix/edu/un010003/

cheers!

0
votes

I added a few newlines and swapped the two commands in /etc/vimrc that seemed to be causing the problem... and this seemed to fix it. I have no idea why.

0
votes

The following seemed to fix this problem for me. I think that there was some autocommand code that interfered with the cursor position restore, so clearing out previous autocommands as below fixed the problem for me:

function! ResCur()
  if line("'\"") <= line("$")
    normal! g`"
    return 1
  endif
endfunction

augroup resCur
  autocmd!
  autocmd BufWinEnter * call ResCur()
augroup END

http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session