Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 977261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:52:31+00:00 2026-05-16T03:52:31+00:00

Is there anyway (internal or via a plugin) to prevent marks to be overridden

  • 0

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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:52:32+00:00Added an answer on May 16, 2026 at 3:52 am

    You may remap the m with custom function:

    let s:marks={}
    function s:SetMark()
        let m=getchar()
        if type(m)==type(0)
            let m=nr2char(m)
        endif
        if m=~#'^[a-zA-Z]$'
            if has_key(s:marks, m)
                throw "Mark ".m."is arleady set"
            endif
            let s:marks[m]=1
        endif
        return "m".m
    endfunction
    nnoremap <expr> m <SID>SetMark()
    

    This function will prevent you from remapping mark. That is how it works:

    1. We define a dictionary, which keys contain already set marks (actually we could use a list, but dictionary should be a bit faster).
    2. We define a function that:
      1. Pick next symbol. As getchar may return either a string or a character number, we must convert it back to string.
      2. Checks whether we are going to set a mark (you can have mark with name 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 using m', m[ and m] since we cannot prevent redefining them by vim itself.
      3. Checks whether mark in question was already set by this function, throws a error if it was.
      4. Returns text mC, where C is your mark name.
    3. We define a mapping that uses this function returned value as {rhs}.

    Note that this will not prevent somebody from redefining this mark by normal! (but not normal without a bang) command, nnoremap (but not nmap) mapping or something similar.

    UPDATE: Modified version of s:SetMark:

    function s:SetMark()
        let m=getchar()
        if type(m)==type(0)
            let m=nr2char(m)
        endif
        if m=~#'^[A-Z]$'
            let pos=getpos("'".m)
            if pos[1]
                echohl Error
                echon "Mark ".m." is arleady set. Overwrite?"
                echohl None
                let c=getchar()
                if type(c)==type(0)
                    let c=nr2char(c)
                endif
                echo
                if c!=?'y'
                    return "<C-l>"
                endif
            endif
        endif
        return "m".m
    endfunction
    nnoremap <special><expr> m <SID>SetMark()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to serialize a property with an internal setter in C#?
Is there any way of accessing the internal SD card on Android devices that
Is there a way to test if a collection is already initialized? try-catch only?
I there anyway that I can install a SharePoint web application not on the
Is there anyway to have a sort of virtual static member in C++? For
Is there anyway to configure a WCF service with a failover endpoint if the
Is there anyway in Java to delete data (e.g., a variable value, object) and
Is there anyway to upgrade the installed JRE in the system? We are having
Is there anyway to declare an object of a class before the class is
Is there anyway to combine all resources into a single exe file such as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.