Execute-keys and registers

Guys, I can’t get why when I do

execute-keys <a-i>w*

on someword I see the message register '/' set to '\bsomeword\b, however / register isn’t changed, and contains old value. I didn’t specified a -save-regs switch, so I expect my default search register to be changed to the current selection, but it’s not happening. Am I missing something?

In :doc execeval you can see the following:

So if you don’t want exec to restore registers, you have to do exec -save-regs '' <a-i>w*.
As a side-note, it used to be that both eval and exec restore the default registers, but this was changed somewhat recently.

Ah, I misreaded the docs. I thought that execute-keys will save those regs if I specify -save-regs switch. Thanks!

Reviving the topic…

Having been burned by the (lack of) -save-regs, I have learned to never script things such as exec d or exec *, but write instead exec -save-regs %{} d or exec -save-regs %{} *.

Yet today I was surprised to see the opposite case: with the search command, -save-regs seems unnecessary. On my version at least (the one available on Debian testing/unstable) exec / will open the search prompt and let you search for “foo” the usual way. Typing n will later select the next instance of “foo”, which shows that the search register was updated correctly.

(To complicate things further, scripting exec /foo<ret> will find “foo” correctly once, but typing n will not select the next instance of “foo”.)

Has anyone on the list noticed this behavior? It seems inconsistent with the docs, because / is a normal-mode command and “should” not update the search register in the absence of the -save-regs ... switch.

Presumably this has something to do with the fact that when the search prompt opens, we are in the Prompt mode. Still, isn’t the search command (/) a Normal-mode command?

As I understand it, when you do:

exec /foo<ret>

…the following things happen:

  1. / is in the default value of -save-regs for exec, so the current contents of the / register are saved
  2. The / key is executed, opening the search prompt
  3. The keys foo are executed, searching for that string
  4. The <ret> key is executed, selecting the first match and adding foo to the / register
  5. Now that all the given keys have been executed, the previous value of the / register is restored.

When you do:

exec /

…the following things happen:

  1. / is in the default value of -save-regs for exec, so the current contents of the / register are saved
  2. The / key is executed, opening the search prompt
  3. Now that all the given keys have been executed, the previous value of the / register is restored.
  4. If the user then types foo and hits <ret> the first match is selected, and foo is added to the / register
1 Like