我写的函数如下,
static int
foo_bar(const char *string)
{
}
当我使用 Vim 缩进时,它会执行类似的操作,
static int
foo_bar(const char *string)
{
}
它在
static int
之前添加了一些额外的空格。我怎样才能解决这个问题?
我最近才发现这个:
http://thisblog.runsfreesoftware.com/?q=2009/04/20/indent-gnu-style-vim
将其添加到您的 vimrc 中并通过键入
==
重新缩进,或者如果您想要缩进 5 行,请键入 5==
我将以下内容放入
~/.vim/ftplugin/cpp.vim
(路径因操作系统而异,请参阅:help add-global-plugins
)。
setl cindent cinoptions=j1,f0,^-2,{2,>4,:4,n-2,(0,t0 sw=2 ts=8 noet
这非常接近 gcc 源代码中使用的实际缩进方法。 (但是
noet
很奇怪。每 4 个缩进级别,您就从使用 8 个空格切换为使用硬制表符。)
int
main()
{
if (condition)
{
f();
}
if (condition)
f();
}