2015년 4월 14일 화요일

Python 을 위한 vim 설정

1. Python syntax coloring
Python Syntax Color를 지정하기 위해서 http://www.vim.org/scripts/script.php?script_id=790 사이트에서 python.vim 파일을 다운로드 받아 ~/.vim/syntax/ 폴더에 복사합니다. ~/.vimrc 파일에는 아래와 같이 추가해줍니다.
syntax on
filetype plugin indent on 

2. Tab 설정
Tab 설정은 ~/.vim/ftplugin/python.vim 파일에 아래와 같이 추가해줍니다. (파일이 없다면 새로 생성해주세요)
set tabstop=4
set softtabstop=4
set shiftwidth=4
set textwidth=100
set expandtab
set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
set nocindent
let python_version_2 = 1 " python 2 문법을 따른다고 옵션을 설정합니다.
let python_highlight_all = 1 " 모든 강조(색상) 기능을 켭니다.
3. exuberant-ctags 설치
$ sudo apt-get install exuberant-ctags

설치 후 ctags --help 하면 도움말 등이 나와야 함

4. tagging file 만드는 법
원하는 디렉토리에서 ctags -R 하면 됨
그러나 이렇게 하면 taggind 에 python 코드의 변수, import 된 패키지 이름 정보도 함께 포함됨
tagging 정보에는 클래스와 함수만 포함되는 것이 코드 브라우징에 좋음.
이를 위해 ~/.ctags 파일에 아래와 같은 내용을 추가

--python-kinds=-iv
--exclude=build
--exclude=dist

위 내용에서 -iv 옵션이 import 와 변수를 tagging 대상에서 제외시키는 역할을 함
--exclude 옵션은 tagging 시 제외할 폴더를 지정할 수 있음

5. Auto Completion 기능
Jedi 플러그인을 설치하면 vim에서 Python 코드 자동완성 기능을 사용할 수 있습니다. 설치 방법은 아래와 같습니다.

5.1. Vundle 플러그인을 설치합니다.
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

5. 2. ~/.vimrc 파일을 다음과 같이 수정합니다.
syntax on
set nocompatible              
filetype off                  

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" " required! 
Bundle 'gmarik/vundle'
" " My bundles here:
Bundle 'davidhalter/jedi-vim'

filetype plugin indent on     " required!

5. 3. vim을 실행 후 :BundleInstall을 실행합니다.

6. File Browser 설치
The NERD Tree 를 설치해야 하는데 아래 링크에 가면
https://github.com/scrooloose/nerdtree
pathogen.vim 을 설치하라고 권장하고 있다. 따라서 이렇게 한다.
6.1 pathogen.vim 설치
mkdir -p ~/.vim/autoload ~/.vim/bundle && \ curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
6.2 Add this to your vimrc:
execute pathogen#infect()
6.3 install nerd tree
cd ~/.vim/bundle
git clone https://github.com/scrooloose/nerdtree.git
Then reload vim, run :Helptags, and check out :help NERD_tree.txt.

6.4 단축키 설정
map <F3> :NERDTreeToggle<CR> or
map <C-n> :NERDTreeToggle<CR>
7. taglist 설치
7.1 설치
아래 사이트에 가서 최신 taglis_xx.zip 다운로드
http://vim.sourceforge.net/scripts/script.php?script_id=273
풀면 아래 두 파일이 있어야 함 plugin/taglist.vim - main taglist plugin file doc/taglist.txt - documentation (help) file
아래 위치에 위 파일들을 복사
$HOME/.vim or the $HOME/vimfiles or the $VIM/vimfiles

Change to the $HOME/.vim/doc or $HOME/vimfiles/doc or $VIM/vimfiles/doc directory, start Vim and run the ":helptags ." command to process the taglist help file. Without this step, you cannot jump to the taglist help topics.
If the exuberant ctags utility is not present in your PATH, then set the Tlist_Ctags_Cmd variable to point to the location of the exuberant ctags utility (not to the directory) in the .vimrc file.
If you are running a terminal/console version of Vim and the terminal doesn't support changing the window width then set the 'Tlist_Inc_Winwidth' variable to 0 in the .vimrc file.
Restart Vim.
You can now use the ":TlistToggle" command (previously ":Tlist") to open/close the taglist window. You can use the ":help taglist" command to get more information about using the taglist plugin.

7.2 vimrc 수정
아래 내용 참고해서 수정
let Tlist_Ctags_Cmd="/usr/bin/ctags"
let Tlist_inc_Winwidth=0
let Tlist_Exit_OnlyWindow=1
let Tlist_Display_Tag_Scope = 1
let Tlist_Display_Prototype = 1
let Tlist_Use_Right_Window = 1
let Tlist_Sort_Type = "name"
let Tlist_WinWidth = 60

map <F4> :Tlist<cr>
nnoremap <F11> <C-t>
nnoremap <F12> <C-]>

7.3 taglist 사용법
ctrl + ] 로 이동하고
ctrl + t 로 이전 위치로 복귀하나, 위와 같이 vimrc 에 단축키 지정해서 사용함


댓글 없음:

댓글 쓰기