[Python & VI] Vi folding 을 class 나 def 에 따라 접도록 설정하기
기본적으로 python을 vi 를 통해 스크립트를 작성할때
indent로 folding 을 한다.
기본 설정 in .vimrc:
" folding settings
autocmd FileType python set foldmethod=indent " use indent for folding (python)
autocmd FileType python set foldnestmax=1 " maximal level of folding
autocmd FileType python set expandtab " insert spaces instead of <TAB>
하지만 간혹 class 내에 서브 함수들을 folding 하는 것에는 한계가 있다.
foldnestmax=2 로 설정을 해도 원하는 데로 깔끔하게 folding 이 되지는 않는다.
한 방법은,
folding 방법을 express 로 설정을 하고
syntax 에 express 를 추가하는 방법이다.
복잡해 보이나 이미 express script가 인터넷에 있어
쉽게 구현할 수 있다.
우선 python.vim 을 아래 링크에서 다운받아 (아래 링크)
혹은
https://www.vim.org/scripts/script.php?script_id=781
~/.vim/syntax/
폴더안에 복사를 한다.
그리고 .vimrc 를 다음과 같이 수정하면 끝~!
" folding settings
autocmd FileType python set foldmethod=expr " use syntax for folding (python)
autocmd FileType python set foldnestmax=1 " maximal level of folding
autocmd FileType python set expandtab " insert spaces instead of <TAB>