Met*_*aEd 21
"开箱即用" .vimrc通过以下声明实现:
source $VIMRUNTIME/vimrc_example.vim
Run Code Online (Sandbox Code Playgroud)
您可能只需要在您的帐户中恢复此声明.vimrc.在任何情况下,请参阅vimrc_example.vim并查看Vim手册中的line()功能,以了解其工作原理.
小智 18
摘自http://amix.dk/vim/vimrc.html
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
Run Code Online (Sandbox Code Playgroud)
Kaz*_*sho 16
对于正在寻找纯 Lua 版本的 Neovim 用户:
-- Restore cursor position
vim.api.nvim_create_autocmd({ "BufReadPost" }, {
pattern = { "*" },
callback = function()
vim.api.nvim_exec('silent! normal! g`"zv', false)
end,
})
Run Code Online (Sandbox Code Playgroud)
thi*_*wfx 13
当前接受的答案的更新版本:
silent! source $VIMRUNTIME/defaults.vim
Run Code Online (Sandbox Code Playgroud)
最后一个编辑位置由Vim自动保存,可用作"特殊"跳转标记..其他特殊标志包括"(位置所储存)和'(位置,你跳了从).
您可以通过键入来跳转到标记'<mark>,这样'.您将转到上次编辑的位置,''将您带回到原来'"的位置,并将您带到保存文件的位置.
Vim.Wikia的 Vim标志更多.
我正在向 @Mariano 回答/sf/answers/1011463911/添加更完整的示例,并进行一些额外的检查
" Only do this part when compiled with support for autocommands
if has("autocmd")
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
augroup END
endif
Run Code Online (Sandbox Code Playgroud)
有一个名为vim-lastplace的插件(我是作者)将智能地返回到您所做的最后一次编辑.
它还有一个配置选项来忽略某些文件类型.默认情况下,它将忽略git,svn和mercurial的提交消息.对于这些文件类型,它将在第一行开始光标.上面的代码片段将跳转到您的提交消息文件的中间(您在之前的提交中停止了),即使这可能不是您想要的.vim-lastplace解决了这个问题.