sponsor Vim development Vim logo Vim Book Ad

basic Tip #602: How to remove one mark or all marks at once

 tip karma   Rating 1/11, Viewed by 1833 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   November 1, 2003 0:55      complexity:   basic
author:   Remove marks      as of Vim:   6.0

To remove a mark you can use \mh in normal mode. Go to the mark and type \mh.

If you are using marks in a script you can use the function below.
Then you would write e.g.

function! MyFunction()
kl "set mark l
"do something
call RemoveMark("l") "Mark l is no longer used, remove it

Here is the function:

function! RemoveMark(mark)
exe "normal '" . a:mark "go to the mark
normal \mh "remove it

If you want to remove all  your marks in normal mode you can use the mapping
map \rm :call RemoveMarks()<cr>

It calls the function:

function! RemoveMarks()
call RemoveMark("a")
call RemoveMark("b")
call RemoveMark("c")
call RemoveMark("d")
call RemoveMark("e")
call RemoveMark("f")
call RemoveMark("g")
call RemoveMark("h")
call RemoveMark("i")
call RemoveMark("j")
call RemoveMark("k")
call RemoveMark("l")
call RemoveMark("m")
call RemoveMark("n")
call RemoveMark("o")
call RemoveMark("p")
call RemoveMark("q")
call RemoveMark("r")
call RemoveMark("s")
call RemoveMark("t")
call RemoveMark("u")
call RemoveMark("v")
call RemoveMark("w")
call RemoveMark("x")
call RemoveMark("y")
call RemoveMark("z")

Could you think of other possibilities?
Please share it with us.

I am using the try-catch clause so the following works only for >= vim 6.2.
If you want to use the functions for an older version remove the try-catch

Happy vimming


 rate this tip  Life Changing Helpful Unfulfilling 

<< Tag with line:column | Bookmarks as menu item >>

Additional Notes

Klaus Horsten, November 1, 2003 1:12

I put the title in the wrong field (in the author field).

Pair programming would be good.

Anonymous, November 2, 2003 12:18
cec@NgrOyphSon.gPsfAc.nMasa.gov, November 3, 2003 6:42
\mh is a mapping to s:ShowMarksClearMark(), which is provided by the
<showmarks.vim> plugin (see vimscript#152).  So don't expect the \mh
command to work without that plugin.  Furthermore, the plugin doesn't
actually remove the mark; instead, it moves it to line 1.
juhas@seas.upenn.edu, November 8, 2003 20:09
To remove all marks you can also use  :%!cat  on unix or  :%!type  on windows.
Anonymous, November 13, 2003 20:45
Removing all marks the way the tip suggests is FAR more efficient than using type or cat; it doesn't spawn an external process, for one and will execute in fixed time regardless of the size of the buffer, for another.  Not to be mean, but I think alternatives to tips should be posted only if they actually IMPROVE upon the tip.
drchip@campbellfamily.biz, November 14, 2003 13:48
As I mentioned above, \mh doesn't remove marks.  It doesn't work at all without the <showmarks.vim> plugin.

The \mh map moves marks to line 1.

The !cat /!type solution, on the other hand, actually does result in the removal of the marks.  Seems like a good idea to me to present a real solution.
Anonymous, November 26, 2003 9:54
Wouldn't it be easier (and maybe more efficient) to use something like "%d | put | 1d" to remove all marks? (Or did I miss something here?)
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge.net Logo