본문 바로가기

Linux

Vim

1. VIMRC

나의 .vimrc 세팅

더보기
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vundle
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()

Plugin 'VundleVim/Vundle.vim'   " Vundle 관리를 위해 필요한 부분
Plugin 'scrooloose/nerdtree'    " 파일트리 창을 보여 줄 수 있는 플러그인
Plugin 'scrooloose/nerdcommenter'  " 멀티라인 주석, 부분 주석 등에 대한 처리를 할 수 있는 플러그인
Plugin 'vim-airline/vim-airline'  " 하단 상태바에 더 많은 정보를 출력
Plugin 'tpope/vim-fugitive'      " vim에서 git의 기능을 사용할 수 있게 해준다
" Plugin 'scrooloose/syntastic'  " vi로 편집 중 실시간으로 문법 체크 기능을 제공 해 주는 플러그인
Plugin 'ctrlpvim/ctrlp.vim'      " 파일 찾기 기능(VS AssistX의 파일 네비게이터와 동일한 역할)
Plugin 'tmhedberg/SimpylFold'

" Color scheme -----------------------------
Plugin 'altercation/vim-colors-solarized'
Plugin 'tomasr/molokai'
Plugin 'nanotech/jellybeans.vim'
" ------------------------------------------
"
Plugin 'valloric/youcompleteme' " 코드 자동 완성 기능을 위한 플러그인
Plugin 'taglist.vim'            " 디파인 매크로, 함수, 변수 등의 리스트를 정렬하여 보여 줄 수 있는 플러그인
Plugin 'DoxygenToolkit.vim'     " Doxygen 스타일의 주석을 자동으로 삽입 가능한 기능을 가진 플러그인
Plugin 'davidhalter/jedi-vim'   " python에 대한 문법 preview 기능(?)
Plugin 'brookhong/cscope.vim'

call vundle#end()



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
" VIM에서 기억할 히스토리 라인수
set history=1000

" Set to auto read when a file is changed from the outside
" 현재 사용하고 있는 파일이 외부에서 수정된 경우 자동으로 읽기
set autoread

" Set to auto write on opening an other file.
" 다른 파일을 읽게 되는 경우 현재 파일을 자동으로 저장하기
" 현재 파일을 저장하지 않으면 ":e" 등으로 다른 파일을 열 수 없음.
set autowrite

" Use mouse or not
" 마우스로 클릭한 위치에 커서 놓기 " 마우스로 드래그한 영역은 비쥬얼 모드로 복사준비하기 " 단 마우스를 사용하면, 마우스 오른 버튼을 눌러 나오는 복사를 선택할 수 없음. " 마우스를 사용하지 않으려면, ":set mouse-=a"를 치기
set mouse=a

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Always show current position
" 오른편 하단에 현재 위치의 (행, 렬)을 표시
set ruler

" Highlight search results
" 검색결과에 하이라이트 표시하기
set hlsearch

" Makes search act like search in modern browsers
" 한글자 입력할때마다 매치되는 부분 표시하기
set incsearch

" Show matching brackets when text indicator is over them
" 현재 커서가 놓여진 괄호의 짝을 표시하기
set showmatch

" line number
" 라인넘버 표시하기
set number

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" syntax highlight
" 언어 syntax에 하이라이트표시
syntax on

" color scheme
" 컬러스킴
colorscheme jellybeans " 컬러 스킴 사용
set background=dark

" Set utf8 as standard encoding
" utf8을 표준 인코딩으로 사용하기
set encoding=utf8

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" auto indent's tab size
" 자동탭 사이즈를 4칸으로 하기
set shiftwidth=4

" 1 tab == 4 spaces
" 탭을 4칸으로 하기
set tabstop=4

" c style auto indent
" c언어 스타일로 indentation하기
set cindent

" #if has to be first on the line
" #if 문을 라인의 시작에 배치하기
set smartindent





"=====================================================
""" NERDTree settings
"=====================================================
let NERDTreeShowBookmarks=1
let NERDTreeChDirMode=2     "setting root dir in NT also sets VIM's cd
let NERDTreeQuitOnOpen=0 "the Nerdtree window will be close after a file is opend.
let NERDTreeShowHidden=1
let NERDTreeShowHidden = 1
let g:NERDTreeWinPos = "right"




"=====================================================
""" Simpley Fold settings
"=====================================================
" SimpleyFold plugin for python fold. Display docstirng when folded
let g:SimpylFold_docstring_preview = 1
" Enable folding with the spacebar
nnoremap <space> za



"=====================================================
""" ctrlp settings
"=====================================================
lp_custom_ignore = {
\ 'dir': '\.git$\|public$\|log$\|tmp$\|vendor$',
\ 'file': '\v\.(exe|so|dll)$'
\ }rl+J,K,L,H






"-------------------------------------------------------
" key mappings
nmap <F3> <ESC>:wa!<CR>
nmap <F4> <ESC>:wqa!<CR>

nmap <F7> <ESC>:Tlist<CR>
nmap <F8> <ESC>:NERDTreeToggle<CR>
nmap <leader><F8> <ESC>:NERDTreeFind<CR>

if has("autocmd")

    " 자동완성
    " autocmd FileType * inoremap { {}<LEFT>
    " autocmd FileType * inoremap [ []<LEFT>
    " autocmd FileType * inoremap ( ()<LEFT>
    " autocmd FileType * inoremap " ""<LEFT>
    " autocmd FileType * inoremap ' ''<LEFT>

    " Python 설정
    autocmd BufNewFile,BufRead *.py setfiletype python
    autocmd FileType python nmap <F5> <ESC>:wa!<CR>:!python3 %<CR>

    " C++ 설정
    autocmd BufNewFile,BufRead *.h,*.hpp,*.cc,*.c,*.cpp setfiletype cpp
    autocmd FileType cpp nmap <F5> <ESC>:wa!<CR>:!make<CR>:cw<CR>
    autocmd FileType cpp nmap <F6> <ESC>:cn<CR>
endif




nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

2. Vundle 플러그인 설치 및 설정

Vundle 이란 vim의 다양한 플러그인들을 설치 하기 쉽게 관리해주는 플러그인 매니저 이다.

가장 먼저 Vundle 플러그인을 설치해야 하는데, github에서 저장소를 clone 하는 형식으로 해당 플러그인을 설치할 수 있다.

더보기
$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

이제 vi의 커맨드 라인 모드 상에서 간단한 명령어를 통해 플러그인들을 설치 및 삭제 또는 조회 해 볼 수 있다.

  • PluginInstall: call vundle#begin()과 call vundle#end() 사이에 기술한 플러그인들을 설치 해 준다.
  • PluginList: 현재 .vimrc 파일에 기술 되어 있는 플러그인들을 볼 수 있다.
  • PluginClean: 설치한 플러그인을 지울 때 사용하는 명령어로 지우고 싶은 플러그인을 .vimrc에서 지우고 저장한 뒤 해당 명령어를 수행하도록 한다.