gpt4 book ai didi

c++ - Vim:将连续的行与空格对齐

转载 作者:行者123 更新时间:2023-11-30 01:59:52 27 4
gpt4 key购买 nike

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

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

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

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

谢谢!

最佳答案

我认为您正在寻找的是 cinoptions(N 选项。尝试 set cinoptions+=(0。根据文档,这看起来像您寻求的一致性。

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

就选项卡而言,您需要使用 :set noexpandtab 禁用 expandtab,并且您需要确保您的制表位、软制表位和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

关于c++ - Vim:将连续的行与空格对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15729023/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com