1
00:00:00,050 --> 00:00:02,020
- [Instructor] As you make changes to files

2
00:00:02,020 --> 00:00:05,010
sometimes you'd like to compare these changes

3
00:00:05,010 --> 00:00:06,080
with the original version.

4
00:00:06,080 --> 00:00:09,000
Instead of using a special program

5
00:00:09,000 --> 00:00:11,060
you can use the built-in diff mode in Vim.

6
00:00:11,060 --> 00:00:14,000
Say you were Rumi writing a quote

7
00:00:14,000 --> 00:00:16,080
and would like to compare two versions of it.

8
00:00:16,080 --> 00:00:21,030
They are road1.txt and road2.txt.

9
00:00:21,030 --> 00:00:23,080
One option is to start Vim in diff mode

10
00:00:23,080 --> 00:00:25,090
using the -d switch.

11
00:00:25,090 --> 00:00:31,080
So vim -d road1.txt and road2.txt.

12
00:00:31,080 --> 00:00:34,020
You can see the differences between the files.

13
00:00:34,020 --> 00:00:36,070
At the bottom you can see which file is which

14
00:00:36,070 --> 00:00:38,070
and you can move between the windows

15
00:00:38,070 --> 00:00:41,030
using Control + W + W

16
00:00:41,030 --> 00:00:43,050
and Control + W + W again

17
00:00:43,050 --> 00:00:45,080
will move you back to the first file.

18
00:00:45,080 --> 00:00:47,080
If you'd like to copy a line over

19
00:00:47,080 --> 00:00:50,090
you can use D + O for diff obtain

20
00:00:50,090 --> 00:00:53,090
or D + P for diff put.

21
00:00:53,090 --> 00:00:56,080
Let's get a diff, so D + O

22
00:00:56,080 --> 00:00:59,070
and we got the line from row two.

23
00:00:59,070 --> 00:01:01,090
This way you can select chunks of changes

24
00:01:01,090 --> 00:01:03,010
and apply them.

25
00:01:03,010 --> 00:01:06,010
Don't forget to write the changes before exiting.

26
00:01:06,010 --> 00:01:08,010
Let's create this regarding changes.

27
00:01:08,010 --> 00:01:13,010
So :qa!.

28
00:01:13,010 --> 00:01:18,060
Now start with just one file, vim road1.txt.

29
00:01:18,060 --> 00:01:20,040
If you'd like to compare from here

30
00:01:20,040 --> 00:01:26,060
you can do :diffsplit and then road2.txt.

31
00:01:26,060 --> 00:01:29,060
You can see here we got the horizontal splitting.

32
00:01:29,060 --> 00:01:32,030
You can tell Vim you'd like a vertical splitting.

33
00:01:32,030 --> 00:01:33,070
Let's close the second file.

34
00:01:33,070 --> 00:01:38,020
So buffer delete road2.txt.

35
00:01:38,020 --> 00:01:40,040
And now we do vert for vertical,

36
00:01:40,040 --> 00:01:44,060
diffsplit with road2.txt.

37
00:01:44,060 --> 00:01:47,010
I personally prefer this setup

38
00:01:47,010 --> 00:01:48,080
and there's a setting for it.

39
00:01:48,080 --> 00:01:51,050
Let's first look at the current diff options,

40
00:01:51,050 --> 00:01:54,050
which is diff opt, or dip for short.

41
00:01:54,050 --> 00:01:58,000
So se for set and dip.

42
00:01:58,000 --> 00:02:00,020
And we see that it is filler.

43
00:02:00,020 --> 00:02:02,020
Let's add the vertical option.

44
00:02:02,020 --> 00:02:07,030
So set diff option +=, meaning add an option,

45
00:02:07,030 --> 00:02:10,060
and saying vertical, Enter.

46
00:02:10,060 --> 00:02:13,050
And now if you do set of dip

47
00:02:13,050 --> 00:02:16,040
we'll see that it's filler and vertical.

48
00:02:16,040 --> 00:02:22,030
And now we can close again bd road2.txt.

49
00:02:22,030 --> 00:02:26,020
And now when we do just diffsplit with road2.txt

50
00:02:26,020 --> 00:02:28,040
we'll get a vertical diff.

51
00:02:28,040 --> 00:02:30,060
To make these settings persistent

52
00:02:30,060 --> 00:02:32,030
let's add it to our Vimrc.

53
00:02:32,030 --> 00:02:37,030
So let's close bd road2.txt

54
00:02:37,030 --> 00:02:40,070
and we'll open .vimrc.

55
00:02:40,070 --> 00:02:42,040
So move one line down,

56
00:02:42,040 --> 00:02:45,010
O for opening a new line in insert mode,

57
00:02:45,010 --> 00:02:47,020
and then set diffopt,

58
00:02:47,020 --> 00:02:50,090
and I like to use the long option in vimrc,

59
00:02:50,090 --> 00:02:54,010
+=vertical.

60
00:02:54,010 --> 00:03:00,070
And then Show diffs side by side comment,

61
00:03:00,070 --> 00:03:04,000
Escape, and write.

