Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call a function that moves the cursor without leaving visual mode?
    text
    copied!<p>I have a function that moves the cursor with the built-in <code>cursor()</code> function and it works fine on normal mode.<br> For concreteness suppose that this is the function:</p> <pre><code>function! F() call cursor( line('.')+1, 1) endfunction </code></pre> <p>used with a mappings as:</p> <pre><code> nnoremap &lt;buffer&gt; a :call F()&lt;cr&gt; </code></pre> <p>Now I want to reuse this function to move the cursor on any visual mode (visual, line visual, and block visual) and without losing the previous selection.</p> <p>For example, with an initial buffer in visual mode (<code>c</code> means the cursor is at a line, <code>v</code> means the line is part of the current visual selection):</p> <pre><code>vc 1 2 3 </code></pre> <p>hitting <code>a</code> would give:</p> <pre><code>v 1 vc 2 3 </code></pre> <p>and hitting <code>a</code> again would give:</p> <pre><code>v 1 v 2 vc 3 </code></pre> <p>so the old selection was kept.</p> <p>I would like to reuse <code>F()</code> as much as possible, since in my application <code>F()</code> is quite large.<br> What is the best way to do that?</p> <p>Up to now, the best I could do was use a wrapper function:</p> <pre><code>function! VisMove(f) normal! gv call function(a:f)() endfunction </code></pre> <p>and map as:</p> <pre><code> vnoremap &lt;buffer&gt; a :call VisMove('F')&lt;cr&gt; </code></pre> <p>however I am not satisfied because this:</p> <ol> <li>It requires putting the annoying wrapper on every new fgplugin I write.</li> <li>Calling a function that moves the cursor (or has other arbitrary side effects) without ever leaving visual (current) mode seems like such a natural thing to be able to do. There is even already <code>&lt;expr&gt;</code> which almost does it, but it resets cursor position.</li> </ol>
 

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