• <bdo id='wALSi'></bdo><ul id='wALSi'></ul>

      <i id='wALSi'><tr id='wALSi'><dt id='wALSi'><q id='wALSi'><span id='wALSi'><b id='wALSi'><form id='wALSi'><ins id='wALSi'></ins><ul id='wALSi'></ul><sub id='wALSi'></sub></form><legend id='wALSi'></legend><bdo id='wALSi'><pre id='wALSi'><center id='wALSi'></center></pre></bdo></b><th id='wALSi'></th></span></q></dt></tr></i><div id='wALSi'><tfoot id='wALSi'></tfoot><dl id='wALSi'><fieldset id='wALSi'></fieldset></dl></div>
    1. <small id='wALSi'></small><noframes id='wALSi'>

      1. <legend id='wALSi'><style id='wALSi'><dir id='wALSi'><q id='wALSi'></q></dir></style></legend>

        <tfoot id='wALSi'></tfoot>
      2. 我可以让 vim 在没有扩展的 C++ 头文件上做语法高亮吗?

        Can I make vim do syntax highlighting on C++ headers that don#39;t have extensions?(我可以让 vim 在没有扩展的 C++ 头文件上做语法高亮吗?)

              <small id='mnJwa'></small><noframes id='mnJwa'>

                <tbody id='mnJwa'></tbody>
              <legend id='mnJwa'><style id='mnJwa'><dir id='mnJwa'><q id='mnJwa'></q></dir></style></legend>
                <bdo id='mnJwa'></bdo><ul id='mnJwa'></ul>

                  <tfoot id='mnJwa'></tfoot>

                  <i id='mnJwa'><tr id='mnJwa'><dt id='mnJwa'><q id='mnJwa'><span id='mnJwa'><b id='mnJwa'><form id='mnJwa'><ins id='mnJwa'></ins><ul id='mnJwa'></ul><sub id='mnJwa'></sub></form><legend id='mnJwa'></legend><bdo id='mnJwa'><pre id='mnJwa'><center id='mnJwa'></center></pre></bdo></b><th id='mnJwa'></th></span></q></dt></tr></i><div id='mnJwa'><tfoot id='mnJwa'></tfoot><dl id='mnJwa'><fieldset id='mnJwa'></fieldset></dl></div>

                • 本文介绍了我可以让 vim 在没有扩展的 C++ 头文件上做语法高亮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个项目,其中包含一堆遵循标准 C++ 头文件命名约定的 C++ 头文件;也就是说,一个名为 Foo 的类将在名为 Foo 的文件中声明,而不是在 Foo.hFoo.hh 中声明.有没有一种好方法可以配置 vim 来仅对这些文件进行语法高亮显示?一个不太令人愉快的回退是为所有没有扩展名的文件启用 C++ 风格的突出显示.我不确定是否有任何更复杂的方法来检测文件的类型,而不是仅仅依靠其扩展名.

                  I have a project with a bunch of C++ header files that follow the standard C++ header naming convention; that is, a class called Foo would be declared in a file called Foo, not Foo.h or Foo.hh. Is there a good way to configure vim to do syntax highlighting for these files only? A slightly-less-pleasing fallback would be to enable C++-style highlighting for all files that don't have an extension. I'm not sure if there's any more sophisticated way to detect the type of file instead of relying solely on its extension.

                  推荐答案

                  您可以为此使用 modeline 功能.模式行允许您在文件的前几行/最后几行的注释中设置某些选项.

                  You can use the modeline feature for this. Modelines allow you to set certain options from within a comment in the first/last few lines of your file.

                  这使它成为设置编码指南、折叠参数的好地方.出于安全原因,无法设置某些选项.有关详细信息,请参阅文档.

                  This makes it a great place to set parameters for coding guidelines, folding. Some options cannot be set for security reasons. See the documentation for more information.

                  把它放在文件的顶部或底部:

                  Put this at the top or bottom of the file:

                  /* vim: set ft=cpp: */
                  

                  更多详细信息,由评论提示:) :

                  More details, prompted by the comments :) :

                  它只有在模式行启用时才有效.在正常情况下,它应该是默认的.要确保启用它,或更改检测到的区域的大小,请在 .vimrc 中设置 modeline 选项:

                  It will only work if modeline is enabled. In normal circumstances it should be by default. To make sure it is enabled, or to change the size of the area it is detected in, set the modeline option in your .vimrc:

                  set modelines=5
                  

                  将确保在每个文件的前五行或最后五行中检测到上面引用的行.

                  will make sure the line like the one quoted above will be detected in the first five or the last five lines of each file.

                  在modeline中,setlocal的意思是为文件加载的缓冲区设置选项.ft选项,也称为filetype, 是决定语法高亮语言的因素.值 cpp 是 C++ 文件使用的值.

                  Inside the modeline, setlocal means to set options for the buffer the file is loaded in. The ft option, also known as filetype, is what determines the syntax highlighting language. The value cpp is the one that is used by C++ files.

                  编辑 2:没有模式行,多做一点工作,如果你能识别出一个神奇的模式:

                  EDIT 2: Without the modeline, with a bit more work, if you can identify a magic pattern:

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

                  含义:每次打开文件时,检查"MagicPattern"是否在其中.如果是,则将其视为 C++.模式参数是正则表达式的 vim 方言;查看帮助模式了解详情.

                  Meaning: Every time you open a file, check if "MagicPattern" is in there. If it is, treat it as C++. The pattern argument is in vim dialect of regular expressions; check help pattern for details.

                  这篇关于我可以让 vim 在没有扩展的 C++ 头文件上做语法高亮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)

                  <legend id='b1E0y'><style id='b1E0y'><dir id='b1E0y'><q id='b1E0y'></q></dir></style></legend>
                    • <bdo id='b1E0y'></bdo><ul id='b1E0y'></ul>

                      <tfoot id='b1E0y'></tfoot>
                      <i id='b1E0y'><tr id='b1E0y'><dt id='b1E0y'><q id='b1E0y'><span id='b1E0y'><b id='b1E0y'><form id='b1E0y'><ins id='b1E0y'></ins><ul id='b1E0y'></ul><sub id='b1E0y'></sub></form><legend id='b1E0y'></legend><bdo id='b1E0y'><pre id='b1E0y'><center id='b1E0y'></center></pre></bdo></b><th id='b1E0y'></th></span></q></dt></tr></i><div id='b1E0y'><tfoot id='b1E0y'></tfoot><dl id='b1E0y'><fieldset id='b1E0y'></fieldset></dl></div>

                      <small id='b1E0y'></small><noframes id='b1E0y'>

                        <tbody id='b1E0y'></tbody>