문제
탭을 GVIM의 공간으로 변환하고 싶습니다. 다음 줄을 추가했습니다 _vimrc
:
set tabstop=2
두 개의 공간에서 멈추기 위해 작동하지만 여전히 하나의 탭 키가 삽입 된 것처럼 보입니다 (H 키를 사용하여 나중에 공간을 계산하려고했습니다).
GVIM을 공백으로 변환하기 위해 어떻게 해야하는지 잘 모르겠습니다.
해결책
IIRC, 같은 것 :
set tabstop=2 shiftwidth=2 expandtab
트릭을해야합니다. 이미 탭이있는 경우 멋진 글로벌 Re와 함께 이중 공간으로 교체하십시오.
다른 팁
다른 답변에 따라 ExpandTab을 확장 한 후에는 새로운 설정에 따라 기존 파일을 변환하는 매우 편리한 방법은 다음과 같습니다.
:retab
현재 버퍼에서 작동합니다.
노력하다
set expandtab
소프트 탭의 경우.
기존 탭을 수정하려면 :
:%s/\t/ /g
탭 탑을 이미 2 개의 공간으로 설정 한 이후 두 공간을 사용했습니다.
이것은 나를 위해 효과가있었습니다.
먼저 다음을 수행하는 탭을 볼 수 있습니다.
:set list
그런 다음 탭을 교체 할 수 있도록 다음을 수행하십시오.
:set expandtab
그 다음에
:retab
이제 모든 탭이 공백으로 교체되었으며 다음과 같이 정상적인보기로 돌아갈 수 있습니다.
:set nolist
gg=G
동료들로부터 파일에 들어간 모든 탭이 아닌 경우 전체 파일을 다시 표시하고 대부분의 제거를 제거합니다.
.vimrc에 다음 줄을 추가하십시오
set expandtab
set tabstop=4
set shiftwidth=4
map <F2> :retab <CR> :wq! <CR>
VIM에서 파일을 열고 F2를 누르십시오. 탭은 4 개의 공간으로 변환되며 파일은 자동으로 저장됩니다.
당신이 당신을 지키고 싶다면 \t
8 공백과 같으면 설정을 고려하십시오.
set softtabstop=2 tabstop=8 shiftwidth=2
이것은 당신에게 두 개의 공간을 줄 것입니다 <TAB>
누르지 만 실제 \t
코드에서 여전히 8 자로 간주됩니다.
파일에서 먼저 탭 검색 : /^i : set expandtab : retab
작동합니다.
expand
탭을 공백으로 변환하는 Unix 유틸리티입니다. 원하지 않는다면 set
VIM에서 모든 것은 vim의 쉘 명령을 사용할 수 있습니다.
:!% expand -t8
이것은 나를 위해 작동하게했습니다.
:set tabstop=2 shiftwidth=2 expandtab | retab
이 기사에는 탭+공간을 처리하고 그 사이를 변환하기위한 우수한 VIMRC 스크립트가 있습니다.
이 명령은 다음과 같습니다.
Space2TAB 공백을 탭으로 변환하고 들여 쓰기에서만 변환합니다.
tab2space 탭을 공백으로, 들여 쓰기에서만 변환합니다.
망상 space2tab ( 'expandtab'이 설정된 경우) 또는 tab2space (그렇지 않으면) 실행하십시오.
각 명령은 탭 열의 공간 수를 지정하는 인수를 수락합니다. 기본적으로 'Tabstop'설정이 사용됩니다.
원천: http://vim.wikia.com/wiki/super_retab#script
" 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>)
이것은 내가 처음 솔루션을 검색했을 때 여기서 답보다 조금 더 도움이되었습니다.