Take diff of two vertical opened windows in Vim

孤街醉人 提交于 2019-11-28 14:35:50

问题


I've have two files opened. They are opened in vertical mode, next to next. Can I instantly diff these two files without leaving or closing Vim ?


回答1:


To begin diffing on all visible windows:

:windo diffthis

which executes :diffthis on each window.

To end diff mode:

:diffoff!

(The ! makes diffoff apply to all windows of the current tab - it'd be nice if diffthis had the same feature, but it doesn't.)




回答2:


in each of the windows you want to diff type:

:diffthis

If you want to diff all of the open windows, you can do:

:windo diffthis

(windo will apply the command to all open windows)




回答3:


Following up on the earlier answers,

  • :windo difft (short for diffthis) will start diff mode in all the open windows.
  • :windo diffo (short for diffoff) will stop diff mode in all the open windows.

I have the following mappings in my vimrc to make it easier:

command! Difft windo diffthis
command! Diffo windo diffoff



回答4:


Following on the earlier answers I adapted the mapping provided by @cxw The following mapping automatically closes NERDTree and diff the open windows. It does not matter if NERDTree is close, it works the same way. I do this quite often so it saved me quite some time.

command! Difft NERDTreeClose | windo diffthis


来源:https://stackoverflow.com/questions/4385515/take-diff-of-two-vertical-opened-windows-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!