使用 vim/cindent 在 C++ 文件中配置注释许可证 header 的缩进

Configuring indentation of commented license header in C++ file with vim/cindent

我的编码风格有一个很好的缩进配置,但是如果我重新缩进 vim.

中的所有文件,我的文件的许可证 header 重新缩进不正确

许可证 header :

/* =========================================================================

  Program:   Visualization Toolkit
  Module:    vtkPeriodicArray.txx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

    This software is distributed WITHOUT ANY WARRANTY; without even
    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    PURPOSE.  See the above copyright notice for more information.

 ========================================================================= */

我的.vimrc(相关部分):

:set tabstop=2    "Number of spaces a TAB in the text stands for  
:set shiftwidth=2 "Number of spaces used for each step of (auto)indent
:set expandtab
:set cindent
:set cinoptions={1s,t0,f0s,g0,i0,(0

希望的结果:许可证没有变化header缩进

看到的结果:

/* =========================================================================

Program:   Visualization Toolkit
Module:    vtkPeriodicArray.txx

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notice for more information.

========================================================================= */

我找到了解决方法。我只是将以下命令映射到我的 .vimrc 中:

map <F12> gg=G\|:3,12>\|:10,12> <Enter> <Enter>

它将 F12 键映射到:

  • 重新缩进所有文件
  • 第 3 行到第 12 行缩进一次
  • 第 10 行到第 12 行缩进一次

所以它非常适合我的 header 并且不会在另一个项目中工作。 无论如何,我所有的 vimrc 都是针对这个项目的。