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

  • Home
  • SEARCH
  • 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 5979755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:42:15+00:00 2026-05-22T21:42:15+00:00

I type really fast and sometimes accidentally save a file with the name consisting

  • 0

I type really fast and sometimes accidentally save a file with the name consisting of a single ; or :. (A typo is sometimes introduced as I type the :wq command.)

Is there any way to write a macro that rejects files matching certain names from being saved?

  • 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-22T21:42:16+00:00Added an answer on May 22, 2026 at 9:42 pm

    A simple yet effective solution would be to define an auto-command
    matching potentially mistyped file names, that issues a warning and
    terminates saving:

    :autocmd BufWritePre [:;]* throw 'Forbidden file name: '..expand('<afile>')
    

    Note that the :throw command is necessary to make Vim stop writing
    the contents of a buffer.

    In order to avoid getting the E605 error because of an uncaught
    exception, one can issue an error using the :echoerr command run
    in the try block—:echoerr raises its error message as an exception
    when called from inside a try construct (see :help :echoerr).

    :autocmd BufWritePre [:;]*
    \   try | echoerr 'Forbidden file name: '..expand('<afile>') | endtry
    

    If it is ever needed to save a file with a name matching the pattern
    used in the above auto-command, one can prepend a writing command
    with :noautocmd or set the eventignore option accordingly (see
    :help :noautocmd and :help eventignore for details), e.g.:

    :noa w :ok.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am I missing something or there really is no support for generic object type
I'm curious as to how often experienced Haskell programmers really use type inference in
I really like the format and type of links from RubyFlow for Ruby related
I really like the following template to create properties for class in VS2005 Type
This is probably a really stupid newbie-sounding question to you developer type people, but
This is a simple question really. I've been using the new type of constructors
I'm coming from a C# background and I really like the type inference that
I've got an ATL method that takes a DATE type, which is really a
I have searched around a bit, and have not really found a professional type
Type.GetType(System.String) Is there a lookup for the aliases available somewhere? Type.GetType(string) returns null .

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.