How do you get bufspec when using Vimdiff Through Git

I read Vimdiff and Viewing Differences with Vimdiff plus doing various google searches using things like "vimdiff multiple", "vimdiff git", "vimdiff commands" etc.

When using do or diffg, I get the error "More than two buffers in diff mode, I don’t know which one to use."

When using diffg v: fname_in, I get "There is no corresponding buffer for v: fname_in".

From the vimdiff documentation:

: [range] diffg [et] [bufspec]
Change the current buffer to cancel the difference with another buffer. If [bufspec] is specified, this buffer is used. If [bufspec] refers to the current buffer, then nothing happens. Otherwise, this only works if diff has another Mode buffer.

and more:

When "diffexpr" is not empty, Vim evaluates the receipt of the diff file in the mentioned format. These variables are set to the file names used:

v: source file fname_in
v: fname_new new version of the same file
v: fname_out result diff file

So, I need to get the name bufspec, but the default variables (fname_in, fname_new and fname_out) are not set.

I ran the git mergetool command in the linux window via terminal.

[Edit] Partial solution that raised more questions. I used the "file name" at the bottom of the buffer. This is only half the answer, because sometimes I get a file, there is no error. I believe that it is always a remote version of a file that "does not exist". I suspect this has something to do with git and indexing.

How do you get the bufspec value sequentially when using vimdiff via git -mergetool?

+7
git git-merge vim vimdiff
source share
3 answers

The [bufspec] argument above may be a buffer number, a pattern for the buffer name, or part of the buffer name. Examples:

  • :diffget Use a different buffer that is in diff mode.
  • :diffget 3 Use buffer 3
  • :diffget v2 Use a buffer that matches v2 and is located in diff (e.g. file.c.v2 )

I always use the buffer number.

+8
source share

Enter "2" and then ctrl-g, you will see the buffer number and file.

+4
source share

To display the available buffer numbers and names (valid values ​​for bufspec), use :ls

(From the title of this question, what I thought was asked, and that is why I looked here.)

:ls will list the numbers and names of the buffer. The window containing the cursor will be indicated by the % symbol:

 :ls 1 #a "Gemfile.lock" line 1 2 %a "Gemfile.lock.LOCAL.4828.lock" line 1 3 a "Gemfile.lock.BASE.4828.lock" line 0 4 a "Gemfile.lock.REMOTE.4828.lock" line 0 

When using diffget or diffput any substring that uniquely matches the name of the buffer can be used as an argument to bufspec. For example, if we assume that the state is reflected in the above fragment, we can use:

diffget REM

to capture the Gemfile.lock.REMOTE.4828.lock version of the change that is under the cursor.

0
source share

All Articles