Fork me on GitHub

Vim IDE搭建

VIM IDE界面:
vim ide

.vimrc基本配置:

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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
 "开启语法高亮功能
syntax enable
"允许用指定语法高亮配色方案替换默认方案
syntax on

set nocompatible " not compatible with vi
set autoread " detect when a file is changed

" make backspace behave in a sane manner
set backspace=indent,eol,start

" set a map leader for more key combos
let mapleader = ','
let g:mapleader = ','


"可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
if has('mouse')
set mouse=a
endif
"set selection=exclusive
"set selectmode=mouse,key

"显示行号
set nu

set shiftwidth=4 " 设定 << 和 >> 命令移动时的宽度为 4
set shiftround " round indent to a multiple of 'shiftwidth'
set softtabstop=4 " 使得按退格键时可以一次删掉 4 个空格
set tabstop=4 " 设定 tab 长度为 4
"set expandtab
set showmatch " 设置匹配模式,显示匹配的括号

set hlsearch "highlight searches
set incsearch "do incremental searching
set ignorecase

set wrap "turn on line wrapping
set wrapmargin=8 " wrap lines when coming within n characters from side
set linebreak " set soft wrapping


set autoindent " automatically set indent of new line
"set smartindent " 智能对齐方式


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => vim支持多种折叠:
" 手动建立折叠(manual)、
" 基于缩进进行折叠(indent)、
" 基于语法进行折叠(syntax)、
" 未更改文本构成折叠(diff)等
" => 折叠快捷方式:
" za 打开或关闭当前折叠
" zM 关闭所有折叠
" zR 打开所有折叠
" zc 折叠
" zC 对所在范围内所有嵌套的折叠点进行折叠
" zo 展开折叠
" zO 对所在范围内所有嵌套的折叠点展开
" [z 到当前打开的折叠的开始处。
" ]z 到当前打开的折叠的末尾处。
" zj 向下移动。到达下一个折叠的开始处。关闭的折叠也被计入。
" zk 向上移动到前一折叠的结束处。关闭的折叠也被计入。
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 基于缩进进行代码折叠
set foldmethod=indent
" 启动 vim 时关闭折叠代码
set nofoldenable


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups, and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"set nobackup
"set nowritebackup
"禁止生成临时文件,*.swp
set noswapfile
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp

"在编辑过程中,在右下角显示光标位置的状态行
set ruler

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => StatusLine
" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set laststatus=2 " show the satus line all the time


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General mappings/shortcuts for functionality
" Additional, plugin-specific mappings are located under
" the plugins section
"Close the current buffer
noremap <C-d> :q<cr>

"不显示行号
nmap <F3> :set nu!<CR>

"撤销修改
nnoremap <S-z> <ESC>u<cr>
inoremap <S-z> <ESC>u<cr>
vnoremap <S-z> <ESC>u<cr>

map <C-a> ggVG
map! <C-a> ggVG
vnoremap <C-c> "+y
"map <C-v> "+p
map <C-S-x> gU
map <c-s-y> gu

"使用箭头导航buffer"
map <S-right> :bn<cr>
map <S-left> :bp<cr>
set autowrite "在切换buffer时自动保存当前的文件

"ALT+up/down行内容的移动(for linux)
map <M-Up> dd<Up><Up>p
map <M-Down> ddp

"ALT+up/down行内容的移动(mac)
" Normal mode
"nnoremap <S-j> :m .+1<CR>==
"nnoremap <S-k> :m .-2<CR>==

" Insert mode
"inoremap <S-j> <ESC>:m .+1<CR>==gi
"inoremap <S-k> <ESC>:m .-2<CR>==gi

" Visual mode
"vnoremap <S-j> :m '>+1<CR>gv=gv
"vnoremap <S-k> :m '<-2<CR>gv=gv


"toggle invisible characters
"set invlist
"set listchars=tab:▸\ ,eol:¬,trail:⋅,extends:❯,precedes:❮
"highlight SpecialKey ctermbg=none " make the highlighting of tabs less annoying
"set showbreak=↳
"nmap <leader>l :set list!<cr>

