git 在vim中从磁盘刷新缓冲区中的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1272007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refresh all files in buffer from disk in vim
提问by odwl
The command to refresh a file from version on disk is :e!
从磁盘版本刷新文件的命令是 :e!
How can I do the same for all files in the buffer?
如何对缓冲区中的所有文件执行相同的操作?
Background: I need that because I am using git with multiple branches with one vim open that contains a buffer. When I checkout a branch, I would like to have vim refresh.
背景:我需要它,因为我使用带有多个分支的 git,其中一个 vim 打开,其中包含一个缓冲区。当我结帐一个分支时,我希望 vim 刷新。
采纳答案by pmf
Read the documentation for bufdo
, it should do what you want.
阅读 的文档bufdo
,它应该可以满足您的需求。
回答by Paul Fenney
The :checkt[ime]
command is designed for this very purpose.
该:checkt[ime]
命令正是为此目的而设计的。
It will prompt you to reload any buffers that have changed; if you wish to skip the prompt, you can do :set autoread
beforehand (you'll still get a prompt on buffers with local unsaved changes).
它会提示您重新加载任何已更改的缓冲区;如果你想跳过提示,你可以:set autoread
事先做(你仍然会得到一个关于本地未保存更改的缓冲区的提示)。
It also avoids the syntax highlighting issue mentioned by Steven Lu on the accepted answer; :bufdo
turns off syntax highlighting by design.
它还避免了 Steven Lu 在接受的答案中提到的语法突出显示问题;:bufdo
按设计关闭语法高亮。
通过找到:http: //vim.1045645.n5.nabble.com/Bug-report-bufdo-e-breaking-syntax-highlighting-on-displayed-buffers-tp1209995p1209998.html
回答by Ivan
Here's what I ended up putting in my .vimrc:
这是我最终放入 .vimrc 的内容:
fun! PullAndRefresh()
set noconfirm
!git pull
bufdo e!
set confirm
endfun
nmap <leader>gr call PullAndRefresh()
回答by phs
From :help autoread
:
来自:help autoread
:
When a file has been detected to have been changed outside of Vim and it has not been changed inside of Vim, automatically read it again. When the file has been deleted this is not done.
当检测到一个文件在 Vim 之外被更改而它在 Vim 内部没有被更改时,自动再次读取它。当文件被删除时,这不会完成。
If, like me, you just want to always passivelyreload stale-but-unmodified buffers, then this seems like it should get the job done.
如果像我一样,您只想被动地重新加载陈旧但未修改的缓冲区,那么这似乎应该可以完成工作。
However the final detail is whenvim notices the stale buffer. That can be forced with checktime
. If you have focus events set up, then we can run checktime
whenever we gain focus like so:
然而,最后的细节是vim何时注意到陈旧的缓冲区。可以强制使用checktime
. 如果您设置了焦点事件,那么我们可以checktime
在获得焦点时运行,如下所示:
set autoread
autocmd FocusGained * checktime
This answeralso has some interesting details.
这个答案也有一些有趣的细节。
回答by MOHRE
As @Matthew S Mentioned here https://vi.stackexchange.com/a/462, you can use:
正如@Matthew S 在这里提到的https://vi.stackexchange.com/a/462,您可以使用:
:set noconfirm
:bufdo !e
:set confirm