如何让 vim 很好地对齐三元 ?: 运算符?
我喜欢使用三元 ?: 运算符编写代码,如下所示:
std::string result = input.empty() ? createNewItem()
: processInput( input );
如何配置 vim,以便在输入 createNewItem()
后按 Return 缩进下一行,以便光标位于同一列中作为最后一个 ?
,这样我就可以继续输入 : processInput( input );
?
我尝试查看 cinoptions-values 设置,但没有看到任何相关内容。
I like to write code using the ternary ?: operator like this:
std::string result = input.empty() ? createNewItem()
: processInput( input );
How can I configure vim so that when pressing Return after having typed createNewItem()
indents the next line so that the cursor is in the same column as the last ?
so that I can just continue typing : processInput( input );
?
I tried looking at the cinoptions-values
setting but I didn't see anything relevant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您至少可以通过添加括号来部分实现这一点:
只有当您将表达式分成三行时,这才有效:I
通常会这样做,但我不得不承认你的格式看起来非常好并且
在表达式很短的情况下可读。
过去,我发现 vim 邮件列表对于这种类型非常有帮助
的问题。以前是谷歌群组的,你可以参考一下
就好像那里有一个团体;我不确定当前状态如何
(因为我无法在工作中访问 Google 群组)。
You can achieve this at least partially be adding parentheses:
This only works if you break the expression up into three lines: I
usually do, but I'll have to admit that your format looks very nice and
readable, in cases where the expressions are short.
In the past, I've found the vim mailing list very helpful for this sort
of question. It used to be gated to Google groups, so you could consult
it as if it were a group there; I'm not sure what the current status is
(since I can't access Google groups from work).
受到 大致相似的启发问题 我运用了我的 vimscript-fu 并创建了一个小脚本来完成这项工作:
我将此文件保存为
vimfiles/indent/after/cpp.vim
并将filetype indent on
添加到我的.vimrc
以切换缩进插件的加载。看起来效果已经足够好了!Inspired by a roughly similiar question I exercised my vimscript-fu and created a little script to do this job:
I saved this file as
vimfiles/indent/after/cpp.vim
and addedfiletype indent on
to my.vimrc
to toggle loading of indentation plugins. It seems to work good enough!