cmap w!! w !sudo tee >/dev/null %



"Plugins
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"plugin
Plugin 'VundleVim/Vundle.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter' "code comment
Plugin 'scrooloose/syntastic'
Plugin 'Valloric/YouCompleteMe'
Plugin 'bling/vim-airline'
Plugin 'majutsushi/tagbar' "install ctags plugin firstly
Plugin 'terryma/vim-multiple-cursors'
Plugin 'tpope/vim-fugitive' "git plugin
Plugin 'kien/ctrlp.vim' "search file plugin
Plugin 'AutoClose' "输入(,{等需要配对的符号时,自动帮你补全剩余半个
Plugin 'Tabular' "代码更加易于纵向排版,以=或,符号对齐

Plugin 't9md/vim-choosewin' "支持类Tmux的操作
Plugin 'shawncplus/phpcomplete.vim'
Plugin 'suan/vim-instant-markdown' "[sudo] npm -g install instant-markdown-d,实时预览markdown文件
Plugin 'jiangmiao/auto-pairs'
Plugin 'tpope/vim-surround'
Plugin 'flazz/vim-colorschemes'

call vundle#end() " required
filetype plugin indent on " required


"MiniBufferExplorer
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1

"NERDTree
" 使用 NERDTree 插件查看工程文件。设置快捷键,速记:file list
nmap <F2> :NERDTreeToggle<CR>
" 设置NERDTree子窗口宽度
let NERDTreeWinSize=32
" 设置NERDTree子窗口位置
let NERDTreeWinPos="left"
" 显示隐藏文件
let NERDTreeShowHidden=1
" NERDTree 子窗口中不显示冗余帮助信息
let NERDTreeMinimalUI=1
" 删除文件时自动删除文件对应 buffer
let NERDTreeAutoDeleteBuffer=1
let NERDTreeQuitOnOpen=0 "打开文件后不关闭NERDTreeFind窗口

"autocmd vimenter * NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
autocmd VimEnter * wincmd p " 默认进入右侧编辑区
"autocmd VimEnter,BufWinEnter * NERDTreeFind | wincmd p "进入vim时打开 NERDTreeFind窗口



"powerline
"set laststatus=2
"set guifont=PowerlineSymbols\ for\ Powerline
"set nocompatible
"set t_Co=256
"let g:Powerline_symbols = 'unicode'

"airline
set t_Co=256
let g:airline_powerline_fonts = 1
"let g:airline_theme='wombat'
" display open buffers in tabline
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1

"Tagbar settings
nmap <F8> :TagbarToggle<CR>
let g:tagbar_autofocus = 1


" map fuzzyfinder (CtrlP) plugin
" nmap <silent> <leader>t :CtrlP<cr>
" nmap <silent> <leader>r :CtrlPBuffer<cr>
let g:ctrlp_map='<C-S-h>'
let g:ctrlp_dotfiles=1
let g:ctrlp_working_path_mode = 'ra'


" CtrlP ignore patterns
" let g:ctrlp_custom_ignore = {
" \ 'dir':
" '\.git$\|node_modules$\|bower_components$\|\.hg$\|\.svn$',
" \ 'file': '\.exe$\|\.so$'
" \ }
" only show files that are not ignored by git
let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']

" search the nearest ancestor that contains .git, .hg, .svn
let g:ctrlp_working_path_mode = 2


"NERD Commenter
"<leader>ca 转换注释的方式,比如: /**/和//
"<leader>cc 注释当前行和选中行
"<leader>c 如果被选区域有部分被注释,则对被选区域执行取消注释操作,其它情况执行反转注释操作
"<leader>cs 添加性感的注释,代码开头介绍部分通常使用该注释
"<leader>cA 跳转到该行结尾添加注释,并进入编辑模式
"<leader>cu 取消注释
"<leader>ci 执行反转注释操作,选中区域注释部分取消注释,非注释部分添加注释
"<leader>cm 对被选区域用一对注释符进行注释,前面的注释对每一行都会添加注释
"<leader>cy 添加注释,并复制被添加注释的部分
"<leader>c$ 注释当前光标到改行结尾的内容


