]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/mergetools/vimdiff.txt
Merge branch 'jc/retire-cas-opt-name-constant'
[thirdparty/git.git] / Documentation / mergetools / vimdiff.txt
CommitLineData
7b5cf8be
FR
1Description
2^^^^^^^^^^^
3
4When specifying `--tool=vimdiff` in `git mergetool` Git will open Vim with a 4
5windows layout distributed in the following way:
6....
7------------------------------------------
8| | | |
9| LOCAL | BASE | REMOTE |
10| | | |
11------------------------------------------
12| |
13| MERGED |
14| |
15------------------------------------------
16....
17`LOCAL`, `BASE` and `REMOTE` are read-only buffers showing the contents of the
18conflicting file in specific commits ("commit you are merging into", "common
19ancestor commit" and "commit you are merging from" respectively)
20
21`MERGED` is a writable buffer where you have to resolve the conflicts (using the
22other read-only buffers as a reference). Once you are done, save and exit Vim as
23usual (`:wq`) or, if you want to abort, exit using `:cq`.
24
25Layout configuration
26^^^^^^^^^^^^^^^^^^^^
27
28You can change the windows layout used by Vim by setting configuration variable
29`mergetool.vimdiff.layout` which accepts a string where the following separators
30have special meaning:
31
32 - `+` is used to "open a new tab"
33 - `,` is used to "open a new vertical split"
34 - `/` is used to "open a new horizontal split"
cf6cac20 35 - `@` is used to indicate the file containing the final version after
7b5cf8be
FR
36 solving the conflicts. If not present, `MERGED` will be used by default.
37
cf6cac20 38The precedence of the operators is as follows (you can use parentheses to change
7b5cf8be
FR
39it):
40
41 `@` > `+` > `/` > `,`
42
43Let's see some examples to understand how it works:
44
45* `layout = "(LOCAL,BASE,REMOTE)/MERGED"`
46+
47--
48This is exactly the same as the default layout we have already seen.
49
50Note that `/` has precedence over `,` and thus the parenthesis are not
51needed in this case. The next layout definition is equivalent:
52
53 layout = "LOCAL,BASE,REMOTE / MERGED"
54--
55* `layout = "LOCAL,MERGED,REMOTE"`
56+
57--
58If, for some reason, we are not interested in the `BASE` buffer.
59....
60------------------------------------------
61| | | |
62| | | |
63| LOCAL | MERGED | REMOTE |
64| | | |
65| | | |
66------------------------------------------
67....
68--
69* `layout = "MERGED"`
70+
71--
72Only the `MERGED` buffer will be shown. Note, however, that all the other
73ones are still loaded in vim, and you can access them with the "buffers"
74command.
75....
76------------------------------------------
77| |
78| |
79| MERGED |
80| |
81| |
82------------------------------------------
83....
84--
85* `layout = "@LOCAL,REMOTE"`
86+
87--
88When `MERGED` is not present in the layout, you must "mark" one of the
89buffers with an asterisk. That will become the buffer you need to edit and
90save after resolving the conflicts.
91....
92------------------------------------------
93| | |
94| | |
95| | |
96| LOCAL | REMOTE |
97| | |
98| | |
99| | |
100------------------------------------------
101....
102--
103* `layout = "LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE"`
104+
105--
106Three tabs will open: the first one is a copy of the default layout, while
107the other two only show the differences between (`BASE` and `LOCAL`) and
108(`BASE` and `REMOTE`) respectively.
109....
110------------------------------------------
111| <TAB #1> | TAB #2 | TAB #3 | |
112------------------------------------------
113| | | |
114| LOCAL | BASE | REMOTE |
115| | | |
116------------------------------------------
117| |
118| MERGED |
119| |
120------------------------------------------
121....
122....
123------------------------------------------
124| TAB #1 | <TAB #2> | TAB #3 | |
125------------------------------------------
126| | |
127| | |
128| | |
129| BASE | LOCAL |
130| | |
131| | |
132| | |
133------------------------------------------
134....
135....
136------------------------------------------
137| TAB #1 | TAB #2 | <TAB #3> | |
138------------------------------------------
139| | |
140| | |
141| | |
142| BASE | REMOTE |
143| | |
144| | |
145| | |
146------------------------------------------
147....
148--
149* `layout = "LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL/BASE/REMOTE),MERGED"`
150+
151--
152Same as the previous example, but adds a fourth tab with the same
153information as the first tab, with a different layout.
154....
155---------------------------------------------
156| TAB #1 | TAB #2 | TAB #3 | <TAB #4> |
157---------------------------------------------
158| LOCAL | |
159|---------------------| |
160| BASE | MERGED |
161|---------------------| |
162| REMOTE | |
163---------------------------------------------
164....
6cc668c0 165Note how in the third tab definition we need to use parentheses to make `,`
7b5cf8be
FR
166have precedence over `/`.
167--
168
169Variants
170^^^^^^^^
171
172Instead of `--tool=vimdiff`, you can also use one of these other variants:
173
174 * `--tool=gvimdiff`, to open gVim instead of Vim.
175
176 * `--tool=nvimdiff`, to open Neovim instead of Vim.
177
178When using these variants, in order to specify a custom layout you will have to
179set configuration variables `mergetool.gvimdiff.layout` and
180`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`
181
182In addition, for backwards compatibility with previous Git versions, you can
183also append `1`, `2` or `3` to either `vimdiff` or any of the variants (ex:
184`vimdiff3`, `nvimdiff1`, etc...) to use a predefined layout.
185In other words, using `--tool=[g,n,]vimdiffx` is the same as using
186`--tool=[g,n,]vimdiff` and setting configuration variable
187`mergetool.[g,n,]vimdiff.layout` to...
188
189 * `x=1`: `"@LOCAL, REMOTE"`
190 * `x=2`: `"LOCAL, MERGED, REMOTE"`
191 * `x=3`: `"MERGED"`
192
193Example: using `--tool=gvimdiff2` will open `gvim` with three columns (LOCAL,
194MERGED and REMOTE).