[vim] vim 설정

spring·2020년 11월 28일
0

필수 설치

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

1. YouCompleteMe (인텔리센스)

이게 jedi-vim보다 더 좋다.
CentOS7에서 이거 쓰기 힘들다.

sudo apt-get install build-essential cmake python3-dev mono-complete golang nodejs default-jdk npm -y
git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
cd ~/.vim/bundle/YouCompleteMe
git submodule update --init --recursive
python3 install.py --all

1. jedi-vim (인텔리센스)

YCM 을 사용한다면 설치 안해도 될 거 같다.


아래 명령으로 설치한다.

git clone --recursive https://github.com/davidhalter/jedi-vim.git ~/.vim/bundle/jedi-vim

2. NERDTree (트리뷰 탐색기 창)

Ubuntu에서 설치

git clone https://github.com/preservim/nerdtree.git ~/.vim/pack/vendor/start/nerdtree
vim -u NONE -c "helptags ~/.vim/pack/vendor/start/nerdtree/doc" -c q

CentOS에서 설치

wget http://www.vim.org/scripts/download_script.php?src_id=17123 -O nerdtree.zip   
unzip nerdtree.zip  
mkdir -p ~/.vim/{plugin,doc}  
cp plugin/NERD_tree.vim ~/.vim/plugin/  
cp doc/NERD_tree.txt ~/.vim/doc/ 
rm nerdtree.zip
rm -r nerdtree_plugin/

창 이동은 Ctrl+W+W로 이동이 가능하다.

3. AutoPEP8 (PEP8로 코드 포맷)

pip install autopep8
git clone https://github.com/tell-k/vim-autopep8 ~/.vim/bundle/vim-autopep8

아래에 F8키로 자동으로 변환되게 수정

4. auto-pairs (쌍 문자 입력)

별로임. 지웠음.

git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs

5. indentLine (indent 줄 표시)

git clone https://github.com/Yggdroot/indentLine.git ~/.vim/pack/vendor/start/indentLine
vim -u NONE -c "helptags  ~/.vim/pack/vendor/start/indentLine/doc" -c "q"

6. incsearch.vim(검색 하이라이팅)

git clone https://github.com/haya14busa/incsearch.vim ~/.vim/bundle/incsearch.vim

/로 검색을 시작하고 n으로 순방향, N으로 역방향 탐색이 가능하다.

.vimrc에 적용

~/.vimrc 에 아래와 같이 입력

set nocompatible
filetype off

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'gmarik/Vundle.vim'

"Plugin 'davidhalter/jedi-vim'

Plugin 'scrooloose/nerdtree'
Plugin 'Xuyuanp/nerdtree-git-plugin'

Plugin 'tell-k/vim-autopep8'

"Plugin 'jiangmiao/auto-pairs'

Plugin 'Yggdroot/indentLine'

Plugin 'Valloric/YouCompleteMe'
Plugin 'haya14busa/incsearch.vim'

call vundle#end()
filetype plugin indent on

syntax on
colo pablo
set nu
set tabstop=2

"Autopep8 shortcut (F8)
autocmd FileType python noremap <buffer> <F8> :call Autopep8()<CR>
let g:autopep8_disable_show_diff=1

"NERDTree shortcut (F6)

nnoremap <silent> <expr> <F6> g:NERDTree.IsOpen() ? "\:NERDTreeClose<CR>" : bufexists(expand('%')) ? "\:NERDTreeFind<CR>" : "\:NERDTree<CR>"

"Undo/Redo shortcut (Ctrl+Z) (Ctrl+y)

nnoremap <C-Z> u
nnoremap <C-Y> <C-R>
inoremap <C-Z> <C-O>u
inoremap <C-Y> <C-O><C-R>

"Select shortcut (Shift+Arrow)

nmap <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>
imap <S-Up> <Esc>v<Up>
imap <S-Down> <Esc>v<Down>
imap <S-Left> <Esc>v<Left>
imap <S-Right> <Esc>v<Right>

"Copy/Cut/Paste shortcut (F2) (F3) (F4)

vmap <F2> y<Esc>i
vmap <F3> d<Esc>i
map <F4> pi
imap <F4> <Esc>pi

"indentLine

let g:indentLine_color_term = 'lightblue'
let g:indentLine_color_gui = 'lightblue'
let g:indentLine_char = '┊'
let g:indentLine_first_char = '┊'
let g:indentLine_showFirstIndentLevel = 1
let g:indentLine_enabled = 1
let g:indentLine_fileTypeExclude = ['help', 'nerdtree', 'text', 'sh']
let g:indentLine_bufNameExclude = ['_.*', 'NERD_tree.*']
let g:indentLine_maxLines = 3000

"YouCompleteMe

let g:ycm_server_python_interpreter = '/usr/bin/python3'
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
let g:ycm_key_list_select_completion = ['', '']
let g:ycm_key_list_previous_completion = ['', '']
let g:SuperTabDefaultCompletionType = ''
let g:ycm_autoclose_preview_window_after_completion=1
map g :YcmCompleter GoToDefinitionElseDeclaration
let g:ycm_semantic_triggers =  {'c' : ['->', '.'],'objc' : ['->', '.', 're!\[[_a-zA-Z]+\w*\s', 're!^\s*[^\W\d]\w*\s','re!\[.*\]\s'],'ocaml' : ['.', '#'],'cpp,objcpp' : ['->', '.', '::'],'perl' : ['->'],'php' : ['->', '::'],'cs,java,javascript,typescript,d,python,perl6,scala,vb,elixir,go' : ['.'],'ruby' : ['.', '::'],'lua' : ['.', ':'],'erlang' : [':'],}

"incsearch

map /  <Plug>(incsearch-forward)
map ?  <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
set hlsearch
let g:incsearch#auto_nohlsearch = 1
map n  <Plug>(incsearch-nohl-n)
map N  <Plug>(incsearch-nohl-N)
map *  <Plug>(incsearch-nohl-*)
map #  <Plug>(incsearch-nohl-#)
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#)
nnoremap <Esc><Esc> :<C-u>nohlsearch<CR>

F8: Code formatting
F6: Turn On/Off NERDTree
Shift+↔↕: Select
F2: Copy
F3: Cut
F4: Paste
/: Find

centos에서는 NERDTree키 설정은 아래와 같이 한다.

map <F6> :NERDTreeMirror<CR>
map <F6> :NERDTreeToggle<CR>

References

profile
Researcher & Developer @ NAVER Corp | Designer @ HONGIK Univ.

1개의 댓글

comment-user-thumbnail
2021년 4월 13일

퍼가요~♥

답글 달기