Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:45:35+00:00 2026-06-16T00:45:35+00:00

When diffing two files in Vim, is it possible to display the total number

  • 0

When diffing two files in Vim, is it possible to display the total number of changes? I suppose, this is equivalent to counting the number of folds, but I don’t know how to do that either.

Ideally, I would like a message which says something like “Change 1 of 12”, which would update as I cycle through the changes with ]c.

I’m having great success converting some members of my office to the wonders of Vim, but Vimdiff is a consistent bugbear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:45:35+00:00Added an answer on June 16, 2026 at 12:45 am

    Here is a slightly more refined solution. It uses the same technique as my previous answer to count the diffs, but it stores the first line of each hunk in a list asigned to a global variable g:diff_hunks. Then the number of hunks below the cursor can be found by finding the position of the line number in the list. Also notice that I set nocursorbind and noscrollbind and reset them at the end to ensure we don’t break mouse scrolling in the diff windows.

    function! UpdateDiffHunks()
        setlocal nocursorbind
        setlocal noscrollbind
        let winview = winsaveview() 
        let pos = getpos(".")
        sil exe 'normal! gg'
        let moved = 1
        let hunks = []
        while moved
            let startl = line(".")
            keepjumps sil exe 'normal! ]c'
            let moved = line(".") - startl
            if moved
                call add(hunks,line("."))
            endif
        endwhile
        call winrestview(winview)
        call setpos(".",pos)
        setlocal cursorbind
        setlocal scrollbind
        let g:diff_hunks = hunks
    endfunction
    

    The function UpdateDiffHunks() should be updated whenever a diff buffer is modified, but I find it sufficient to map it to CursorMoved and BufEnter.

    function! DiffCount()
        if !exists("g:diff_hunks") 
            call UpdateDiffHunks()
        endif
        let n_hunks = 0
        let curline = line(".")
        for hunkline in g:diff_hunks
            if curline < hunkline
                break
            endif
            let n_hunks += 1
        endfor
        return n_hunks . '/' . len(g:diff_hunks)
    endfunction
    

    The output of DiffCount() can be used in the statusline, or tied to a command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a PHP library that will provide me inline diffing between two
I've been researching on finding an efficient solution to this. I've looked into diffing
In a project where some of the files contain ^M as newline separators, diffing
Possible Duplicate: Why does Mercurial think my SQL files are binary? I generated a
I know and love liquibase for schema migrations / schema diffing very much, but
Apparently Gnumeric's native file format is compressed xml. Diffing binary files isn't easy, so
Microsoft Visual Studio uses XML to save its .vcproj project files. So diffing XML
When using opening multiple files with split windows from the command line, vim likes
This is maybe unusual so let me set the scene: We have an SVN
I’m trying to make a counter which shows the number of days until we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.