Wednesday, February 21, 2018

Re: vimdiff - how to jump to next difference in long line - shortcut ]c does not work

On Wed, Feb 21, 2018 at 5:27 AM, Igor Forca <igor2x@gmail.com> wrote:
@Christian, thanks a lot for explanation. It looks like ]c jumps through lines and searches for changes (it skips the same lines in both files), but cursor is always placed on first character in line. Interesting. It looks I misunderstood the help:
]c Jump forwards to the next start of a change.

Is there some solution to jump to the first character of change. So in the case of my sample (step 2 in my previous post) to first letter of b?
Imagine I have file with long lines (I receive data from database with multiple columns) and jumping to the first character colored red would spare me plenty of time. Using the same shortcut to jump to next block of changes etc. Does anything like that exists?


Here is a script-ized way:

-- 8< --
fu! s:DiffSearch(opt)
    let ctx = synIDattr(diff_hlID(line('.'), col('.')), "name")
    let skip_same = 1
    if a:opt != 'curline'
        norm! ]c
    endif
    let cur_pos = getpos('.')
    for i in range(1, col('$'))
        let cur_ctx = synIDattr(diff_hlID(line('.'), i), "name")
        if skip_same && ctx == cur_ctx
            continue
        endif
        let skip_same = 0
        if cur_ctx == "DiffText"
            let cur_pos[2] = i
            call setpos('.', cur_pos)
            break
        endif
    endfor
endf
nn <silent> ]c :call <SID>DiffSearch('')<cr>
nn <silent> ]x :call <SID>DiffSearch('curline')<cr>
-- 8< --
 
Use ]c for the behavior you want, and use "]x" if you want to search in the current line. Feel free to modify this to suit to your needs.

Once search pattern \%h or \%s (help todo.txt) gets implemented in vim, you should be able to just search for "DiffText" directly.

Regards,
-Arun

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: