<ScriptCmd> doesn't make sure the visual marks are updated

15 views
Skip to first unread message

Christian J. Robinson

unread,
Jan 31, 2022, 4:19:48 PM1/31/22
to vim_dev

I have several visual mappings that could benefit from <ScriptCmd> but they call functions that rely on the `< and `> marks to be properly set, and <ScriptCmd> doesn't make sure they are "current" so the marks from a previous visual selection are used.

If I prefix the <ScriptCmd> with <C-C> the marks update.

It took me a while to figure this out as the behavior was so strange to me (and my mappings/functions are fairly complex).

- Christian

--
Christian J. Robinson <hep...@gmail.com>

Bram Moolenaar

unread,
Feb 1, 2022, 6:13:39 AM2/1/22
to vim...@googlegroups.com, Christian J. Robinson

Christian J. Robinson wrote:

> I have several visual mappings that could benefit from <ScriptCmd> but they
> call functions that rely on the `< and `> marks to be properly set, and
> <ScriptCmd> doesn't make sure they are "current" so the marks from a
> previous visual selection are used.
>
> If I prefix the <ScriptCmd> with <C-C> the marks update.
>
> It took me a while to figure this out as the behavior was so strange to me
> (and my mappings/functions are fairly complex).

I don't understand what you mean. The <ScriptCmd> mapping doesn't do
anything with the '< and '> marks. And I don't see how CTRL-C does
anything but end Visual mode.

The idea with <ScriptCmd> is that it can be used in any mode and returns
to that mode after doing its work.

--
Never under any circumstances take a sleeping pill
and a laxative on the same night.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian J. Robinson

unread,
Feb 1, 2022, 9:30:54 AM2/1/22
to Bram Moolenaar, vim_dev
I have attached a demonstration script. If you edit then source it in a new Vim instance you will get "0 0" then "1 1" echoed into the message history, but it should be "1 1" then "2 2".

If you change the \test mapping to have a preceding <c-c> in the rhs, you get the expected output, which is "1 1" then "2 2".
scriptcmd_visual_bug.vim

Bram Moolenaar

unread,
Feb 1, 2022, 11:04:42 AM2/1/22
to vim...@googlegroups.com, Christian J. Robinson

Christian J. Robinson wrote:

> I have attached a demonstration script. If you edit then source it in a new
> Vim instance you will get "0 0" then "1 1" echoed into the message history,
> but it should be "1 1" then "2 2".
>
> If you change the \test mapping to have a preceding <c-c> in the rhs, you
> get the expected output, which is "1 1" then "2 2".

This is unlreated to using <ScriptCmd>. While Visual mode is active the
'< and '> marks are still set to the previously selected text. This is
mentioned at the help for these marks.

Instead of using that, you can use line('v'). The help for that:

v In Visual mode: the start of the Visual area (the
cursor is the end). When not in Visual mode
returns the cursor position. Differs from |'<| in
that it's updated right away.


--
Lower life forms have more fun!

Christian J. Robinson

unread,
Feb 1, 2022, 11:29:01 AM2/1/22
to Bram Moolenaar, vim_dev
Somehow I missed that, and I apologize. This solves my problem.
Reply all
Reply to author
Forward
0 new messages