vim不记得最后的位置

我的Ubuntu LTS 12.04有vim编辑器。 如果我打开一个文件,移动到一个段落并重新打开vim,那么光标总是会转到文件的开头。

这不是预期的行为。 关闭文件后vim如何记住上次读取位置?

我也尝试了vi ,但结果是一样的。

解决了它:

的/ etc / VIM /的vimrc

已经包含必要的function。 只需要取消注释:

 " Uncomment the following to have Vim jump to the last position when " reopening a file if has("autocmd") au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif endif 

(事实上​​,您也可以参考/usr/share/vim/vim73/vimrc_example.vim)

我有同样的问题,结果是我的主目录中的.viminfo文件拥有错误的所有权。 它由root:root拥有。

一旦我通过将文件所有权更改为自己来修复文件所有权,记住文件位置再次开始为我工作

我认为这个wiki发布可能会提供一个解决方案。 我不认为恢复这个位置是预期的行为。 http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session

有一个名为vim-lastplace的插件(我是作者),它会在你离开的地方打开你的文件。 它通过忽略提交消息来改进上述建议,因为您通常编辑新消息并希望从提交消息文件的顶部开始。

就我而言,vi是一个符号链接: /usr/bin/vi -> /etc/alternatives/vi -> /usr/bin/vim.tiny 。 后者没有真正的vimfunction。 安装包’vim’(使用synaptic或apt-get)使这个符号链接指向/usr/bin/vim.basic ,这解决了这个问题。

Lunar Mushrooms解决方案存在错误。 在这里纠正:

 if has("autocmd") " When editing a file, always jump to the last known cursor position. " Don't do it when the position is invalid or when inside an event handler " (happens when dropping a file on gvim). " Also don't do it when the mark is in the first line, that is the default " position when opening a file. autocmd BufReadPost * \ if line("'\"") > 1 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif endif