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为例。
翻译自: https://www.systutorials.com/how-to-make-vim-indent-c11-lambdas-correctly/
vim c语言格式缩进