티스토리 뷰

linux

.vimrc 설정

Shin_lab 2016. 2. 23. 22:31

.vimrc 파일 설정

// 제가 쓰는 .vimrc에서 설정해주는 부분은 다음과 같다.

1. Vundle => Vim Plugin Manager

- ~/.vim/bundle/ 폴더에 git을 통해 소스를 가져옴

- Setup Vundle

sudo apt-get install git

git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

- Install Plugins

:PluginInstall => vim에서 실행

vim +PluginInstall +qall => 터미널에서 실행

- Search Plugins

:PluginSearch SrcExpl

2. vim setting

3. ctags + cscope

sudo apt-get install ctags cscope

4. Tag List + Source Explorer + NerdTree + Auto Compl Pop

"Vundle Configuration

"------------------------------------------------------------------------------------------------------------
set nocompatible            " be iMproved, required
filetype off                    " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
    " alternatively, pass a path where Vundle should install plugins
    "call vundle#begin('~/some/path/here')

    " let Vundle manage Vundle, required
    Plugin 'gmarik/Vundle.vim'

    " User Plugins here :
    Plugin 'The-NERD-tree'
    Plugin 'The-NERD-Commenter'
"    Plugin 'Source-Explorer-srcexpl.vim'
    Plugin 'SrcExpl'
    Plugin 'cscope.vim'
    Plugin 'taglist-plus'
"    Plugin 'trinity.vim'
    Plugin 'Trinity'
    Plugin 'AutoComplPop'

    " The following are examples of different formats supported.
    " Keep Plugin commands between vundle#begin/end.
    " plugin on GitHub repo
    Plugin 'tpope/vim-fugitive'
    " plugin from http://vim-scripts.org/vim/scripts.html
    Plugin 'L9'
    " Git plugin not hosted on GitHub
    Plugin 'git://git.wincent.com/command-t.git'
    " git repos on your local machine (i.e. when working on your own plugin)
    "Plugin 'file:///home/gmarik/path/to/plugin'
    " The sparkup vim script is in a subdirectory of this repo called vim.
    " Pass the path to set the runtimepath properly.
    Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
    " Avoid a name conflict with L9
    "Plugin 'user/L9', {'name': 'newL9'}

    " Brief help
    " :BundleList          - list configured bundles
    " :BundleInstall(!)    - install(update) bundles
    " :BundleSearch(!) foo - search(or refresh cache first) for foo
    " :BundleClean(!)      - confirm(or auto-approve) removal of unused bundles
    "
    " see :h vundle for more details or wiki for FAQ
    " NOTE: comments after Bundle command are not allowed..
call vundle#end()            " required
filetype plugin indent on    " required

"vim setting
"------------------------------------------------------------------------------------------------------------
set vb "visual bell
set nu
set nuw=5
set cin
set background=dark
set nowrap
set autoindent
set cindent
set mps+=<:>
set sm
set hls
set ic
set scs
set ls=2
syntax on


