用于C ++模板的Vim缩进? [英] Vim indentation for c++ templates?

查看:83
本文介绍了用于C ++模板的Vim缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人拥有或知道可以很好地缩进c ++模板的vim插件/宏/函数?

Does anyone have or know about vim plugin/macro/function that indents nicely c++ templates?

当我在vim .hpp/.h文件中突出显示模板定义并用'='缩进时,我得到这样的东西:

When I highlight template definition in vim .hpp/.h file and indent it with '=' I get something like this:

>     template <
>         class TFilter,
>               class TParser,
>               class TConsumer,
>               class TDataProcessor,
>               class TDataFeed,
>               class TSymbolMap
>                   >
>                   struct DataFeedTraits
>                   {
>                       typedef TFilter             Filter;
>                       typedef TParser<TSymbolMap> Parser;
>                       typedef TConsumer<Parser>   Consumer;
>                       typedef TDataProcessor<Filter,Consumer>  DataProcessor;
>                       typedef TDataFeed<Filter,DataProcessor,Parser,Ccnsumer> DataFeed;
>                   };

我认为该问题使struct/class声明与右括号'>'对齐. 我想以这样的结果结束,或者类似,就格式化而言,确切的格式并不重要:

I think the cindent aligns the struct/class declaration with the closing bracket '>'. I would like to end up with something like this, or similar, exact formatting does not matter, as far as it is formatted:

template <
    class TFilter,
    class TParser,
    class TConsumer,
    class TDataProcessor,
    class TDataFeed,
    class TSymbolMap
    >
struct DataFeedTraits
{
    typedef TFilter             Filter;
    typedef TParser<TSymbolMap> Parser;
    typedef TConsumer<Parser>   Consumer;
    typedef TDataProcessor<Filter,Consumer> DataProcessor;
    typedef TDataFeed<Filter,DataProcessor,Parser,Ccnsumer> DataFeed;
};

推荐答案

您可以使用表达式(即编写vim脚本函数).该函数应接受字符串(即行)并返回要缩进的空格数.这使您可以灵活地为该模板条件返回缩进级别,或回退到 smartindent cindent .

You can use the identexpr option to specify indent by evaluating an expression (i.e. writing a vim script function). This function should accept a string -- the line -- and return the number of spaces to indent. This gives you the flexibility to return an indent level for this template condition, or fall-back to autoindent, smartindent or cindent in normal, C-like situations.

此处创建了一个示例来处理Qt的信号和插槽扩展. 它证明了回退到cindent函数.

Here is an example that was created to handle the signals and slots extension of Qt. It demonstrates fall-back to the cindent function.

这篇关于用于C ++模板的Vim缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