1

我想用制表符缩进vim中的所有内容,除了特殊情况。例如,我有这个 c++ 代码(其中<tab>是制表符系列,<s>是空格字符系列):

<tab>if(true &&
<tab><s>true)
<tab>{
<tab><tab>//code here
<tab>}

我想在写完 '&&' 并按 'o' 跳到下一行并开始编写以使 vim 放置一个制表符和空格数,直到 '(' 从前一行开始。

是否可以在 vim 中定义这种编码风格?

谢谢!

4

2 回答 2

5

我认为您正在寻找的(Ncinoptions. 试试set cinoptions+=(0。根据文档,这看起来像您寻求的对齐方式。

可以使用 help 命令找到更多信息:或查看cinoptions-values 帮助:help cinoptions-values的在线版本。

就制表符而言,您需要使用 禁用expandtab:set noexpandtab并且您需要确保您的制表位、软制表位和 shiftwidth 都已相应设置。例如,Linux 源代码使用您上面提到的样式,我的 vimrc 中有这个:

setlocal ts=8 sts=8 sw=8 tw=80

" Don't expand tabs to spaces.
setlocal noexpandtab

" Enable automatic C program indenting.
setlocal cindent

" Don't outdent function return types.
setlocal cinoptions+=t0

" No extra indentation for case labels.
setlocal cinoptions+=:0

" No extra indentation for "public", "protected", "private" labels.
setlocal cinoptions+=g0

" Line up function args.
setlocal cinoptions+=(0

" Setup formatoptions:
"   c - auto-wrap comments to textwidth.
"   r - automatically insert comment leader when pressing <Enter>.
"   o - automatically insert comment leader after 'o' or 'O'.
"   q - allow formatting of comments with 'gq'.
"   l - long lines are not broken in insert mode.
"   n - recognize numbered lists.
"   t - autowrap using textwidth,
setlocal formatoptions=croqlnt
于 2013-03-31T12:35:00.283 回答
0

在您的 .vimrc 中添加以下内容

set tabstop=2
set expandtab
set shiftwidth=2
set smarttab
set linebreak
set smartindent
set cindent
set autoindent

这就是在 vim 中推出令人敬畏的一切所需的一切。:)

于 2013-03-31T11:50:09.997 回答