I'd like vim to automatically open files at line 1 instead of where it left off the last time. I tried putting gg in .vimrc, but that didn't work. There's must be some way to do this.
CentOS, RHEL and Fedora ship a system-wide vimrc file at
/etc/vimrc that sets up an autocmd that will jump to the last mark of a file whenever one is found.
The installed autocmd looks like this:
augroup redhat autocmd! " When editing a file, always jump to the last cursor position autocmd BufReadPost * \ if line("'\"") > 0 && line ("'\"") <= line("$") | \ exe "normal! g'\"" | \ endif
(The main difference being that the name of the augroup is "fedora" on Fedora and "redhat" on RHEL or CentOS.)
While it is possible to disarm this rule by changing the
'viminfo' setting to prevent Vim from saving marks on the viminfo file, that has the unfortunate side effect of having it stop preserving that information altogether, which is otherwise useful in certain situations.
A more direct and precise approach to disable this behavior is to delete the rule, which you can do from your user's vimrc file, since it's sourced after the system-wide config.
You can use the following command to delete that rule on CentOS:
autocmd! redhat BufReadPost *
And this one to delete it on Fedora:
autocmd! fedora BufReadPost *
You can safely add both rules in your vimrc file, since they don't do anything unless those rules exist (presumably from the system-wide vimrc file.)
These commands will remove that single rule from the augroup, rather than clear the augroup altogether, since the augroup also installs other unrelated autocmds that might be desirable, therefore the suggestion to delete that one particular rule only.
I suspect this is related to the
viminfo setting. From
- The viminfo file
If you exit Vim and later start it again, you would normally lose a lot of information. The viminfo file can be used to remember that information, which enables you to continue where you left off.
The viminfo file is used to store:
- The command line history.
- The search string history.
- The input-line history.
- Contents of non-empty registers.
- Marks for several files.
- File marks, pointing to locations in files.
- Last search/substitute pattern (for 'n' and '&').
- The buffer list.
- Global variables.
A possible value for the
viminfo entry is:
" " Tell vim to remember certain things when we exit " '20 : marks will be remembered for up to 20 previously edited files " "100 : will save up to 100 lines for each register " :20 : up to 20 lines of command-line history will be remembered " % : saves and restores the buffer list " n... : where to save the viminfo files " set viminfo='20,\"100,:20,%,n~/.viminfo
You can see what you're
viminfo is set to with:
You could update that to change
'0. From the example above: