# * 나만의 커스터마이징 Vim

Written by 📝 Hidekuma

# 적용방법

  1. 로컬 ~/.vimrc에 최하단 코드를 복붙한다. .vimrc가 없으면 만들어준다.
  2. 변경사항을 반영하기 위해, .vimrc를 재로딩해준다.
  $ source ~/.vimrc
1
  1. Vundle을 설치한다.
  $ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
1
  1. .vimrcvi로 연다.
  $ vi ~/.vimrc
1
  1. ctrl + : 하면, 화면 가장 하단에 커맨드라인을 칠 수가 있다.
  2. VundleInstall이라고 쳐준다.
  3. 완료! 기능은 사용하면서, 각 플러그인의 리포지터리와 컨픽파일 내부에 커맨드를 살펴보면 좋다.

# 컨픽파일(~/.vimrc)

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" HIDEKUMA's vimrc
" customzing for work
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Shared plugin setup for Vundle
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

filetype off                                       " required by Vundle (re-enabled below)
if isdirectory(expand("~/.vim/bundle/Vundle.vim/"))
  set rtp+=~/.vim/bundle/Vundle.vim
  call vundle#begin()

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vundle plugins
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

  " Basic
  Plugin 'VundleVim/Vundle.vim'                       " let Vundle manage Vundle, required

  " Files & Search
  Plugin 'scrooloose/nerdtree'
  Plugin 'ctrlpvim/ctrlp.vim'
  Plugin 'majutsushi/tagbar'

  " Styling
  Plugin 'vim-airline/vim-airline'          " nice statusline at the bottom of each window 
  " Plugin 'vim-airline/vim-airline-themes'
  Plugin 'airblade/vim-gitgutter'

  " Movement
  Plugin 'Lokaltog/vim-easymotion'
  Plugin 'vim-scripts/matchit.zip'

  " Theme
  Plugin 'nanotech/jellybeans.vim'
  Plugin 'chriskempson/vim-tomorrow-theme'
  Plugin 'nightsense/snow'

  " Editing utilities
  Plugin 'tpope/vim-surround'
  Plugin 'tpope/vim-repeat'
  Plugin 'terryma/vim-multiple-cursors'
  Plugin 'mattn/emmet-vim'

  " Syntax / Indenting
  Plugin 'scrooloose/syntastic'
  Plugin 'chr4/nginx.vim'
  Plugin 'plasticboy/vim-markdown'
  Plugin 'groenewege/vim-less'
  Plugin 'pangloss/vim-javascript'
  Plugin 'nathanaelkane/vim-indent-guides'

  " Lint
  Plugin 'w0rp/ale'

  " PHP / Yii
  Plugin 'mikehaertl/pdv-standalone'
  Plugin 'StanAngeloff/php.vim'
  Plugin '2072/PHP-Indenting-for-VIm'
  Plugin 'shawncplus/phpcomplete.vim'

  " Python
  Plugin 'rkulla/pydiction'

  " Git
  Plugin 'tpope/vim-fugitive'

  " Auto complete
  "Plugin 'Valloric/YouCompleteMe'

  " End of Vundle plugins
  call vundle#end()            " required
endif

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

set nocompatible                " be iMproved, required
set history=50                  " How many lines of history to remember
set confirm                     " Ask for confirmation in some situations (:q)
set ignorecase smartcase        " case insensitive search, except when mixing cases
set modeline                    " we allow modelines in textfiles to set vim settings
set hidden                      " allows to change buffer without saving
set mouse=a                     " enable mouse in all modes
set noerrorbells                " don't make noise
set novisualbell                " don't blink
set t_Co=256                    " Enable 256 color mode
set exrc                        " Scan working dir for .vimrc
set autoindent smartindent
set smarttab
set showcmd
set showmatch
set title

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text Formatting/Tab settings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

set formatoptions=tcrqn         " autowrap and comments (see :h 'fo-table)
set autoindent                  " keep indent on next line and make BS work with indenting
set wrap                        " wrap lines that exceed screen
set smarttab                    " Make Tab work fine with spaces
set showmatch                   " show matching brackets
set matchtime=5                 " tenths of a second to blink matching brackets
set hlsearch                    " highlight search phrase matches (reset with :noh)
set incsearch                   " do highlight as you type you search phrase
set list                        " show tabs, trailings spaces, ...
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" UI
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

set wildmenu                    " Show suggestions on TAB for some commands
set ruler                       " Always show current positions along the bottom
set cmdheight=1                 " the command bar is 1 high
set number                      " turn on line numbers
set lazyredraw                  " do not redraw while running macros (much faster)
set backspace=indent,eol,start  " make backspace work normal
set whichwrap+=<,>,h,l          " make cursor keys and h,l wrap over line endings
set report=0                    " always report how many lines where changed
set fillchars=vert:\ ,stl:\ ,stlnc:\    " make the splitters between windows be blank
set laststatus=2                " always show the status line
set scrolloff=10                " Start scrolling this number of lines from top/bottom
set hlsearch incsearch
set cursorline
set cursorcolumn
"set clipboard=unnamed " use OS clipboard -- brew install reattach-to-user-namespace
 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" File settings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=utf-8              " Let Vim use utf-8 internally
set fileencoding=utf-8          " Default for new files
set termencoding=utf-8          " Terminal encoding
set fileformats=unix,dos,mac    " support all three, in this order
set fileformat=unix             " default file format

filetype plugin indent on    " required

" Enable syntax highlighting (based on detected filetype)
syntax on

" When editing a file, always jump to the last cursor position.
autocmd BufReadPost * if line("'\"") && line("'\"") <= line("$") | exe "normal `\"" | endif

" Set some file types by extension
autocmd BufNewFile,BufRead *.xt,*.xd setf xml
autocmd BufNewFile,BufRead *.tpl,*.page setf html

" Global indent settings
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab

" Indenting per file type
"  - tabstop:       number of spaces inserted for each tab
"  - softtabstop:   make spaces feel like real tabs (e.g. for backspace)
"  - shiftwidth:    number of spaces for indentation (e.g. > and < )
"  - expandtab:     use spaces instaed of Tab. <c-v><TAB> gives real Tab
"  - autoindent:    keep indenting of previous line
autocmd FileType php setlocal tabstop=4 softtabstop=4 shiftwidth=4 expandtab autoindent
autocmd FileType html setlocal tabstop=4 softtabstop=4 shiftwidth=4 expandtab autoindent
autocmd FileType javascript setlocal tabstop=4 softtabstop=4 shiftwidth=4 expandtab

" PHP settings
" Let the surround plugin use `-` for <?php ?>
autocmd FileType php let b:surround_45 = "<?php \r ?>"
" Let the surround plugin use `=` for <?= ?>
autocmd FileType php let b:surround_61 = "<?= \r ?>"
" Fix javascript word boundaries (erratically activated for PHP files): exclude $
autocmd FileType php setlocal iskeyword-=$

" Function for autodetecting tab settings
function Kees_settabs()
    if len(filter(getbufline(winbufnr(0), 1, "$"), 'v:val =~ "^\\t"')) > len(filter(getbufline(winbufnr(0), 1, "$"), 'v:val =~ "^ "'))
        set noet
    else
        set et
    endif
endfunction
autocmd BufReadPost * call Kees_settabs()

" No folding for markdown files
let g:vim_markdown_folding_disabled=1

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin Settings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" color
color jellybeans
color Tomorrow-Night
"color snow 

" pydiction
let g:pydiction_location = '~/.vim/bundle/pydiction/complete-dict'
let g:pydiction_menu_height = 10

" nerdtree
nmap ,nt :NERDTree<CR>

" vim-airline
"let g:airline_theme='sol'
"let g:airline_theme_patch_func = 'AirlineThemePatch'
"function! AirlineThemePatch(palette)
"  if g:airline_theme == 'sol'
"    " Current tab should always have hightes optical priority, so don't use
"    " redish colors for modified tabs
"
"    " Color for current tab if modified (darkened blue)
"    let a:palette.tabline.airline_tabmod[3] = 30
"
"    " Color for modified (grey
"    let a:palette.normal_modified.airline_c[3] = 244
"  endif
"endfunction
let g:airline#extensions#tabline#enabled = 1        " Enhanced top tabline
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline#extensions#ale#enabled = 1

" vim-multiple-cursor
let g:multi_cursor_use_default_mapping=0
let g:multi_cursor_next_key='<C-n>'
let g:multi_cursor_prev_key='<C-p>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<Esc>'

" vim-indent-guides
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_auto_colors = 0
let g:indent_guides_exclude_filetypes = ['help', 'nerdtree']
"hi IndentGuidesOdd ctermbg=White
"hi IndentGuidesEven ctermbg=LightCyan
let g:indent_guides_guide_size = 1 
let g:indent_guides_start_level = 2

" highlight line number
hi LineNr ctermfg=white cterm=bold

" highlight cursor color
hi CursorColumn ctermbg=NONE
hi CursorLine ctermbg=Black cterm=bold

" tagbar
nmap <F8> :TagbarToggle<CR>

" tpope/vim-surround
let g:surround_indent = 0           " Make indenting on block selection + S work

" StanAngeloff/php.vim
let php_sql_query = 1               " Highlight SQL inside strings
let php_parent_error_close = 1      " Highlight parent error ] or )
let php_parent_error_open = 1       " Skip php end tag if there's an unclosed ( or [
let php_folding = 0                 " No folding
let php_sync_method = 0             " Sync from start

" 2072/PHP-Indenting-for-VIm
let g:PHP_outdentphpescape = 0      " Indent PHP tags as the surrounding non-PHP code
let g:PHP_noArrowMatching = 1       " Don't align arrows of chained method calls
let g:PHP_vintage_case_default_indent = 1   " Indent case: and default: in switch()

" vim-scripts/matchit
let b:match_ignorecase = 1

" PDV (PHP Documentor)
nnoremap <C-K> :call PhpDocSingle()<CR>
vnoremap <C-K> :call PhpDocRange()<CR>

"ctrlp
set wildignore+=*/tmp/*,*.so,*.swp,*.zip     " MacOSX/Linux
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe  " Windows
let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard'] 
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_match_window = 'min:0,max:30'

" php auto complete
let g:phpcomplete_mappings = {
   \ 'jump_to_def': '<C-]>',
   \ 'jump_to_def_split': '<C-W><C-]>',
   \ 'jump_to_def_vsplit': '<C-W><C-\>',
   \ 'jump_to_def_tabnew': '<C-W><C-[>',
   \}

" emmet
  let g:user_emmet_settings = {
  \  'php' : {
  \    'extends' : 'html',
  \    'filters' : 'c',
  \  },
  \  'xml' : {
  \    'extends' : 'html',
  \  },
  \  'haml' : {
  \    'extends' : 'html',
  \  },
  \  'tpl' : {
  \    'extends' : 'html',
  \  },
  \}

  " ALE
  let g:ale_fixers = {
  \   'php': ['php_cs_fixer'],
  \   'python': ['autopep8', 'yapf']
  \}
  let g:ale_completion_enabled = 1

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
Last Updated: 7/5/2019, 8:38:55 AM