emacs-evil / evil

The extensible vi layer for Emacs.
GNU General Public License v3.0
3.37k stars 281 forks source link

Inconsistent global (:g) behavior #1216

Open Kwelity opened 4 years ago

Kwelity commented 4 years ago

Issue type

Environment

Emacs version: 26.3 Operating System: Arch Linux (5.4.3) Evil version: 1.3.0 Evil installation type: Doom emacs Graphical/Terminal: Both Tested in a make emacs session (see CONTRIBUTING.md): No

Reproduction steps

one
first
two
second
three
third

exec the global (multi-repeat) cmd: :g/^/normal J to exec normal 'J' (join) command to every match

Expected behavior

the behavior I get with vim:

one first
two second
three third

Actual behavior

one first two second three third

Further notes

It seems that evil will 'recurcively' execute the :g command, resulting in a single line, whereas vim, will only execute the normal command once.

TheBB commented 4 years ago

Yeah, the reason this happens is that our global implementation first finds all the lines where the pattern matches and marks them, then runs through all the markers and operates on them. I expect it'll break on most commands that manipulate across newlines.

I'm not sure about the exact semantics of Vim's implementation though. I suppose it finds a match, operates on it, moves to the next line and continues. Sort of like n.j0n.j0n.j0... would behave. I tried a quick and dirty fix but it broke some other tests so I'll have to look at it later. (Or someone else can do it.)