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 6090099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:10:30+00:00 2026-05-23T12:10:30+00:00

Is it possible to change the colorscheme in Vim when I open a .vim,

  • 0

Is it possible to change the colorscheme in Vim when I open a .vim, .htm, .html, .xml or the _vimrc file?
(also change colorscheme when I switch to an already open file with above extension)

This is what I want my vim to do:

file = txt or a new (not saved) buffer: colorscheme1 (default colorscheme)
file = vimrc, vim, html, htm: colorscheme2

I noted also that my vim doesn’t detect all filetypes.
Text files are not recognized as text file.

ps:
If this is not possible would it be possible to switch to another colorscheme and keep it when I restart VIM (without changing something in vimrc)?


edit:

Found the solution with an autocmd:

augroup filetype_colorscheme
    au BufEnter *
    \ if !exists('b:colors_name')
        \ | if &ft == "vim" || &ft == "html"
            \ | let b:colors_name = 'colorscheme 2'
        \ | else
            \ | let b:colors_name = 'colorscheme 1'
        \ | endif
    \ | endif
    \ | exe 'colorscheme' b:colors_name
augroup END 

still one problem:
above code changes the colorscheme of all files in a split window when I click in a buffer

Is there a way to desactivate (and reactivate) an autocmd using a shortcut key?

  • 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-23T12:10:31+00:00Added an answer on May 23, 2026 at 12:10 pm

    You should be able to achieve something close to what you want with the following autocommands:

    colo <colourscheme1>  "default
    autocmd! BufEnter,BufNewFile *.html,*.vim,*xml colo <colourscheme2>
    autocmd! BufLeave *.html,*.vim,*xml colo <colourscheme1>
    

    And of course you can modify the list of file extensions as you wish. The colourscheme will be <colourscheme1> by default, or <colourscheme2> if you open (or switch to) any of the specified types, and will revert to <colourscheme1> when you open (or switch to) any other type within a Vim session.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to change the name of an already open memory mapped file,
Possible Duplicate: Change CSS Dynamically I need to change the height of a div
Is it possible to change the width of a scroll bar on a form.
Is it possible to change the font size used in a ContextMenu using the
Is it possible to change a Sharepoint 2007 Site Theme through a Web Service?
Is it possible to change the frame title when using \againframe from the Beamer
Is it possible to change the auto-increment offset on a pre-existing table with JavaDB?
Is it possible to change the connection string of a bound dataset during runtime?
I know it's possible to change some columns in GridView controls to check boxes
I was wondering if it was possible to change the my Shoes app's icon?

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.