"mouse useage
set mouse=a
"status bar
set laststatus=2
set statusline=%<%F%h%m%r%h%w%y\ %{strftime(\"%Y/%m/%d-%H:%M\")}%=\ col:%c%V\ ascii:%b\ pos:%o\ lin:%l\,%L\ %P
"current line color
set cursorline
hi cursorline guibg=#EFF5EF
hi CursorColumn guibg=#EFF5EF
"상용구 설정
iab xdate <C-R>=strftime("%Y-%m-%d %H:%M:%S")<CR>
iab xtime <C-R>=strftime("%H:%M:%S")<CR>


"font setting
"------------------------------------------------------------------------------------------------------------
" UTF-8, euc-kr 한글문서 그냥 열기
if v:lang =~ "^ko"
     set encoding=cp949
     set fileencodings=utf-8,cp949
     set guifontset=-*-*-medium-r-normal--16-*-*-*-*-*-*-*
endif

if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
     set encoding=utf-8
     set fileencodings=utf-8,cp949
endif

if has("gui_running")
     set gfn=굴림체:h9:cHANGEUL
endif


"edit setting
"------------------------------------------------------------------------------------------------------------
set si
set ai

set ts=4
set sw=4
set sts=4
set noet

set scs
set ignorecase
set smartcase

set report=0

"붙여넣기시 들여쓰기 여부 선택 <Ins> 키로 paste 상태와 nopaste 상태 전환
set pastetoggle=<Ins>
"매치되는 괄호 표시
set showmatch


"ctags
"------------------------------------------------------------------------------------------------------------
set tags +=/usr/include/tags
set tags +=./tags


"cscope
"------------------------------------------------------------------------------------------------------------
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb

if filereadable ("./cscope.out")
     cs add cscope.out
else
     cs add /usr/src/linux/cscope.out
endif
set csverb

function! LoadCscope()
    let db = findfile("cscope.out", ".;")
    if (!empty(db))
        let path = strpart(db, 0, match(db, "/cscope.out$"))
        set nocscopeverbose " suppress 'duplicate connection' error
        exe "cs add " . db . " " . path
        set cscopeverbose
    endif
endfunction
au BufEnter /* call LoadCscope()


"Tag list
"------------------------------------------------------------------------------------------------------------
let Tlist_Ctags_Cmd="/usr/bin/ctags"
let Tlist_Inc_Winwidth=0
let Tlist_Exit_OnlyWindow=0
let Tlist_Auto_Open=0
let Tlist_Use_Right_Window=1
"Window close=off

"Source explorer
"------------------------------------------------------------------------------------------------------------
let g:SrcExpl_winHeight = 8
let g:SrcExpl_refreshTime = 100
let g:SrcExpl_jumpKey = "<ENTER>"
let g:SrcExpl_gobackKey = "<SPACE>"
let g:SrcExpl_searchLocalDef = 1
let g:SrcExpl_isUpdateTags = 0
let g:SrcExpl_updateTagsCmd = "ctags --sort=foldcase -R ."
let g:SrcExpl_updateTagsKey = "<F11>"
let g:SrcExpl_prevDefKey = "<F9>"
let g:SrcExpl_nextDefKey = "<F10>"
let g:SrcExpl_pluginList = [
   \ "__Tag_List__",
   \ "_NERD_tree_",
   \ "Source_Explorer"
   \ ]

nmap <C-H> <C-W>h
nmap <C-J> <C-W>j
nmap <C-K> <C-W>k
nmap <C-L> <C-W>l
nmap <C-I> <C-W>j:call g:SrcExpl_Jump()<CR>
nmap <C-O> :call g:SrcExpl_GoBack()<CR>
"map <F3> :tnext^M
"map <F2> :tprevious^M


"Nerd tree
"------------------------------------------------------------------------------------------------------------
let NERDTreeWinPos="left"


"auto complpop
"------------------------------------------------------------------------------------------------------------
function! InsertTabWrapper()
     let col = col('.') - 1
     if !col || getline('.')[col-1]!~'\k'
     return "\<TAB>"
     else
     if pumvisible()
     return "\<C-N>"
     else
     return "\<C-N>\<C-P>"
     end
     endif
endfunction

inoremap <TAB> <c-r>=InsertTabWrapper()<cr>

hi Pmenu ctermbg=red
hi PmenuSel ctermbg=yellow ctermfg=black
hi PmenuSbar ctermbg=blue

"man page setting
"------------------------------------------------------------------------------------------------------------
function! Man()
     let sm = expand("<cword>")
     exe "!man -S ko:2:3:4:5:6:7:8".sm
endfunction

nmap ,ma :call Man()<cr><cr>


"macro setting
"------------------------------------------------------------------------------------------------------------
nmap <F2> :!find . -iname '*.c' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' > cscope.files<CR>
     \:!cscope -b -i cscope.files -f cscope.out<CR>
    \:cs reset<CR>

nmap <F6> :NERDTreeToggle<CR>
nmap <F7> :SrcExplToggle<CR>
nmap <F8> :TlistToggle<CR>