본문으로 바로가기

vim으로 python 편집 시 py 확장자를 가진 파일의 tab은 무조건 space로 전환된다.


이러한 현상은 .vimrc 파일 혹은 .vim/vimrc 파일에 아래와 같은 설정이 있는 경우 발생할 수 있다.


set expandtab              "탭을 스페이스로 바꾸는 설정

filetype plugin indent on  "파일 타입에 따른 plugin과 indent 설정 on


특히 filetype indent on이 설정된 경우 기본 설치된 python.vim이 vim 기동 시 수행되고 python.vim안에 파이썬 확장자를 위한 설정이 되어 있어 .py 확장자를 가진 파일의 tab은 무조건 space로 전환이 이루어 진다.


확장자에 따른 expandtab이 어떤 파일로 부터 영향을 받는지 알기 위해  verb set expandtab?" 명령을 사용하여 확인할 수 있다.

:verb set expandtab?

expandtab

  Last set from /usr/share/vim/vim81/ftplugin/python.vim line 115


python.vim 파일의 115라인에서 해당 설정을 확인할 수 있다.


113 if !exists("g:python_recommended_style") || g:python_recommended_style != 0

114     " As suggested by PEP8.

115     setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8

116 endif



따라서 "filetype plugin indent on"를 사용하며 python의 tab을 space가 아닌 tab으로 유지하기 위해서는 ./vim/vimrc에 아래 설정을 하여주면 자신만의 설정이 가능하게 된다.


let g:python_recommended_style = 0


python tab style 전체 설정은 다음과 같다.


filetype plugin indent on

let g:python_recommended_style = 0

autocmd FileType py setlocal ts=4 sw=4 sts=4 smartindent noexpandtab

autocmd BufEnter *.\(py\) setlocal noexpandtab


'Programing > vim & neovim' 카테고리의 다른 글

vi/vim/nvim 추천 글 모음  (1) 2018.04.17