My Ubuntu LTS 12.04 has vim editor. If I open a file, move to a paragraph and reopen vim, then the cursor goes to beginning of the file always.
This is not the expected behavior. How the vim can remember last read position after closing a file?
I tried vi
also, but the result is the same.
The file
/etc/vim/vimrc
already contains necessary feature. Just need to uncomment it:(Infact, you can refer to
/usr/share/vim/vim73/vimrc_example.vim
also)I had this same problem and it turned out that the .viminfo file in my home directory had the wrong ownership. It was owned by root:root.
Once I fixed the file ownership by changing it to myself, remembering file position started working for me again
I think this wiki posting may provide a solution. I don't believe restoring the position is the expected behavior. http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session
There is a plugin called vim-lastplace (I am the author) that will open your files where you left off. It improves on the above suggestions by ignoring commit messages because you're typically editing a new message and want to start at the top of the commit message file.
Good convention is to create your own .vimrc file in your $HOME directory, and include this line which will cause Vim to jump to the last known position in a previously edited file.
In $HOME/.vimrc, add the following lines:
There is no need to edit the system-wide file /etc/vim/vimrc.
Creating and using your own .vimrc in your $HOME directory is also better for maintainability. The system vimrc configuration file could be updated when the Vim application package gets an update next time, or edited by someone else. Your own file in your own home-directory will be honored when you run Vim.
I actually recommend you look into all the great things you can do with your own .vimrc file. I have mine configured with tons of useful options and even a few custom functions.
In my case, vi was a symlink:
/usr/bin/vi -> /etc/alternatives/vi -> /usr/bin/vim.tiny
. The latter has no real vim features. Installing the package 'vim' (using synaptic or apt-get) made this symlink point to/usr/bin/vim.basic
, and this fixed the issue.In my case was that I had copied my .vimrc from another machine.
This was the offending line.
My problem was that because I use different systems, ie. cygwin, wsl2, linux etc... I had copied it from a cygwin install and it had looked something like this
which is obviously not correct for my linux install. Modding it to look like the first example above fixed my problem.
There is a mistake in Lunar Mushrooms solution. Here the correction:
The last edit information is stored at
.viminfo
.If it hasn't a read mod for your user, just change it.