I am looking for a way to save and restore marks at the beginning and end of my custom Vimscript function. I am writing a plugin and I don't want my plugin to change any of the user's marks, so I would like to save the state at the beginning of my function, execute some commands which create marks, and then at the end restore the original state of the marks. Similar how we can do
let l:old_value = getreg("q")
--- some work ---
setreg("q", l:old_value)
I've read the docs and googled around, but couldn't find any way of saving and restoring a mark in this way.
getpos()
,setpos()
, and/orgetmarklist()
getpos()
andsetpos()
is that it doesn't get updated if some text is inserted/deleted above the mark. However,getmarklist()
seems to be what I was looking for. Do you know if there's a builtin way to create a mark from a dictionary entry ingetmarklist()
or do I have to parse it manually, go to the position, create mark, and then go back to previous position?setpos()
.getpos()
is not updated, after inserting/deleting text above a mark.