Tip #492: jump to file from :CVSDiff output
tip karma |
Rating 1/1, Viewed by 896
|
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
created: |
|
June 24, 2003 2:07 |
|
complexity: |
|
basic |
author: |
|
daniel kullmann |
|
as of Vim: |
|
5.7 |
I use :CVSDiff from cvscommand.vim quite often to get an overview of the changes i made to a file.
I always want to jump from the diff to the corresponding line in the original file.
So I wrote a small script that does that, and put it in $VIM/after/syntax/diff.vim
Pressing <Return> will execute that script.
function! DiffJumpToFile()
let a=line(".") " current line number
let b=search("^\\(---\\|\\*\\*\\*\\) ", "b") " search for line like *** 478,489 ***
let c=getline(b) " get this line as string
let d=strpart(c, 4, match(c, ",")-4) " get the first line number (478) from that string
let f=search("^\\(---\\|\\*\\*\\*\\) .*\\t", "b") " search for line like *** fileincvs.c ....
let g=getline(f) " get this line as string
let h=match (g, "\\t", 4) " look for end of filename (terminated by tab) in string
let i=strpart(g, 4, h-4) " get the filename
execute ":b " . i | " change to that file
execute "normal " . (d+a-b-1) . "G" | " go to right line number
endfunction
nmap <buffer> <Return> :call DiffJumpToFile()<CR>
I didn't put that script in the script section because it doesn't have any error checking at all.
<< can anyone tell me how to get rid of the F1 mapping ? |
Open the directory for the current file in Windows >>
Additional Notes
|