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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:31:40+00:00 2026-06-05T06:31:40+00:00

Standard headers for C++ are typically installed in /usr/include/c++/4.x (in Linux). Since most of

  • 0

Standard headers for C++ are typically installed in /usr/include/c++/4.x (in Linux). Since most of the headers do not have any extension (.h, .hpp, etc.), vim cannot recognize the format for these files as C++.

I have seen this other question in SO, but the solutions posted in there do not solve my problem. One solution there involves using modeline but standard C++ headers do not include a vim-friendly signature. Instead, they include in the first line something like:

// <algorithm> -*- C++ -*-

I guess I could search for that pattern (-*- C++ -*-) in order to detect the file type. The other solution posted in the previously mentioned SO question actually goes in that direction. The answer suggests to use:

au BufRead * if search('MagicPattern', 'nw') | setlocal ft=cpp | endif

so I have tried to do:

au BufRead * if search('-*- C++ -*-', 'nw') | setlocal ft=cpp | endif

but it does not work (i.e., the file type is not detected).

Is it possible to detect the file type using that approach? Does it exist any plugin or any other way to solve this?

  • 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-06-05T06:31:45+00:00Added an answer on June 5, 2026 at 6:31 am

    n.m’s answer does the trick, but this is better:

    au BufRead * if search('\M-*- C++ -*-', 'n', 1) | setlocal ft=cpp | endif
    

    The extra argument to search is the stopline, and ensures that this rule will only be applied to files with the pattern in line 1.

    This is important because, without the stopline any files that contain the pattern, including your vimrc, will satisfy the match and potentially be highlighted using the wrong syntax rules.

    Also, using stopline the w flag is unnecessary.

    Look at :help search for more information.

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

Sidebar

Related Questions

I have not found any specification about whether duplicate HTTP response headers are allowed
Is it reasonable to put custom headers higher in include section than standard headers?
Only with standard gcc Objective-C headers. Most of all I am interesting in arrays
Possible Duplicate: parser for c++ headers to extract functions with standard linux tools? is
The published code for Palm OS applications doesn't include standard headers, but instead uses
Do I need an extern C {} block to include standard C headers in
standard power operation ( ** ) in Python does not work for negative power!
For the purposes of this question, I am interested only in Standard-Compliant C++, not
I have been making websites for years now. Most of them tend to be
Using the following steps: (I have checked this similar post , which does not

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.