Okay, suppose we have a line of text:
[s]tackoverflow rocks
where the brackets show the location of the cursor, in normal mode. After pressing tr, you get:
stackov[e]rflow rocks
Now for the fun part. What happens if you push ; to repeat the command? Nothing! Vim finds the next ‘r’ (immediately to the right of the cursor) and positions itself just left of that (where it already was).
I would prefer that ; advance the cursor to this position:
stackoverflow[ ]rocks
This can be achieved by using l to move right one character before pressing ;, but the extra step is irritating. There is a similar issue with T, but not with f and F. Is there some way to make ; behave the way I want with t and T?
Maybe it’s not the answer you are looking for but I could not resist writing a VIM script for this. I put it in my .vimrc and it works for me:
The basic idea is that
;will not move to the next match, but2;will (if there is a match). The script supports;after any oftTfF. The easiest way to implement the,command is to write a similar function for that.EDIT
Changed the script after Luc’s excellent suggestion
EDIT2
OK, these things are always more difficult than I originally think. The current mapping has the following problems:
trabove. Now what shouldd;orc;do? As far as I’m concerned they should delete or change up until the firstrnot the second. This can be solved by only doing the mapping for normal and visual mode, not operator pending mode.v;;;;after the first;the editor is no longer in visual mode (because of the:call). This can be solved by calling the function using@=instead of:call.So now I end up with the following in my .vimrc (I also made one function for
,and;):