我想将tab转换为gVim中的空格。 我_vimrc
下行添加到个人_vimrc
: vim
set tabstop=2
它能够在两个空格处中止,但它仍然看起来像是插入了一个tab键(我尝试使用h键来计算空格)。 spa
我不知道如何将gVim转换为空格? rest
本文有一个很好的vimrc脚本,用于处理选项卡+空格,并在它们之间进行转换。 code
提供如下命令: ip
Space2Tab仅在缩进中将空格转换为制表符。 get
Tab2Space仅将选项卡转换为空格。 string
RetabIndent执行Space2Tab(若是设置了'expandtab')或Tab2Space(不然)。 it
每一个命令都接受一个参数,该参数指定选项卡列中的空格数。 默认状况下,使用'tabstop'设置。 io
资料来源: http : //vim.wikia.com/wiki/Super_retab#Script function
" 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(<line1>,<line2>,0,<q-args>) command! -nargs=? -range=% Tab2Space call IndentConvert(<line1>,<line2>,1,<q-args>) command! -nargs=? -range=% RetabIndent call IndentConvert(<line1>,<line2>,&et,<q-args>)
当我第一次寻找解决方案时,这对个人帮助有所帮助。
首先在文件中搜索选项卡:/ ^ I:设置expandtab:retab
将工做。
gg=G
将从新整理整个文件,并删除大部分(若是不是所有)我从同事那里获得的文件。
将如下行添加到.vimrc中
set expandtab set tabstop=4 set shiftwidth=4 map <F2> :retab <CR> :wq! <CR>
在vim中打开文件并按F2键。选项卡将转换为4个空格,文件将自动保存。
这对我有用:
你能够看到首先这样作的标签:
:set list
而后能够替换制表符而后执行如下操做:
:set expandtab
而后
:retab
如今全部选项卡都已替换为空格,而后您能够返回到正常查看,以下所示:
:set nolist