Ed bookmarks disappear after a global replacement
If I make a bookmark in
ed for an address by invoking
k plus any other letter, I can return to that address later by invoking
'+letter. I frequently make these bookmarks, especially when navigating a long document.
However, if I create such a bookmark and then perform a global substitution (such as
g/vim/s//ed/g) when I try to return to the address I bookmarked it is gone and
ed gives me
Invalid address. This is strange because it is especially after invoking a global substitution that one would like to return to the place where one was previously because global substitutions reset
dot to the last edited line.
Am I missing something here?
The mark set with the
k command is cleared when the line that it refers to is either deleted or modified. The mark is not cleared if the line is shifted by the deletion or insertion of other lines.
This is documented in the GNU
ed manual (
info ed) where it’s describing the
[…] The mark is not cleared until the line is
deleted or otherwise modified. […]
ed manual has the same wording.
The POSIX standard text does not document this in relation to the
k command, but says for the
g command that…
[…] Any line modified by the command list shall be unmarked. […]