I have searched the help:
:h jumpto-diffs
With explanation that:
]c
should jump to the next start of the change.
But in my case this key shortcut does nothing.
I started gVim on Windows 7 with command:
gvim -u NONE -N
and key shortcut still does not work.
Maybe this is related to my keyboard (Slovenian keyboard):
See keyboard layout: https://gate2home.com/Slovenian-Keyboard
I have to press <Right-Alt> to get ] key.
Any idea what is wrong? Any workaroud?
I tried to use mapping like:
:map a ]c
and when pressing a nothing happens.
My gVim is v8.0.1529 witch is latest nightly build for win32 from:
https://github.com/vim/vim-win32-installer/releases/download/v8.0.1529/gvim_8.0.1529_x64.zip
2. Open the first file:
:e file1.txt
3. Diff mode second file:
:vert diffsp file2.txt
4. Do the mapping you suggested:
nnoremap a ]c
5. Press the a key and nothing happens.
So still a problem.
By the way if mappings would be the problem then ]c shortcut should be working out of the box because I have run gVim in: "gvim -u NONE -N" clean environment.
Any other idea?
2. Just to make a simple test I created two files with content.
a) create files
file1:
aaa bbb
file2:
aaa ccc
b) open Vim with: gvim -u NONE -N
c) :e file1
d) :vert diffsp file2
e) ]c --> it does nothing. I expect cursor jumps to first letter of bbb.
3. Other diff commands work fine. Like :diffget and :diffput I use all the time
without a problem.
Additionally: It may not be a Windows problem. Now I did a test on Ubuntu 16.04
Server. I did the test from step 2 above and the same problem. Strange... Do I
understand correctly what ]c should do? As I understand the CURSOR should jump
to the first letter of bbb string. Is it?
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?
fu! s:DiffSearch(opt)let ctx = synIDattr(diff_hlID(line('.'), col('.')), "name")let skip_same = 1if a:opt != 'curline'norm! ]cendiflet cur_pos = getpos('.')for i in range(1, col('$'))let cur_ctx = synIDattr(diff_hlID(line('.'), i), "name")if skip_same && ctx == cur_ctxcontinueendiflet skip_same = 0if cur_ctx == "DiffText"let cur_pos[2] = icall setpos('.', cur_pos)breakendifendforendfnn <silent> ]c :call <SID>DiffSearch('')<cr>nn <silent> ]x :call <SID>DiffSearch('curline')<cr>
TEST 1: LINES WITH NO DIFFERENCE BETWEEN TWO LINES WITH DIFFERENCES
File1:
aaa aaa
aaa bbb
aaa aaa
aaa bbb
File2:
aaa aaa
aaa ccc
aaa aaa
aaa ccc
Lines 2 and 4 are different. There are lines without difference between two different lines, like line 3. In this case ]c works perfectly it jumps between diff changes. Excellent.
TEST 2: LINES WITH DIFFERENCES ARE ONE AFTER ANOTHER
File1 - the same as in test 1.
File 2:
aaa aaa
aaa ccc
aaa ccc
aaa ccc
Now lines 2, 3 and 4 are different. Cursor on first line first column and pressing ]c jumps correctly to second line at first letter of c. Now I see this difference is acceptable and I would like to jump to next difference. Executing ]c I expect to get to the next (third) row and search for difference. Like executing j0 (down and at first character in line) and then executing ]c again.
I would like to have ]c working just like search does. For example searching for aaa, executing /aaa then n (for next). Every time I press n it gets to the next search string. Like that I would like to have ]c to "search" next difference. Difference should not be the block but line.
P.S. I am sorry I am not familiar with vim scripting. I would do the change myself if I know how to program in vim-script.
@Arun, thanks a lot for this code. I have performed two tests:
TEST 1: LINES WITH NO DIFFERENCE BETWEEN TWO LINES WITH DIFFERENCES
File1:
aaa aaa
aaa bbb
aaa aaa
aaa bbb
File2:
aaa aaa
aaa ccc
aaa aaa
aaa ccc
Lines 2 and 4 are different. There are lines without difference between two different lines, like line 3. In this case ]c works perfectly it jumps between diff changes. Excellent.
TEST 2: LINES WITH DIFFERENCES ARE ONE AFTER ANOTHER
File1 - the same as in test 1.
File 2:
aaa aaa
aaa ccc
aaa ccc
aaa ccc
Now lines 2, 3 and 4 are different. Cursor on first line first column and pressing ]c jumps correctly to second line at first letter of c. Now I see this difference is acceptable and I would like to jump to next difference. Executing ]c I expect to get to the next (third) row and search for difference. Like executing j0 (down and at first character in line) and then executing ]c again.
I also tested the ]c and it behaves the sames as ]x and [c behaves the same as [x on my previous post samples. I actually only need ]x and [x behavior, but just out of curiosity what suppose to be the difference between "x" and "c" commands?
P.S. Just two small typos in your script. Comments in lines 47 and 49 are the same as lines 52 and 54. Probably copy/paste problem.
File1:
aaa ccc
aaa ccc
File2:
aaa bbb
aaa bbb
If cursor is in file1 at first line first column, diff enabled and pressing ]x I expect cursor to jump to first line first c letter, but it jumps to second line first c character. It looks this problem only appears if difference is in first line. If difference is any other line but first one the problem does not appear.
@Rick, thanks for providing the info about diffchar plugin. I tested it and it is awesome. I will definitely use it for projects when I work with code. But for projects where I analyze huge data files like long lines and 3000+ rows, this plugin is understandably little bit slow. Thanks.
@Arun, I have tested your code in deep. It is working perfectly. What I have found is little trouble in the case when first line include the change.
File1:
aaa ccc
aaa ccc
File2:
aaa bbb
aaa bbb
If cursor is in file1 at first line first column, diff enabled and pressing ]x I expect cursor to jump to first line first c letter, but it jumps to second line first c character. It looks this problem only appears if difference is in first line. If difference is any other line but first one the problem does not appear.