Skip to content
Bruno Heridet edited this page Sep 28, 2017 · 1 revision

eval / exec commands are very powerful construct. They support many switches that may be hard to understand at first. This page attempts to clarify their usage.

-itersel

run once for each selection with that selection at the only one

Let's start by a simple buffer content:

foo
bar
qux

and make 3 selections with: wCC. The main selection is therefore on qux.

def no-loop %{
  eval %{
    echo -debug %val{selection}
    echo -debug %val{selections}
  }
}

If we run the above no-loop command, here's the output of the `debug buffer:

qux
foo:bar:qux

Now, let's add the -itersel switch:

def loop %{
  eval -itersel %{
    echo -debug %val{selection}
    echo -debug %val{selections}
  }
}

This time, if we run this loop command, here's the debug output:

foo
foo
bar
bar
qux
qux

A few things to observe:

  • the iteration starts from foo despite the fact that qux is our main selection. If the main selection was bar (by rotating with the ' command), the result would be the same.
  • as stated in the description of the itersel switch, in each loop, %val{selection} == %val{selections}
Clone this wiki locally