How to fix: `Marker `]` is not set in this buffer`?

By default Vim already defines some marks that can be used to move around the buffer. I noticed that '[ and '] are not bound to anything (user-error: Marker ‘]’ is not set in this buffer).

These two marks are tracking the last yank or change in the buffer. I searched in Doom repo, Evil repo, and other places but haven’t found an answer to this.

After a bit of further investigation I found what is going on. The marker [ and [ are set by evil-paste-{before,after}, for example. Therefore, the command '[ means “jumps to the line of the last paste” which is different behavior when compared to stock Vim:

'[ `[ To the first character of the previously changed or yanked text.

'] `] To the last character of the previously changed or yanked text.

We can verify the differences in behavior by opening Vim and typing anything in the buffer. If you try the two commands mentioned above, both of them will work out of the box because they take changes into account.

Not sure if there is a way to make up for this, although “move to last paste” is already good enough for me, I was expecting to have at least the “move to last yank” :confused:

For now, I’ve been using this hacky solution to enable the marker on yank:

;; fix issue with ] and [ markers in Evil
(defun bk/bring-marker-back-on-yank (&rest _)
  (evil-set-marker ?\[ (point))
  (evil-set-marker ?\] (1- (point))))

(advice-add #'evil-yank :before #'bk/bring-marker-back-on-yank)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.