git/list[1] front-page[2] threads[3] people[4] search[5] about
 

mergetools: wrong window selected for vimdiff1

From
SMSebastián Mancilla <smancill@smancill.dev>
Date
Jan 5, 2023, 18:47 UTC
Message-ID
<167294445271.7.3739319158947040124.89448053@smancill.dev>
The layout for the vimdiff1 mergetool is "@LOCAL,REMOTE". From the man page:
    o   layout = "@LOCAL,REMOTE"
        When MERGED is not present in the layout, you must "mark" one
        of the buffers with an asterisk. That will become the buffer
        you need to edit and save after resolving the conflicts.
            ------------------------------------------
            |                   |                    |
            |                   |                    |
            |                   |                    |
            |     LOCAL         |    REMOTE          |
            |                   |                    |
            |                   |                    |
            |                   |                    |
            ------------------------------------------
But after opening the buffers, the cursor is in the *right window*.

This is confusing, since it makes you think the right buffer is the one that needs to be edited, instead of the left one.

Debug output (the make-conflicts.sh script in this repository [0] can be used to quickly test a file with conflicts):

    Merging:
    poem.txt
    Normal merge conflict for 'poem.txt':
      {local}: modified file
        {remote}: modified file
        LAYOUT    : @LOCAL,REMOTE
        CMD       : echo
        NESTED MIN: 0
        CLEAN     : @LOCAL,REMOTE
        LAYOUT    : @LOCAL
        CMD       : echo | leftabove vertical split
        NESTED MIN: 0
        CLEAN     : @LOCAL
        LAYOUT    : REMOTE
        CMD       : echo | leftabove vertical split | 1b | wincmd l
        NESTED MIN: 0
        CLEAN     : REMOTE
        FINAL CMD : -c "set hidden diffopt-=hiddenoff | echo |
leftabove vertical split | 1b | wincmd l | 3b | execute 'tabdo windo
diffthis' | tabfirst"
        FINAL TAR : LOCAL
        4 files to edit

Also note that when vimdiff1 was introduced by 30bb8088af (mergetools/vimdiff: add vimdiff1 merge tool variant, 2021-02-13), Vim echoed a nice message to remember which buffer shall be edited:

> +        *vimdiff1)
> +                "$merge_tool_path" -f -d \
> +                        -c 'echon "Resolve conflicts leftward then save. Use :cq to abort."' \
> +                        "$LOCAL" "$REMOTE"

But with the refactor done by 0041797449 (vimdiff: new implementation with layout support, 2022-03-30), now the message is gone:

Show 12 quoted lines
>          *vimdiff1)
> -                "$merge_tool_path" -f -d \
> -                        -c 'echon "Resolve conflicts leftward then save. Use :cq to abort."' \
> -                        "$LOCAL" "$REMOTE"
> -                ret="$?"
> -                if test "$ret" -eq 0
> -                then
> -                        cp -- "$LOCAL" "$MERGED"
> -                fi
> -                return "$ret"
> +                layout="@LOCAL,REMOTE"
>                  ;;
[0]: https://github.com/whiteinge/diffconflicts/tree/master/_utils
-- 
Sebastián Mancilla
Message 1 of 1 in “mergetools: wrong window selected for vimdiff1”
  1. Sebastián MancillaJan 5, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.