vim c语言格式缩进_如何使Vim正确缩进C ++ 11 lambda?

vim c语言格式缩进

Vim seems not indent C++11 lambas very well. How to make Vim indent C++11 lambdas correctly?

Vim似乎不太适合缩进C ++ 11 lambas。 如何使Vim正确缩进C ++ 11 lambda?

For this following program, Vim indents it as

对于以下程序,Vim将其缩进为

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main ()
{
  std::vector<std::string> strs({"one", "two"});
  std::vector<std::string> newstrs;

  std::transform(strs.begin(), strs.end(), std::back_inserter(newstrs), [](const std::string& s) -> std::string {
      if (s == "one") {
      return "1";
      } else if (s == "two") {
      return "2";
      } else {
      return s;
      }
      });

  return 0;
}

The C++ lambda is indented incorrectly by Vim. The lambda function should be indented like

Vim错误地缩进了C ++ lambda 。 lambda函数应该像

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main ()
{
  std::vector<std::string> strs({"one", "two"});
  std::vector<std::string> newstrs;

  std::transform(strs.begin(), strs.end(), std::back_inserter(newstrs), [](const std::string& s) -> std::string {
    if (s == "one") {
      return "1";
    } else if (s == "two") {
      return "2";
    } else {
      return s;
    }
  });

  return 0;
}

You may add these lines to your vimrc for C/C++ to indent lambdas correctly as you listed above

您可以将这些行添加到C / C ++的vimrc中,以正确缩进lambda,如上所列

setlocal cindent
" handle lambda correctly
setlocal cino=j1,(0,ws,Ws

The key is setting cino (cinoption) to be j1,(0,ws,Ws. jN is new in Vim 7.4 for “indent Java anonymous classes correctly” which improves C/C++ lambda indenting too.

关键是将cino (cinoption)设置为j1,(0,ws,Ws jN是Vim 7.4中的新功能,用于“正确缩进Java匿名类”,这也改善了C / C ++ lambda缩进。

Check my vimrc as an example.

我的vimrc为例。

Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自: https://www.systutorials.com/how-to-make-vim-indent-c11-lambdas-correctly/

vim c语言格式缩进

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值