将连续线与空格对齐

将连续线与空格对齐

本文介绍了Vim:将连续线与空格对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

 < tab> if(true&& 
< tab>< ; s> true)
< tab> {
< tab>< tab> //这里的代码
< tab>}

我想在写入&&'后按下'o'跳到下一行,然后开始写入,使vim放入标签



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



谢谢!

解决方案

我认为你要找的是 / code>选项 cinoptions 。尝试 set cinoptions + =(0 。根据文档,



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

对于标签页,您需要使用禁用 expandtab :set noexpandtab ,并且您需要确保相应地设置了标签页,软标签页和shiftwidth。例如,Linux源代码使用像上面提到的样式,我在我的vimrc中有这样的样式:

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

不要将制表符展开到空格。
setlocal noexpandtab

启用自动C程序缩进。
setlocal cindent

不要过多的函数返回类型
setlocal cinoptions + = t0

没有额外的缩进用于case标签。
setlocal cinoptions + =:0

public,protected,private标签没有额外的缩进
setlocal cinoptions + = g0

排列函数args。
setlocal cinoptions + =(0

设置格式选项:
c - 自动换行注释到文本宽度
r - 输入>
o - 自动在'o'或'O'后插入注释引号
q - 允许使用'gq'格式化注释
l长行不
n - 识别编号列表
t - 使用textwidth命令自动换行
setlocal formatoptions = croqlnt


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

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

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 <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

这篇关于Vim:将连续线与空格对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:49