Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do You Get the bufspec While Using Vimdiff Through Git

I've 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, don't know which one to use".

When using diffg v:fname_in I get "No matching buffer for v:fname_in".

From the vimdiff documentation:

:[range]diffg[et] [bufspec]
Modify the current buffer to undo difference with another buffer. If [bufspec] is given, that buffer is used. If [bufspec] refers to the current buffer then nothing happens. Otherwise this only works if there is one other buffer in diff mode.

and more:

When 'diffexpr' is not empty, Vim evaluates to obtain a diff file in the format mentioned. These variables are set to the file names used:

v:fname_in original file
v:fname_new new version of the same file
v:fname_out resulting diff file

So, I need to get the name of bufspec, but the default variables (fname_in, fname_new, and fname_out) aren't set.

I ran the command git mergetool on a linux box through a terminal.

[Edit] A partial solution that bred more questions. I used the "filename" at the bottom of the buffer. It's only a half answer, because occasionally I get a file does not exist error. I believe it's consistently the remote version of the file that "does not exist". I suspect this has something to do with git and indexing.

How do you get the bufspec value consistently while using vimdiff through git-mergetool?

like image 916
Elizabeth Buckwalter Avatar asked Mar 24 '10 18:03

Elizabeth Buckwalter


2 Answers

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

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

:ls will list the buffer numbers and names. The window currently containing the cursor will be denoted by a %:

: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 a buffer name can be used as the bufspec argument. For example, assuming the state reflected in the above snippet, we can use:

diffget REM

to grab Gemfile.lock.REMOTE.4828.lock's version of the change that is currently under the cursor.

like image 116
Stew Avatar answered Oct 26 '22 16:10

Stew


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

  • :diffget Use the other buffer which is in diff mode
  • :diffget 3 Use buffer 3
  • :diffget v2 Use the buffer which matches v2 and is in diff mode (e.g., file.c.v2)

I always use the number of the buffer.

like image 36
nono Avatar answered Oct 26 '22 16:10

nono