Is there anyway (internal or via a plugin) to prevent marks to be overridden ?
I mean a way so you can’t set a mark if it’s already used (I’m thinking especially of global marks).
I’m thinking of adding them in my vimrc or session, but I would prefer another way.
Update
Don’t send me a script to do it. I can do it myself, my question was more if there is a hidden way in VIM to do it or if I had to write a script myself. The answer is apparently no.
Thanks anyway to people who already sent me a script. I’ll use them to write my own one (as the scripts sent are not exactly what I want)
You may remap the
mwith custom function:This function will prevent you from remapping mark. That is how it works:
getcharmay return either a string or a character number, we must convert it back to string.a, but not with name%). If you try to set mark%, it would be ignored by vim, so no need to keep useless keys. And no need to prevent you from usingm',m[andm]since we cannot prevent redefining them by vim itself.mC, whereCis your mark name.{rhs}.Note that this will not prevent somebody from redefining this mark by
normal!(but notnormalwithout a bang) command,nnoremap(but notnmap) mapping or something similar.UPDATE: Modified version of s:SetMark: