Friday, October 14, 2016

Re: Weird behaviour with the 'gN' command

Hi,

any update regarding this issue ?

++
Osman

2016-10-09 23:25 GMT+02:00 Osman Koçak <kocakosm@gmail.com>:
Hmmm, I see...
However, I think it should be possible to fix it since the forward search ('/') don't mess up in such cases.
I also have a "workaround" (in Vimscript) that **seems** to work (I wrote and tested it quite quickly, so I'm not sure):
function! Select_match() abort
  if &selection == 'exclusive' && stridx(&virtualedit, 'onemore') == -1
    return ''
  endif
  let [l1, c1] = getpos('''<')[1:2]
  let [l2, c2] = getpos('''>')[1:2]
  let pos = getpos('.')
  let l = pos[1] + (l2 - l1)
  let c = pos[2] + (c2 - c1)
  if l1 != l2
    let c += strwidth(getline(l1)) - strwidth(getline(pos[1]))
  endif
  execute 'normal ' . l . 'G' . c . '|v' . pos[1] . 'G' . pos[2] . '|'
endfunction
This function should behave as the 'gN' command... 

++
Osman

2016-10-09 18:01 GMT+02:00 Christian Brabandt <cblists@256bit.org>:
On So, 09 Okt 2016, Osman Koçak wrote:

> OK, can you please let me know when the patch eventually gets into Vim.
> Thanks again!

Hm, that is a tricky one and I am not sure how to solve that one.

If you take this text (here with line numbers:)
1 test test test test
2 test test test test
3 test test test test
4 test
5 test test test

The basic logic for the gN motion is, (1st) move to the next match and
from there (2nd) move to the end of the previous match, then (3rd) mark
everything until the beginning of the now current match.

However the search pattern "test\ntest" adds some uncertainty, where the
next and previous match starts. Consider your cursor on the first
character of the word test in line 3. The motion gN will first move it
to the next match, which is at the beginning of the next line (line 4),
however, at the same time, it is still part of the current match.
Therefore, jumping back to the previous match will move the cursor to
line 2 end of the first word test.

To fix that, we would need to make sure, that at step one, we have to
move over everything which is part of the current match and I really
don't know if this is possible.

I am uncertain whether this is a bug or should be documented, that gN
might not work well for overlapping multiline patterns.

Best,
Christian

--
--
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.


--
--
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:

Post a Comment