就我而言,我有两个文件 file1 和 file2。使用 vimdiff,我想合并更改,如下所示:
- 第一个区别是,将 file1 中的行放在 file2 中的行上方。这意味着差异,例如
Listing 2
在文件2和List 2
应该List 2
其次是Listing 2
在合并的文件中。
- 在另一个更改中反转大小写。
快照如下所示。
我们如何使用 vimdiff 来实现这一点?
您可以使用以下基本命令进行合并:
-
do - Get changes from other window into the current window.
-
dp - Put the changes from current window into the other window.
-
]c - Jump to the next change.
-
[c - Jump to the previous change.
-
zo - Open folded lines.
-
zc - Close folded lines.
-
zr - Unfold both files completely.
-
zm - Fold both files completely.
-
Ctrlww - change window.
-
:only | wq
- 退出其他窗口,写入并退出。
需要注意的怪癖
-
Both do and dp work if you are on a block of change (or just one line under a single line of change) in Normal mode, but not in Visual mode.
-
The undo command will only work in the buffer that was changed, so if you use dp and change your mind, you need to switch to the other buffer to undo.
-
:diffupdate
将重新扫描文件中的更改(Vim 可能会感到困惑,并显示虚假内容)。
可视化模式和更细粒度的控制
在可视模式下选择文本行时,必须使用普通命令:
-
:'<,'>diffget
and
-
:'<,'>diffput
.
例如:
- 进入视觉模式并标记一些文本/线条。
- 然后输入
:diffput
将选定的行推送到其他文件或:diffget
从另一个文件中获取选定的行。
详细说明一下:这意味着如果存在由多行组成的更改块,则选择行的子集并发出:diffput
只会在另一个缓冲区中应用这些更改。
(:diffget
and :diffput
也接受范围,请参阅:h copy-diffs
了解更多。)
比较 Vim 内的两个缓冲区
如果您分片加载两个文件(:vs
or :sp
), 你可以做:diffthis
在每个窗口上并实现已加载到缓冲区中的文件的差异。
:diffoff
可用于关闭 diff 模式。
此 Vimcast 帖子和视频 http://vimcasts.org/episodes/fugitive-vim-resolving-merge-conflicts-with-vimdiff/在实践中展示这一点。
如何应用缓冲区之间的所有更改
-
确保所有参与缓冲区都处于 diff 模式(请参阅:h start-vimdiff
)
-
A。获取从缓冲区到当前缓冲区的更改::%diffget <buffer-number>
-
b.将当前缓冲区中的所有更改放入另一个缓冲区中::%diffput <buffer-number>
(:%
是选择整个文件的范围;看:h :%
. :ls
将显示当前打开的缓冲区。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)