" Fugitive Shortcuts
"nmap <silent> <leader>gs :Gstatus<cr>
"nmap <leader>ge :Gedit<cr>
"nmap <silent><leader>gr :Gread<cr>
"nmap <silent><leader>gb :Gblame<cr>
nmap gs :Gstatus<cr>
nmap ge :Gedit<cr>
nmap gr :Gread<cr>
nmap gb :Gblame<cr>


" syntastic
let g:syntastic_check_on_open = 0 "是否在打开文件时检查
let g:syntastic_check_on_wq = 1 "是否在保存文件后检查
let g:syntastic_error_symbol = ''
let g:syntastic_warning_symbol = ''
let g:syntastic_auto_loc_list = 1
let g:syntastic_loc_list_height = 5
let g:syntastic_enable_highlighting = 0
let g:syntastic_php_checkers = ['php', 'phpcs', 'phpmd', 'phplint']
let g:syntastic_html_checkers = []

" YouCompleteMe
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
let g:ycm_complete_in_comments = 1 "在注释输入中也能补全
let g:ycm_complete_in_strings = 1 "在字符串输入中也能补全
let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_comments_and_strings = 1 "注释和字符串中的文字也会被收入补全
let g:ycm_seed_identifiers_with_syntax=1 "语言关键字补全, 不过python关键字都很短,所以,需要的自己打开
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_min_num_of_chars_for_completion=2 " 从第2个键入字符就开始罗列匹配项`
let g:ycm_key_invoke_completion = '<C-n>' "直接触发自动补全, <C-Space>for mac
let g:ycm_cache_omnifunc=0 "禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_seed_identifiers_with_syntax=1 "开启语义补全
let g:ycm_complete_in_comments = 1 "在注释输入中也能补全
let g:ycm_complete_in_strings = 1 "在字符串输入中也能补全
set completeopt-=preview "YCM的previw窗口比较恼人,还是关闭比较好"

" 比较喜欢用tab来选择补全...
function! MyTabFunction ()
let line = getline('.')
let substr = strpart(line, -1, col('.')+1)
let substr = matchstr(substr, "[^ \t]*$")
if strlen(substr) == 0
return "\<tab>"
endif
return pumvisible() ? "\<c-n>" :
"\<c-x>\<c-o>"
endfunction
inoremap <tab> <c-r>=MyTabFunction()<cr>"


" 跳转到定义处, 分屏打开
let g:ycm_goto_buffer_command = 'horizontal-split'
let g:ycm_error_symbol = '>>'
let g:ycm_warning_symbol = '>*'
nmap <leader>gd :YcmDiags<CR>
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR> " 跳转到申明处
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR> " 跳转到定义处
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>

"minibufexplorer
"let g:miniBufExplorerMoreThanOne=0 "避免出现多个窗口

"multiple-cursors
let g:multi_cursor_use_default_mapping=0
" Default mapping
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>'

"tabular
"eg :Tab /|, :Tab/:, :Tab /:\zs
let g:tabular_loaded = 1


"与tmux中使用up/down/left/right键出现ABCD冲突, 使用tmux时要禁用
let g:autoclose_on = 1


" Window Chooser ------------------------------
" mapping
nmap - <plug>(choosewin)
" show big letters
let g:choosewin_overlay_enable = 1

" auto pairs
let g:AutoPairsFlyMode = 0
let g:AutoPairsShortcutBackInsert = '<M-b>'

" xdebug
"let g:debuggerMaxDepth = 5
"let g:debuggerPort = 8888

" vim json格式化
map <F4> :%!python -m json.tool<CR>

注意:
1、安装YouCompleteMe,出现YouCompleteMe unavailable: requires Vim compiled with Python (2.7.1+ or 3.4+) support

MAC OS下MACPORTS安装vim,首先查看:

$ vim --version | grep python      
+comments          +libcall           -python            +vreplace
+conceal           +linebreak         -python3           +wildignore

可见vim未支持python,则增加python支持修复即可:

sudo port install vim +python
轻轻的我走了,正如我轻轻的来