-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_vimrc_linux
More file actions
404 lines (317 loc) · 9.53 KB
/
_vimrc_linux
File metadata and controls
404 lines (317 loc) · 9.53 KB
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
""""""""""""""""""""""VUNDLE PLUGIN""""""""""""""""""""
" 不兼容vi
set nocompatible
" 不检测文件类型
filetype off
" 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'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'jelera/vim-javascript-syntax'
"Plugin 'walm/jshint.vim'
Plugin 'moll/vim-node'
Plugin 'airblade/vim-gitgutter'
"Plugin 'Yggdroot/indentLine'
"Plugin 'nvie/vim-flake8'
Plugin 'davidhalter/jedi-vim'
"Plugin 'axiaoxin/vim-json-line-format'
Plugin 'junegunn/vim-emoji'
Plugin 'mhinz/vim-startify'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'suan/vim-instant-markdown'
"Plugin 'tpope/vim-surround'
"Plugin 'SirVer/ultisnips'
"Plugin 'honza/vim-snippets'
Plugin 'bling/vim-airline'
Plugin 'kien/ctrlp.vim'
Plugin 'majutsushi/tagbar'
Plugin 'scrooloose/nerdcommenter'
Plugin 'scrooloose/nerdtree'
Plugin 'Yggdroot/vim-mark'
Plugin 'jlanzarotta/bufexplorer'
Plugin 'Valloric/YouCompleteMe'
call vundle#end()
" 针对不同的文件类型采用不同的缩进格式
filetype plugin indent on
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just
" :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to
" auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
""""""""""""""""""""""BASE CONFIG"""""""""""""""""""""""
" 取消备份
set nobackup
set noswapfile
" 解决中文乱码
set encoding=utf-8
set fileencodings=utf-8,chinese,gbk,latin-1,gb2312,ucs-bom,cp936
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
" 解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" 解决consle输出乱码
"language messages zh_CN.utf-8
" 状态栏配置
set laststatus=2
" 打开语法高亮
syntax enable
" 开启语法检测
syntax on
" vimrc文件修改之后自动加载
autocmd! bufwritepost .vimrc source %
" 文件修改之后自动载入
set autoread
" yy直接复制到系统剪切板(For macvim)
"set clipboard=unnamed
" 高亮搜索命中的文本
set nohlsearch
" 随着键入即时搜索
set incsearch
" 搜索时忽略大小写
set ignorecase
" 有一个或以上大写字母时仍大小写敏感
set smartcase
set guifont=Menlo:h14
"set lines=24 columns=90
"colorscheme librae
" 使用自带配色
colorscheme desert
set background=dark
" 在状态栏显示正在输入的命令
set showcmd
" 显示括号配对情况
set showmatch
" :next, :make 命令之前自动保存
set autowrite
" 允许使用鼠标
"set mouse=a
" 设置行号
set nu
" 退格键可用
set backspace=2
" 退格键一次删掉4个空格
set smarttab
" 缩进
set autoindent
set smartindent
" 保存文件时自动删除行尾空格或Tab
"autocmd BufWritePre * :%s/\s\+$//e
" 保存文件时自动删除末尾空行
"autocmd BufWritePre * :%s/^$\n\+\%$//ge
" 填充Tab
set noexpandtab
set tabstop=8
set shiftwidth=8
set shiftround
" 代码折叠 光标在缩进下方时用za命令折叠或展开
set fdm=indent
" 默认展开
set foldlevel=99
" 突出显示当前行,列
"set cursorline
"set cursorcolumn
" 设置 退出vim后,内容显示在终端屏幕, 可以用于查看和复制
"set t_ti= t_te=
" wildmode
set wildmode=list:longest,full
" wildmenu
set wildmenu
" 256 color (fix airline display)
set term=xterm-256color
" do not wrap
set nowrap
" 打开文件时始终跳转到上次光标所在位置
autocmd BufReadPost *
\ if ! exists("g:leave_my_cursor_position_alone") |
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif |
\ endif
hi ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+\%#\@<!$\| \+\%#\@<!\ze\t/
"""""""""""""""""""""""""KEY MAPPING""""""""""""""""""""
" 映射切换buffer的键位
nnoremap [b :bp<CR>
nnoremap ]b :bn<CR>
" 映射切换tab的键位
nnoremap [t :tabp<CR>
nnoremap ]t :tabn<CR>
" normal模式下Ctrl+c全选并复制到系统剪贴板(linux必须装有vim-gnome)
nmap <C-c> gg"+yG
" visual模式下Ctrl+c复制选中内容到剪贴板
vmap <C-c> "+y
" Ctrl+v原样粘贴剪切板内容
inoremap <C-v> <ESC>"+pi
" w!!写入只读文件
cmap w!! w !sudo tee >/dev/null %
" 切换行号显示
"nnoremap <F2> :set nonu!<CR>:set foldcolumn=0<CR>
" F2显示TagList
nmap <silent> <F2> :TagbarToggle<CR>
" F3打开目录树
nmap <silent> <F3> :NERDTreeToggle<CR>
" F4 CtrlP
nmap <silent> <F4> :CtrlP<CR>
" 运行脚本
"if exists("$VIRTUAL_ENV")
" autocmd BufRead,BufNewFile *.py noremap <F5> :!$VIRTUAL_ENV'/bin/python' %<CR>
"else
" autocmd BufRead,BufNewFile *.py noremap <F5> :!python %<CR>
"endif
" <F5> 新建标签页
map <F5> <Esc>:tabnew<CR>
" <F6> vimgrep
nmap <F6> :vimgrep /<C-R>=expand("<cword>")<cr>/ **/*.c **/*.h<cr><C-o>:cw<cr>
nmap <C-F6> :vimgrep /<C-R>=expand("<cword>")<cr>/ **/*<cr><C-o>:cw<cr>
" <F7> 拷贝粘贴代码不破坏缩进
set pastetoggle=<F7>
" <F8> sort import and auto pep8
"autocmd FileType python map <buffer> <F8> :!yapf -i % --style=google;isort %;<CR><CR>
" cancel highlighting ExtraWhitespace
"nmap <F8> :match ExtraWhitespace /\s\+\%#\@<!$\| \+\%#\@<!\ze\t/<cr>
" change file format from dos to unix completely
nmap <S-F8> :e ++ff=unix<cr>:0,$s/\r//g<cr>:w ++ff=unix<cr>
" remove unexpected white spaces
nmap <C-F8> :%s=\s\+$==<cr>
" <C-F12> generate cscope.out in current dir
function! RunShell(Msg, Shell)
echo a:Msg . '...'
call system(a:Shell)
echon 'done'
endfunction
"nmap <C-F12> :!cscope -Rb<cr>
nmap <C-F12> :call RunShell("Generate cscope", "cscope -Rb")<cr>:cs add cscope.out<cr>
" cscope autoload
if has("cscope")
set csto=1
set cst
set nocsverb
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
" 给当前单词添加引号
nnoremap w" viw<esc>a"<esc>hbi"<esc>lel
nnoremap w' viw<esc>a'<esc>hbi'<esc>lel
" 在Normal Mode和Visual/Select Mode下,利用Tab键和Shift-Tab键来缩进文本
nnoremap > >>
nnoremap < <<
vnoremap > >gv
vnoremap < <gv
" 左右分割窗口Ctrl+w +v
" 上下分割窗口Ctrl+w +s
" 关闭窗口Ctrl+w +q
" quicker window switching
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" emoji
imap <C-e> <C-X><C-U>
" Set mapleader
let mapleader=","
nmap <leader>sa :cs add cscope.out<cr>
nmap <leader>ss :cs find s <C-R>=expand("<cword>")<cr><cr>
nmap <leader>sg :cs find g <C-R>=expand("<cword>")<cr><cr>
nmap <leader>sc :cs find c <C-R>=expand("<cword>")<cr><cr>
nmap <leader>st :cs find t <C-R>=expand("<cword>")<cr><cr>
nmap <leader>se :cs find e <C-R>=expand("<cword>")<cr><cr>
nmap <leader>sf :cs find f <C-R>=expand("<cfile>")<cr><cr>
nmap <leader>si :cs find i <C-R>=expand("<cfile>")<cr><cr>
nmap <leader>sd :cs find d <C-R>=expand("<cword>")<cr><cr>
nmap <leader>zz <C-w>o
" mark setting
nmap <silent> <leader>hl <Plug>MarkSet
vmap <silent> <leader>hl <Plug>MarkSet
nmap <silent> <leader>hh <Plug>MarkClear
vmap <silent> <leader>hh <Plug>MarkClear
nmap <silent> <leader>hr <Plug>MarkRegex
vmap <silent> <leader>hr <Plug>MarkRegex
" tab setting
nmap <leader>t1 1gt
nmap <leader>t2 2gt
nmap <leader>t3 3gt
nmap <leader>t4 4gt
nmap <leader>t5 5gt
nmap <leader>t6 6gt
nmap <leader>t7 7gt
nmap <leader>t8 8gt
nmap <leader>t9 9gt
" buffer setting
nmap <leader>b1 :buffer 1<CR>
nmap <leader>b2 :buffer 2<CR>
nmap <leader>b3 :buffer 3<CR>
nmap <leader>b4 :buffer 4<CR>
nmap <leader>b5 :buffer 5<CR>
nmap <leader>b6 :buffer 6<CR>
nmap <leader>b7 :buffer 7<CR>
nmap <leader>b8 :buffer 8<CR>
nmap <leader>b9 :buffer 9<CR>
""""""""""""""""""""""""""""""PLUGIN CONFIG""""""""""""""""""""""""""
" NerdCommenter
let g:NERDSpaceDelims=1
" NERDTREE
" 不显示的文件
let NERDTreeIgnore=['\.pyc$', '\~$']
" show nerdtree when starts up
"autocmd vimenter * NERDTree
" 退出最后一个buff时也退出nerdtree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" Always put it right
let g:NERDTreeWinPos="right"
let g:NERDTreeWinSize=24
" Tagbar
let g:tagbar_left = 1
let g:tagbar_width = 24
let g:tagbar_autoclose = 0
let g:tagbar_iconchars = ['▸', '▾']
let g:tagbar_autoshowtag = 1
" CtrlP
let g:ctrlp_show_hidden = 1
"Ctrl-X Ctrl-U emoji补全
set completefunc=emoji#complete
" instant-markdown
let g:instant_markdown_slow = 1
" airline
let g:airline_section_y = '%{strftime("%H:%M")}'
" 开启tabline
let g:airline#extensions#tabline#enabled = 1
" tabline中当前buffer两端的分隔字符
"let g:airline#extensions#tabline#left_sep = ' '
" tabline中未激活buffer两端的分隔字符
"let g:airline#extensions#tabline#left_alt_sep = '|'
" tabline中buffer显示编号
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline_theme = 'sol'
" jedi
autocmd FileType python setlocal completeopt-=preview
let g:jedi#completions_command = "<C-n>"
"" flake8
"let g:flake8_show_in_file = 1
"let g:flake8_show_in_gutter = 1
"autocmd! BufRead,BufWritePost *.py call Flake8()
" gitgutter
let g:gitgutter_sign_modified = '*'
let g:gitgutter_sign_removed = '-'
" ultisnips
"let g:UltiSnipsExpandTrigger="<tab>"
"let g:UltiSnipsJumpForwardTrigger="<tab>"
"let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
" jshint
"autocmd! BufRead,BufWritePost *.js :JSHint