리눅스 들여쓰기 스타일 지정(Linux vi tab intend)
최근에 Python을 vi로 작성해니 들여쓰기의 기본값인 '8'을 '4'로 바꿔야겠다는 생각이 들었다.
그래서 찾아본 vi 환경설정 방법이다.
(*실제 Python.org 에서 권고하는 들여쓰기가 '4'이다.)
○ " .vimrc " 파일을 생성하여 다음을 입력한다.
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
○ 저장 후 vi/vim을 재시작한다.
간단하다!!!
각 속성이 의미하는 바는 아래와 같다.
----------------------------
http://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces
To define this on a permanent basis for the current user, create (or edit) the .vimrc
file:
$ vim ~/.vimrc
Then, paste the configuration below into the file. Once vim is restarted, the tab settings will apply.
set tabstop=4 " The width of a TAB is set to 4.
" Still it is a \t. It is just that
" Vim will interpret it to be having
" a width of 4.
set shiftwidth=4 " Indents will have a width of 4
set softtabstop=4 " Sets the number of columns for a TAB
set expandtab " Expand TABs to spaces
To make the above settings permanent add these lines to your vimrc.
In case you need to make adjustments, or would simply like to understand what these options all mean, here's a breakdown of what each option means:
tabstop
The width of a hard tabstop measured in "spaces" -- effectively the (maximum) width of an actual tab character.
shiftwidth
The size of an "indent". It's also measured in spaces, so if your code base indents with tab characters then you want shiftwidth
to equal the number of tab characters times tabstop
. This is also used by things like the =
, >
and <
commands.
softtabstop
Setting this to a non-zero value other than tabstop
will make the tab key (in insert mode) insert a combination of spaces (and possibly tabs) to simulate tab stops at this width.
expandtab
Enabling this will make the tab key (in insert mode) insert spaces instead of tab characters. This also affects the behavior of the retab
command.
smarttab
Enabling this will make the tab key (in insert mode) insert spaces or tabs to go to the next indent of the next tabstop when the cursor is at the beginning of a line (i.e. the only preceding characters are whitespace).