vim代码格式化自动加空格_Vim:将连续线与空格对齐

I would like to indent everything in vim with tabs, except a particular case. For example I have this c++ code(where is a tab character series and is a space character series):

if(true &&

true)

{

//code here

}

I would like after writing '&&' and press 'o' to jump on the next line and start writing to make vim put a tab and the number of spaces till '(' from the line before.

Is it possible to define this coding style in vim?

Thanks!

解决方案

I think what you're looking for is the (N option for cinoptions. Try set cinoptions+=(0. According to the documentation, this looks like the alignment that you seek.

More information can be found by using help command: :help cinoptions-values or looking at the online version of the help for cinoptions-values.

As far as tabs go, you'll want to disable expandtab with :set noexpandtab, and you'll want to make sure your tabstops, soft tabstops, and shiftwidth are all set accordingly. As an example, the Linux source code uses a style like you mention above, and I have this in my 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 .

" 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值