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

时间:2015-04-17 12:19:07

标签: vim comments licensing auto-indent

我的编码样式有一个很好的cindent配置,但如果我重新加载vim中的所有文件,我的文件的许可标题将无法正确重新标记。

许可证标题:

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

  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

希望结果:许可证标题缩进没有变化

看到结果:

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

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.

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

1 个答案:

答案 0 :(得分:0)

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

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

它将F12键映射到:

  • reindent all file
  • 缩进一个缩进的第3到12行
  • 缩进一个缩进的第10到12行

因此它对我的标题非常具体,并且不适用于另一个项目。 无论如何,我所有的vimrc都是专门用于这个项目的。