Inconsistent behaviour of 't' compared to 'f'

17 views
Skip to first unread message

Sergii Boiko

unread,
Oct 13, 2010, 5:45:48 AM10/13/10
to vim_dev
When you work in normal mode and use 'f' for moving to some char, it
can be repeated by ';' combination. But it's not a case for 't'. When
you hit till-symbol and then press ';' cursor sticks and can't move
further. So, to repeat till-search you should shift cursor one
position further.

I suggest change behaviour of 't' to be more handy and useful. So in
case you already before 'till-char' combination t-char moves you to
next till-char. And ';' combination works in the same fashion for
repeating last till-search.

For example (i'll mark cursor position with _char-on-wich-cursor-is-
located_):

# _s_ome piece of text

you hit 'te', cursor moves to 'm':

# so_m_e piece of text

now you press ';' and cursor moves to 'i':

# some p_i_ece of text

now if you press 'te' cursor goes to 't':

# some piece of _t_ext

Ben Fritz

unread,
Oct 13, 2010, 12:45:02 PM10/13/10
to vim_dev


On Oct 13, 4:45 am, Sergii Boiko <cris.k...@gmail.com> wrote:
> When you work in normal mode and use 'f' for moving to some char, it
> can be repeated by ';' combination. But it's not a case for 't'. When
> you hit till-symbol and then press ';' cursor sticks and can't move
> further. So, to repeat till-search you should shift cursor one
> position further.
>
> I suggest change behaviour of 't' to be more handy and useful. So in
> case you already before 'till-char' combination t-char moves you to
> next till-char. And ';' combination works in the same fashion for
> repeating last till-search.
>

On the contrary, I think it is the proposed new behavior that is
inconsistent. See what happens when you use a count:

fp2; will move to the 3rd 'p' on a line.
tp2; will currently move to just before the 3rd 'p' on a line. Your
proposal would move to just before the 4th.

Or when you aren't in exactly the same place to start with:

0dtpj0d; will delete from the start of the line to the first 'p' AND
DO THE SAME ON THE NEXT LINE. Your proposal would delete from the
start of the line to just before the 2nd 'p' on the next line.

Ingo Karkat

unread,
Oct 14, 2010, 2:48:53 AM10/14/10
to vim...@googlegroups.com

I think you misunderstood the proposal. The jump behavior of ';' will only
change if the cursor currently is before the 'till-char'; the behavior would not
change in all other locations (as in your last example, on the start of the
line). This would eliminate the "no-op" nature of a (countless) ';' command in
those places.

It seems like a useful change (that, because it breaks vi-compatibility, would
need to be configurable in 'cpoptions'). Before providing a patch, it may be
worthwhile to send around a Vimscript prototype (i.e. a mapping override of 't'
and ';') first, so that more interested people could easily try this out and
voice their opinions.

-- regards, ingo

Sergii Boiko

unread,
Oct 14, 2010, 4:00:10 AM10/14/10
to vim_dev
Sorry, I've done mistake. In last case cursor moves to 'c':

# some pie_c_e of text

Sergii Boiko

unread,
Oct 14, 2010, 5:33:56 AM10/14/10
to vim_dev
Ingo, thanks for positive comment. Because i'm switching to dvorak and
'f' isn't so useful at this layout as 't'. And this behaviour very
annoys me, because 't' is not so handy as 'f'.

I don't know vim-script very well to write some prototype, but if
someone takes care of it, i will test it thoroughly.

Romain Chossart

unread,
Oct 15, 2010, 9:01:59 AM10/15/10
to vim...@googlegroups.com
I almost created a topic for that a few months ago.

Basically, I agree with Sergii.

Cheers
--
Romain Chossart

> --
> You received this message from the "vim_dev" 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
>

Ben Fritz

unread,
Oct 15, 2010, 3:07:14 PM10/15/10
to vim_dev


On Oct 14, 4:33 am, Sergii Boiko <cris.k...@gmail.com> wrote:
> Ingo, thanks for positive comment. Because i'm switching to dvorak and
> 'f' isn't so useful at this layout as 't'. And this behaviour very
> annoys me, because 't' is not so handy as 'f'.
>
> I don't know vim-script very well to write some prototype, but if
> someone takes care of it, i will test it thoroughly.
>

Here's a quick proof-of-concept, for the ';' command only. It may fail
in some situations. I couldn't get it working right in visual mode:

nnoremap ; :<C-U>call DoubleJumpIfNoMove(v:count1)<CR>
onoremap ; v:<C-U>call DoubleJumpIfNoMove(v:count1)<CR>

fun! DoubleJumpIfNoMove(count)
if a:count==1
let curpos=getpos('.')
normal! ;
if curpos==getpos('.')
normal! 2;
else
normal! ;
endif
else
exec 'normal! '.a:count.';'
endif
endfun

Ben Fritz

unread,
Oct 16, 2010, 12:08:11 AM10/16/10
to vim_dev


On Oct 15, 2:07 pm, Ben Fritz <fritzophre...@gmail.com> wrote:
> On Oct 14, 4:33 am, Sergii Boiko <cris.k...@gmail.com> wrote:
>
> > Ingo, thanks for positive comment. Because i'm switching to dvorak and
> > 'f' isn't so useful at this layout as 't'. And this behaviour very
> > annoys me, because 't' is not so handy as 'f'.
>
> > I don't know vim-script very well to write some prototype, but if
> > someone takes care of it, i will test it thoroughly.
>
> Here's a quick proof-of-concept, for the ';' command only. It may fail
> in some situations. I couldn't get it working right in visual mode:
>

And here is a more complete solution, with visual mode and the ,
motion also working:

nnoremap ; :<C-U>call DoubleJumpIfNoMove(v:count1, ';')<CR>
onoremap ; v:<C-U>call DoubleJumpIfNoMove(v:count1, ';')<CR>
xnoremap ; :<C-U>call DoubleJumpIfNoMove(v:count1, ';', 1)<CR>
nnoremap , :<C-U>call DoubleJumpIfNoMove(v:count1, ',')<CR>
onoremap , v:<C-U>call DoubleJumpIfNoMove(v:count1, ',')<CR>
xnoremap , :<C-U>call DoubleJumpIfNoMove(v:count1, ',', 1)<CR>

fun! DoubleJumpIfNoMove(count, op, ...)
let cmdprefix=''
if a:0
normal! gv
endif
if a:count==1
let curpos=getpos('.')
exec 'normal!' a:op
if curpos==getpos('.')
exec 'normal! 2'.a:op
endif
else
exec 'normal! '.a:count.a:op
endif
endfun

Sergii Boiko

unread,
Oct 18, 2010, 9:13:26 AM10/18/10
to vim_dev
Thank you, Ben.

I'll test it and write feedback.
Reply all
Reply to author
Forward
0 new messages