Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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:</p> <pre><code>map ; :call Semicolon()&lt;CR&gt; function Semicolon() let s:pos1 = getpos(".") normal! ; let s:pos2 = getpos(".") if s:pos1 == s:pos2 normal! 2; endif endfunction </code></pre> <p>The basic idea is that <code>;</code> will not move to the next match, but <code>2;</code> will (if there is a match). The script supports <code>;</code> after any of <code>tTfF</code>. The easiest way to implement the <code>,</code> command is to write a similar function for that.</p> <p><strong>EDIT</strong> Changed the script after Luc's excellent suggestion</p> <p><strong>EDIT2</strong></p> <p>OK, these things are always more difficult than I originally think. The current mapping has the following problems:</p> <ol> <li>Suppose you did a search like <code>tr</code> above. Now what should <code>d;</code> or <code>c;</code> do? As far as I'm concerned they should delete or change up until the first <code>r</code> not the second. This can be solved by only doing the mapping for normal and visual mode, not operator pending mode.</li> <li>The current mapping does not work in visual mode. i.e., if you type <code>v;;;;</code> after the first <code>;</code> the editor is no longer in visual mode (because of the <code>:call</code>). This can be solved by calling the function using <code>@=</code> instead of <code>:call</code>.</li> </ol> <p>So now I end up with the following in my .vimrc (I also made one function for <code>,</code> and <code>;</code>):</p> <pre><code>" Remap ; and , commands so they also work after t and T " Only do the remapping for normal and visual mode, not operator pending " Use @= instead of :call to prevent leaving visual mode nmap ; @=FixCommaAndSemicolon(";")&lt;CR&gt; nmap , @=FixCommaAndSemicolon(",")&lt;CR&gt; vmap ; @=FixCommaAndSemicolon(";")&lt;CR&gt; vmap , @=FixCommaAndSemicolon(",")&lt;CR&gt; function FixCommaAndSemicolon(command) let s:pos1 = getpos(".") execute "normal! " . a:command let s:pos2 = getpos(".") if s:pos1 == s:pos2 execute "normal! 2" . a:command endif return "" endfunction </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload