linux - Detecting file type for C++ standard headers with vim -
standard headers c++ typically installed in /usr/include/c++/4.x (in linux). since of headers not have extension (.h, .hpp, etc.), vim cannot recognize format these files c++.
i have seen other question in so, solutions posted in there not solve problem. 1 solution there involves using modeline standard c++ headers not include vim-friendly signature. instead, include in first line like:
// <algorithm> -*- c++ -*- i guess search pattern (-*- c++ -*-) in order detect file type. other solution posted in mentioned question goes in direction. answer suggests use:
au bufread * if search('magicpattern', 'nw') | setlocal ft=cpp | endif so have tried do:
au bufread * if search('-*- c++ -*-', 'nw') | setlocal ft=cpp | endif but not work (i.e., file type not detected).
is possible detect file type using approach? exist plugin or other way solve this?
n.m's answer trick, better:
au bufread * if search('\m-*- c++ -*-', 'n', 1) | setlocal ft=cpp | endif the argument search stopline, , ensures rule applied files pattern in line 1.
this important because, without stopline files contain pattern, including vimrc, satisfy match , potentially highlighted using wrong syntax rules.
also, using stopline w flag unnecessary.
look @ :help search more information.
Comments
Post a Comment