JAVA中for循环缩制表位_用vim中的空格替换制表符

我想将tab转换为gVim中的空格。 我_vimrc下行添加到我的_vimrc :

set tabstop=2

它可以在两个空格处停止,但它仍然看起来像是插入了一个tab键(我尝试使用h键来计算空格)。

我不知道如何将gVim转换为空格?

#1楼

本文有一个很好的vimrc脚本,用于处理选项卡+空格,并在它们之间进行转换。

提供以下命令:

Space2Tab仅在缩进中将空格转换为制表符。

Tab2Space仅将选项卡转换为空格。

RetabIndent执行Space2Tab(如果设置了'expandtab')或Tab2Space(否则)。

每个命令都接受一个参数,该参数指定选项卡列中的空格数。 默认情况下,使用'tabstop'设置。

" Return indent (all whitespace at start of a line), converted from

" tabs to spaces if what = 1, or from spaces to tabs otherwise.

" When converting to tabs, result has no redundant spaces.

function! Indenting(indent, what, cols)

let spccol = repeat(' ', a:cols)

let result = substitute(a:indent, spccol, '\t', 'g')

let result = substitute(result, ' \+\ze\t', '', 'g')

if a:what == 1

let result = substitute(result, '\t', spccol, 'g')

endif

return result

endfunction

" Convert whitespace used for indenting (before first non-whitespace).

" what = 0 (convert spaces to tabs), or 1 (convert tabs to spaces).

" cols = string with number of columns per tab, or empty to use 'tabstop'.

" The cursor position is restored, but the cursor will be in a different

" column when the number of characters in the indent of the line is changed.

function! IndentConvert(line1, line2, what, cols)

let savepos = getpos('.')

let cols = empty(a:cols) ? &tabstop : a:cols

execute a:line1 . ',' . a:line2 . 's/^\s\+/\=Indenting(submatch(0), a:what, cols)/e'

call histdel('search', -1)

call setpos('.', savepos)

endfunction

command! -nargs=? -range=% Space2Tab call IndentConvert(,,0,)

command! -nargs=? -range=% Tab2Space call IndentConvert(,,1,)

command! -nargs=? -range=% RetabIndent call IndentConvert(,,&et,)

当我第一次寻找解决方案时,这对我的帮助有所帮助。

#2楼

首先在文件中搜索选项卡:/ ^ I:设置expandtab:retab

将工作。

#3楼

gg=G将重新整理整个文件,并删除大部分(如果不是全部)我从同事那里得到的文件。

#4楼

将以下行添加到.vimrc中

set expandtab

set tabstop=4

set shiftwidth=4

map :retab :wq!

在vim中打开文件并按F2键。选项卡将转换为4个空格,文件将自动保存。

#5楼

这对我有用:

你可以看到首先这样做的标签:

:set list

然后可以替换制表符然后执行以下操作:

:set expandtab

然后

:retab

现在所有选项卡都已替换为空格,然后您可以返回到正常查看,如下所示:

:set nolist

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值