Skip to content

Differences from Sam

Marc André Tanner edited this page Aug 1, 2020 · 5 revisions

Below we list some deliberate differences in behavior compared to sam and/or acme.

Multiple dots

We support multiple "dots" (or ranges, selections) at the same time, enabling a more interactive experience. In sam the following two independent commands run one after another

,x/pattern
c/replacement

have the effect that x sets dot to the last occurrence of pattern which is then subsequently replaced.

Whereas in vis the x commands creates a new selection for every occurrence of pattern and switches to visual mode. If the change command c is later executed it affects all selections.

More compact syntax

Commands within groups (braces) do not have to appear on separate lines. x/Emacs/ { i/>/ a/</ } is valid syntax.

Changes do not need to be in sequence just non-overlapping

x/Emacs/ { d i/V/ a/i/ } works as expected.

Different regex anchor behavior

In vis ^ and $ always match the beginning / end of the range they are applied to. This differs from sam where they only match the beginning / end of a line. Rob Pike writes on this topic in his Structural Regular Expressions paper:

The program to capitalize ‘i’s should be writable as

    x/[A-Za-z]+/ g/^i$/ c/I/

That is, the definition of ^ and $ should reflect the structure of the input.
For compatibility and because of some problems in the implementation, however,
^ and $ in sam always match line boundaries.

The above command works as expected in vis.

The substitute command s was dropped

Use /pattern/ c/replacement/ to substitute the first, /pattern/ // c/replacement to change the second or x/pattern/ c/replacement/ to replace all matches.

Count specifier for g and v commands

Sam's substitute command supports an explicit count specifier: s3/pattern/replacement/ indicates that only the third occurence of pattern should be substituted.

In vis a more generalized variant of the same concept has been integrated into the g and v commands.

The equivalent of the above sam command is x/pattern/ g3 c/replacement/.

Count specifier for text commands

The text given for the a, i and c commands can optionally be prefixed with a count specifier, indicating how many times it should be inserted.

\1 - \9 and & in text commands

These refer to the corresponding register values capturing the (sub) expression matches of the last performed search. & contains the complete matched text.

Hence, x/Vi/ c/>&</ has the same effect as x/Vi/ { i/>/ a/</ }.

And x/(.)-(.)/ c/\2-\1/ applied to o-O results in O-o.

\t in text commands

In addition to \n for newlines, \t can be used to specify literal tab characters.

Marks as addresses

'm where m denotes one of the vi marks can be used as an address.

Searches do not wrap around

Currently searches with +/pattern, -/pattern do not wrap around at the end (start) of the file.

Limited command prompt support for multi-line commands

Sam has a dedicated command window, whereas in vis' command prompt multi-line commands need to be entered using <Ctrl-v><Enter>.

Unsupported commands

Commands for functionality covered by traditional vi keybindings are not implemented. Examples include: m (move), t (copy), k (set mark) and u undo.

Multi-file support is not yet well supported

While the commands X and Y are recognized, multi-file support is not yet well supported and will need further design work.

See also issue #219 and the mailing list discussion.

Mouse support

The mouse is currently not used at all.

External commands

Changes of external commands < and | are only applied if they exit with success. Append || true to the command to match the sam behavior of using the output irrespective of exit status.