使用 gvim 比较两个文件的不同:
方式一,使用 gvim 同时打开两个待比较的文件。
比较通用方式是采用 gvim -d 选项,具体命令,如下:
gvim -d <file1> <file2>
方式二,先用 gvim 打开一个文件,然后启动 diff mode,与另一个文件进行比较。
-
正常使用 gvim 编辑一个文件
<file1>
,命令如下:gvim <file1>
-
然后采用
:diffthis
或:diffsplit
命令启动 diff mode。a) 采用
:diffthis
命令的具体示例在当前文件
<file1>
窗口中,打开另一个文件<file2>
。如果采用垂直切分(vertical split)方式打开文件<file2>
,命令如下::vs otherFile
如果采用水平切分(horizontal split)方式打开,命令如下:
:sp otherFile
在当前文件
<file1>
中,启动 diff mode,命令如下::diffthis
到此,就可以看到两个文件的差异显示了。
关闭 diff mode 的命令,如下:
:diffoff
b) 采用
:diffsplit
命令的具体示例一条命令即可以显示两文件之间的差异,如下:
:diffsplit <file2>
如果以垂直切割窗口方式打开了
<file2>
,使用命令::vert diffsplit <file2>
切换分屏
ctrl+w ,再按 h左, l右, j 下, k 上,w 窗口循环切换
关闭当前窗口分屏:ctrl+w,再按 c
向右或向下方交换窗口:Ctrl + w + r 而Ctrl + w + R则和它方向相反。
交换同列或同行的窗口的位置:Ctrl + w + x
diff mode 常用命令速查表(cheat sheet)
[c Jump to the previous diff 跳到前一个不同之处
]c Jump to the next diff 调到下一个不同之处
do diffget: Pull the changes to the current file 将所有的不同之处拉到当前文 件,使之与另一个文件内容相同
dp diffput: Push the changes to the other file 将所有的不同之处推到另一个文件
:diffupdate rescan files for differences 重新扫描文件之间的不同之处
可以使用
2]c
跳转到下两个差异点 可以在第 5行和第 16行之间用diffput,在第
19行到23行之间使用diffget,命令如下:
bash :5,16diffput :19,23diffget
Folds 折叠命令
zo/zO Open 打开折叠
zc/zC Close 关闭折叠
za/zA Toggle 在打开折叠和关闭折叠之间进行切换
zv Open folds for this line 为当前行打开折叠
zM Close all 关闭所有折叠
zm Fold more (foldlevel += 1) 更多地折叠
zR Open all 打开所有折叠
zr Fold less (foldlevel -= 1) 更少地折叠