Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


share|improve this question

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

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.

share|improve this answer

This is more of a comment than a real answer. Solaris is not a Linux distro. It is a version of Unix operating system. vi on RedHat which is a Linux distro (Linux != Unix) is symbolically linked to vim. Solaris vi refers to genuine vi editor created by Bill Joy. So we are not talking here about the same editors. I have no idea how vim behaves as I am using nvi on my OpenBSD box which is another clone of genuine vi. I would suggest that you install vi editor on your RedHat box first and try to reproduce the problem. Typing vi filename.txt should open the file and put the prompt at the begging of the first line. Typing vi + filename.txt should open file in the last line. However vi can be open with many other options like vi +n filename.txt which puts you at the beginning of n-th line or vi +/regexp filename.txt which puts you at the beginning of the line which contains first occurrence of the regular expression (regexp), view filename.txt read only mode. Please refer to the man pages for the complete list. Do not forget to unlink vi command from vim when you install a real vi.

share|improve this answer

There might be some other option available for this, but you can use the following work around

vim <filename> +1

+1 indicates, to move the cursor to line 1.

share|improve this answer
i got line 2: E682: Invalid search pattern or delimiter when i put just vim +1 in my .exrc -- i don't want to have to specify a file, i.e. i want it applied to ANY file – amphibient Dec 26 '12 at 17:52
same with vim * +1 – amphibient Dec 26 '12 at 17:54
It is a option to be entered at command-line and not a one to put in vimrc file. As mentioned this is a work around. – mtk Dec 26 '12 at 17:56
I think it is distro-specific -- it doesn't behave like that on Solaris but does on RHEL – amphibient Dec 26 '12 at 17:58

To make sure, that this function is added by a plugin try to open the file with

vim --noplugin <filename>

If the cursor doesn't jump to the position of the last edit you should open the file again without the --noplugin-switch and study the output of :scriptnames. :scriptnames lists all previously sourced scripts.

If you are a semi-experienced vim user you can exclude most of the scripts by means of the path. For instance, all scripts located under &rtp/{ftplugin,spell,colors,syntax} (&rtp := runtimepath) are out of question.

I can imagine, that the script which implements this feature has a related name.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.