Disable vi from going to the last visited line upon file opening

vivim

Is there something I can put in my exrc file to prevent vi from going to the last line I was on last time I had the file open and just set the cursor at the top by default?

I think it is distro-specific — it doesn't behave like that on Solaris but does on RHEL.

Best Answer

This feature is implemented as autocommand. It is set up in /etc/vimrc - see snippet below. Remove it from there or add command to remove that autocommand to your vimrc file. (I am using fedora - on rhel it should be very similar)

if has("autocmd")
  augroup fedora
  autocmd!
  "...
  " When editing a file, always jump to the last cursor position
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  \   exe "normal! g'\"" |
  \ endif
  "...
  augroup END
endif

If you do not have permissions or do not want to change /etc/vimrc, the command to put in your local .vimrc to remove the autocommand is :au! <group> <cmdname>, in this case :au! fedora BufReadPost.

Related Question