Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在vim中缩进c的多行注释_C_Vim - Fatal编程技术网

如何在vim中缩进c的多行注释

如何在vim中缩进c的多行注释,c,vim,C,Vim,在我正在工作的项目中,在我用c代码编写的每个函数之前,我都会正确地缩进多行注释。我使用gvim编辑器。问题是很多时候我在函数中做了一些更改,不得不重新编辑注释,重新编辑注释会使注释不缩进。我必须再次重申这一评论。我发现很难重新编辑多行注释。gvim中是否有任何快捷方式或实用工具,我可以使用它们轻松地自动缩进多行注释 我在网上搜索了这个问题,没有找到任何有用的方法来解决这个问题。在这里,我展示了一个多行注释的示例,我在函数前面编写了多行注释,在重新编辑(注意,它现在是未缩进的)它之后是预期结果 我

在我正在工作的项目中,在我用c代码编写的每个函数之前,我都会正确地缩进多行注释。我使用gvim编辑器。问题是很多时候我在函数中做了一些更改,不得不重新编辑注释,重新编辑注释会使注释不缩进。我必须再次重申这一评论。我发现很难重新编辑多行注释。gvim中是否有任何快捷方式或实用工具,我可以使用它们轻松地自动缩进多行注释

我在网上搜索了这个问题,没有找到任何有用的方法来解决这个问题。在这里,我展示了一个多行注释的示例,我在函数前面编写了多行注释,在重新编辑(注意,它现在是未缩进的)它之后是预期结果

我还有一个问题。您是否在用c编写每个函数之前编写注释。如果是,如果在函数中做了一些更改,如何保持注释的缩进

/*
 * Function: remove_item_from_list
 * --------------------
 *  Removes an item from a list. Here list is a sequence of same type objects. 
 *  pItem is also same type object. This is a generic function in the sense
 *  that it can work for different type of objects. Currently pList will have 
 *  only one copy of pItem w.r.t. the calling places. So whenever the item  
 *  found a break statement is used.
 *
 *  pList : a sequence of objects
 *  pItem : object
 *
 *  returns: modified list
 */
现在,在对函数做了一些更改之后,我重新编辑了注释。现在gvim编辑器中的注释如下所示。我对注释的更改出现在#####块中

/*
 * Function: remove_item_from_list
 * --------------------
 *  Removes an item from a list. Here list is a sequence of same type objects. 
 *  pItem is also same type object. This is a generic function in the sense
 *  that it can work for different type of objects. ##Currently it works for Animal and Bird type objects. If you want this function to work for some there type object then you have add check for that object. Note that this function assumes that pItem can't be NULL.## Currently pList will have 
 *  only one copy of pItem w.r.t. the calling places. So whenever the item  
 *  found a break statement is used.
 *
 *  pList : a sequence of objects
 *  pItem : object
 *
 *  returns: modified list
 */

您可以使用
gq
命令(
:help gq
)。围绕段落运行视觉选择,以设置格式并键入
gq
。根据设置的
textwidth
(如@Michail所述),Vim将正确包装文本,记住它是一条注释


通过这种方式,您可以键入注释、编辑注释、返回注释,而无需考虑太多的格式设置,一旦您对注释的格式感到满意,就可以使用
gq
命令(
:help gq
)。围绕段落运行视觉选择,以设置格式并键入
gq
。根据设置的
textwidth
(如@Michail所述),Vim将正确包装文本,记住它是一条注释


通过这种方式,您可以键入评论、编辑评论、返回评论,而不必考虑太多的格式,只要您满意,就可以进行格式设置。

术语不是“缩进”,缩进是指前导空格。您需要的是文本换行。请参阅
:help textwidth
,了解有关此项的一些信息,并检查
formatoptions
是否包含
c
标志。(当然还有,
:help formatoptions
)这个术语不是“缩进”,缩进是指前导空格。您需要的是文本换行。请参阅
:help textwidth
,了解有关此项的一些信息,并检查
formatoptions
是否包含
c
标志。(当然还有,
:help formatoptions
)。您的建议完美地解决了我的问题,非常感谢。现在我将从痛苦中解脱。
gq
也采取了一项动议,因此
gqip
将重新格式化整个段落。请参见
:h motion.txt
。Great@Ranju,如果您对此感到满意,请不要忘记批准回复:-)您提出的建议完美地解决了我的问题,非常感谢。现在我将从痛苦中解脱。
gq
也采取了一项动议,因此
gqip
将重新格式化整个段落。请参见
:h motion.txt
。Great@Ranju,如果您对此感到满意,请不要忘记批准回复:-)
/*
 * Function: remove_item_from_list
 * --------------------
 *  Removes an item from a list. Here list is a sequence of same type objects. 
 *  pItem is also same type object. This is a generic function in the sense
 *  that it can work for different type of objects. Currently it works for 
 *  Animal and Bird type objects. If you want this function to work for some 
 *  there type object then you have add check for that object. Note that this 
 *  function assumes that pItem can't be NULL.## Currently pList will have 
 *  only one copy of pItem w.r.t. the calling places. So whenever the item  
 *  found a break statement is used.
 *
 *  pList : a sequence of objects
 *  pItem : object
 *
 *  returns: modified list
 */