-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
405 lines (384 loc) · 16.1 KB
/
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
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
405
" ----- Encoding Scheme -----
set enc=utf8
" 去掉BOM标记
set nobomb
" ----- Color Scheme -----
" extends the color scheme's background color to the whole terminal screen
set term=screen-256color
colorscheme molokai " 默认配色方案
if (has("termguicolors"))
" set Vim-specific sequences for RGB colors
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors " True Colors
" 更好的配色方案
" colorscheme material-theme
colorscheme solarized8_flat
endif
set background=dark " light 为亮色方案
syntax enable " 打开语法高亮
" ----- Status Line -----
set laststatus=2 " 显示状态行
set noshowmode " get rid of -- INSERT --
set showtabline=2 " forces the tabline to always show
" ----- Tab & Spaces -----
set shiftwidth=2 " 自动缩进所使用的空白长度
set tabstop=2 " number of visual spaces per TAB
set softtabstop=2 " number of spaces in tab when editing
set expandtab " tabs are spaces
set autoindent " 设置自动缩进
" 解决插入模式下delete/backspce键失效问题
set backspace=2
" ----- Searching -----
set number " 打开行号
set is hls " highlight matches
set cursorline " 高亮行
" press return to temporarily get out of the highlighted search
:nnoremap <CR> :nohlsearch<CR><CR>
" Search down into subfolders
" Provides tab-completion for all file-related tasks
set path+=**
" ----- Spell & Length Checking -----
set spell spelllang=en,cjk " cjk 同时针对中日两种文字的写法
set colorcolumn=81 " 设置超过80长度提示
" ----- Split Layouts -----
set splitbelow
set splitright
" ----- Conceal Modes -----
set concealcursor=
" ----- Undo/Redo -----
" 在你的 vimrc 加入
set undofile " Maintain undo history between sessions
" 设置你的undo保存位置,你需要先 mkdir ~/.vim/undodir
set undodir=~/.vim/undodir
" ----- Folding Setting -----
set foldmethod=manual " 启用手工折叠
"----- Keyboard Shortcuts -----
" Find the file in the NERDTree window
nmap <F5> :NERDTreeFind<CR>
" F6 key will toggle the NERDTree window
nmap <F6> :NERDTreeToggle<CR>
" 按功能键<F9>进入粘贴模式
set pastetoggle=<F9>
" <F10> run python code
let g:pymode_run_bind = '<F10>'
" F11 key will toggle the Tagbar window
nmap <F11> :TagbarToggle<CR>
" 用 <F12> 在当前窗口下面打开一个终端
noremap <F12> :below term<cr>
" 生成pdf文件
" 默认情况下,生成的 PDF 不含目录,同时各级标题不含编号,仅仅字体大小有变化,
" 要给各个 section 加上编号,可以用 --number-sections 选项;加上目录,可以使用 --toc 选项。
" 使用默认设置生成的 PDF margin 太大,根据 Pandoc 官方
" FAQ,可以使用下面的选项更改 margin:
" -V geometry:"top=2cm, bottom=1.5cm, left=2cm, right=2cm"
nmap <F8> :Pandoc! pdf -F pandoc-crossref -F pandoc-citeproc
\ -V geometry:margin=1in
\ --pdf-engine=xelatex
\ -V CJKmainfont:'Source Han Serif SC'<cr>
nmap <F7> :Pandoc! -s -F pandoc-crossref -F pandoc-citeproc
\ --mathjax=https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML<cr>
"split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" close run window in vim's python mode
:nnoremap <C-z> <C-w>z
" 使用 leader+w 在插入和normal模式下保存文件,我经常在 insert 模式下代替 Esc
inoremap <leader>w <Esc>:w<cr>
noremap <leader>w :w<cr>
noremap <leader>p :ALEFix<cr>
" Quickly open/reload vim
nnoremap <leader>ev :vsplit $MYVIMRC<CR>
nnoremap <leader>sv :source $MYVIMRC<CR>
" provide hjkl movements in Insert mode and Command-line mode via the <Alt>
" modifier key
noremap! <ESC>h <Left>
noremap! <ESC>j <Down>
noremap! <ESC>k <Up>
noremap! <ESC>l <Right>
" Alt + a 光标移当前行行首
imap <ESC>a <ESC>I
" Alt + f 光标移下一单词
imap <ESC>f <ESC><Right>wi
" Alt + b 光标移上一单词
imap <ESC>b <ESC><Right>bi
" ALT + E 光标移当前行行尾
imap <ESC>e <ESC>A
" change pydocstring default keymapping
nmap <silent> <ESC>l <Plug>(pydocstring)
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
" ----- Plugin Management -----
" using Vim-plug to install plugins
call plug#begin('~/.vim/plugged')
Plug 'gabrielelana/vim-markdown' " Markdown 语法高亮
Plug 'godlygeek/tabular' " Format tables automatically
Plug 'majutsushi/tagbar' " outline viewer
Plug 'scrooloose/nerdtree' " file system explorer
Plug 'rking/ag.vim' " 使用 Ag 在 vim 里搜索内容
Plug 'itchyny/lightline.vim' " statusline/tabline plugin
Plug 'itchyny/vim-gitbranch' " Provides the branch name
Plug 'mengelbrecht/lightline-bufferline' " display the list of buffers
Plug 'mhinz/vim-startify' " fancy start screen
Plug 'w0rp/ale' " Asynchronous Lint Engine
Plug 'mzlogin/vim-markdown-toc' " Markdown 的文章目录生成和更新
Plug 'mattn/webapi-vim' " An Interface to WEB APIs
Plug 'mattn/gist-vim' " a vimscript for creating gists
Plug 'airblade/vim-gitgutter' " shows a git diff
Plug 'vim-pandoc/vim-pandoc' " pandoc integration and utilities
Plug 'vim-pandoc/vim-pandoc-syntax' " pandoc markdown syntax
Plug 'vim-pandoc/vim-rmarkdown' " Rmarkdown support for vim
Plug 'lyokha/vim-xkbswitch' " automatic keyboard layout switching
Plug 'Yggdroot/indentLine' " display the indention levels
Plug 'python-mode/python-mode', { 'branch': 'develop' }
Plug 'aperezdc/vim-template' " Simple templates plugin for Vim
Plug 'previm/previm' " Realtime preview by Vim.
Plug 'tyru/open-browser.vim' " Open URI with your favorite browser
Plug 'lervag/vimtex' " A modern plugin for editing LaTeX
Plug 'jiangmiao/auto-pairs' " insert or delete brackets etc. in pair
Plug 'heavenshell/vim-pydocstring' " Generate Python docstring
Plug 'tpope/vim-endwise' " wisely add 'end'
Plug 'tpope/vim-ragtag' " ghetto HTML/XML mappings
Plug 'tpope/vim-surround' " quoting/parenthesizing made simple
Plug 'tpope/vim-repeat' " enable '.' supported plugin
Plug 'tpope/vim-commentary' " comment stuff out
Plug 'maximbaz/lightline-ale' " ALE indicator for the lightline
Plug 'farmergreg/vim-lastplace' " reopen files at last edit position
Plug 'Valloric/ListToggle' " toggle the quickfix and location-list
Plug 'roxma/nvim-yarp' " Remote Plugin Framework for Neovim
Plug 'roxma/vim-hug-neovim-rpc' " a compatibility layer for neovim rpc
Plug 'davidhalter/jedi-vim' " autocompletion
Plug 'ncm2/ncm2'
" Fast python completion (use ncm2 if you want type info or snippet support)
Plug 'HansPinckaers/ncm2-jedi'
Plug 'ncm2/ncm2-bufword' " Words in buffer completion
Plug 'ncm2/ncm2-path' " Filepath completion
Plug 'goerz/jupytext.vim' " edit ipynb files via jupytext
Plug 'sirver/ultisnips'
" JavaScript bundle for vim, this bundle provides syntax highlighting and
" improved indentation.
Plug 'pangloss/vim-javascript'
call plug#end()
" ----- Plugin Options -----
" ----- Documentation Setting -----
" enable conceal for italic, bold, inline-code and link text
let g:markdown_enable_conceal = 1 " gabrielelana/vim-markdown
" Add support for markdown files in tagbar.
let g:tagbar_type_markdown = {
\ 'ctagstype': 'markdown',
\ 'ctagsbin' : 'markdown2ctags.py',
\ 'ctagsargs' : '-f - --sort=yes',
\ 'kinds' : [
\ 's:sections',
\ 'i:images'
\ ],
\ 'sro' : '|',
\ 'kind2scope' : {
\ 's' : 'section',
\ },
\ 'sort': 0,
\ }
" In the case of .md, filetype becomes a modula2. If so, please describe in
" .vimrc this setting
augroup PrevimSettings
autocmd!
autocmd BufNewFile,BufRead *.{md,mdwn,mkd,mkdn,mark*} set filetype=markdown
augroup END
" To enable pandoc functionality for markdown files while using the markdown
" filetype and syntax, use
let g:pandoc#filetypes#handled = ["pandoc", "markdown"]
" opt out of syntax file for markdown files
" vim-pandoc-syntax 与 markdown linter 冲突
let g:pandoc#filetypes#pandoc_markdown = 0
" set gists to be private by default
let g:gist_post_private = 1
" 解决中文输入法切换的问题
let g:XkbSwitchEnabled = 1
" ----- LaTex config -----
" prevent vim from detecting a file with the `tex` suffix as a |plaintex|.
let g:tex_flavor = 'latex'
let g:vimtex_view_method='zathura'
" let g:vimtex_quickfix_mode=0
set conceallevel=1
let g:tex_conceal='abdmg'
" 最后两行控制的是“隐藏”功能。
" 开启了这个功能,除了你光标所在的那一行之外,
" 文本里夹杂的LaTeX代码就都会隐藏或者替换成其他符号。
" ----- Snips config -----
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
" ----- Template Setting -----
" E-mail address of the current user.
let g:email = "[email protected]"
" Current logged-in user name.
let g:username = "GUO DEJIE"
" ----- Autocompletion Setting -----
" ncm2 settings
autocmd BufEnter * call ncm2#enable_for_buffer()
set completeopt=menuone,noselect,noinsert
set shortmess+=c
inoremap <c-c> <ESC>
" make it fast
let ncm2#popup_delay = 5
let ncm2#complete_length = [[1, 1]]
" Use new fuzzy based matches
let g:ncm2#matcher = 'substrfuzzy'
" Disable Jedi-vim autocompletion and enable call-signatures options
let g:jedi#auto_initialization = 1
let g:jedi#completions_enabled = 0
let g:jedi#auto_vim_configuration = 0
let g:jedi#smart_auto_mappings = 0
let g:jedi#popup_on_dot = 0
let g:jedi#completions_command = ""
let g:jedi#show_call_signatures = "1"
let g:jedi#goto_command = "<leader>d"
let g:jedi#goto_assignments_command = "<leader>g"
let g:jedi#goto_definitions_command = ""
let g:jedi#documentation_command = "K"
let g:jedi#usages_command = "<leader>n"
let g:jedi#rename_command = "<leader>r"
" ----- Browser Setting -----
" If it looks like URI, open an URI under cursor.
" Otherwise, search a word under cursor.
nmap gx <Plug>(openbrowser-smart-search)
vmap gx <Plug>(openbrowser-smart-search)
if has("unix")
" WSL 用户如果使用chrome
let g:gist_browser_command = 'cmd.exe /C start %URL%'
let g:previm_open_cmd = "ws"
let g:previm_enable_realtime=1
if has('macunix')
" Do Mac stuff here
" 苹果 用户如果使用chrome
let g:gist_browser_command = "open -a Google\\ Chrome"
let g:previm_open_cmd = "open -a Google\\ Chrome"
let g:netrw_browsex_viewer="open -a Google\\ Chrome"
endif
endif
" ----- Statusline/Tabline Setting -----
" show git branch using lightline.vim, configure as follows.
let g:lightline = {
\ 'colorscheme': 'selenized_dark',
\ 'enable': {
\ 'statusline': 1,
\ 'tabline': 1
\ },
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ],
\ 'right': [[ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype', 'charvaluehex' ],
\ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_ok' ]]
\ },
\ 'component_function': {
\ 'gitbranch': 'gitbranch#name',
\ }
\ }
" Bufferline Configuration
let g:lightline#bufferline#min_buffer_count = 2
let g:lightline#bufferline#unicode_symbols = 1
let g:lightline#bufferline#show_number = 2
let g:lightline#bufferline#shorten_path = 0
let g:lightline#bufferline#unnamed = '[No Name]'
nmap <Leader>1 <Plug>lightline#bufferline#go(1)
nmap <Leader>2 <Plug>lightline#bufferline#go(2)
nmap <Leader>3 <Plug>lightline#bufferline#go(3)
nmap <Leader>4 <Plug>lightline#bufferline#go(4)
nmap <Leader>5 <Plug>lightline#bufferline#go(5)
nmap <Leader>6 <Plug>lightline#bufferline#go(6)
nmap <Leader>7 <Plug>lightline#bufferline#go(7)
nmap <Leader>8 <Plug>lightline#bufferline#go(8)
nmap <Leader>9 <Plug>lightline#bufferline#go(9)
nmap <Leader>0 <Plug>lightline#bufferline#go(10)
" Bufferline Integration
let g:lightline.tabline = {'left': [['buffers']], 'right': [['close']]}
let g:lightline.component_expand = {'buffers': 'lightline#bufferline#buffers',
\ 'linter_checking': 'lightline#ale#checking',
\ 'linter_warnings': 'lightline#ale#warnings',
\ 'linter_errors': 'lightline#ale#errors',
\ 'linter_ok': 'lightline#ale#ok',
\ }
let g:lightline.component_type = {'buffers': 'tabsel',
\ 'linter_checking': 'left',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error',
\ 'linter_ok': 'left',
\ }
let g:lightline#ale#indicator_checking = "\uf110 "
let g:lightline#ale#indicator_warnings = "\uf071 "
let g:lightline#ale#indicator_errors = "\uf05e "
let g:lightline#ale#indicator_ok = "\uf00c "
" ----- Code Checking -----
" 实现python格式或者markdown格式的自动调整
let g:ale_fixers = {
\ 'python': ['add_blank_lines_for_python_control_statements',
\ 'autopep8','isort','yapf','remove_trailing_lines','trim_whitespace',
\ 'ale#fixers#generic_python#BreakUpLongLines'],
\ 'markdown': ['prettier','remove_trailing_lines','trim_whitespace'],
\ 'javascript': ['prettier'],
\}
" configure linters
let g:ale_linters = {
\ 'python': ['pylint'],
\ 'markdown': ['mdl'],
\}
" 如果你觉得默认的 ale 提示符不好看,我们可以修改 ale 提示符使用 emoji 符号,
" 换成萌萌的 emoji 表情
let g:ale_sign_error = '😡'
let g:ale_sign_warning = '😠'
" ALE sets some background colors automatically for warnings and errors in the
" sign gutter. These colors can be customised, or even removed completely:
highlight clear ALEErrorSign
highlight clear ALEWarningSign
"普通模式下,前往上一个错误或警告
nmap <silent> <leader>k <Plug>(ale_previous_wrap)
" 前往下一个错误或警告
nmap <silent> <leader>j <Plug>(ale_next_wrap)
" Disable auto-detection of virtualenvironments
let g:ale_virtualenv_dir_names = []
" Environment variable ${VIRTUAL_ENV} is always used"
" prettier options:
" 'always' - Wrap prose if it exceeds the print width.
" 'never' - Do not wrap prose.
" 'preserve' - Wrap prose as-is. available in v1.9.0+
let g:ale_javascript_prettier_options = '--prose-wrap always'
" enable running ALEFix when files are saved
let g:ale_fix_on_save = 0
" ----- Pymode Setting -----
" Pymode检查代码太卡了,所以这里关掉了pymode的代码检查功能。插件Ale实现了代码的
" 异步检查,这样在代码检测的时候不会影响到其它操作。
let g:pymode_lint = 0
" Turn on the rope script
let g:pymode_rope = 1
let g:pymode_breakpoint_bind = '<leader>b'
let g:pymode_rope_show_doc_bind = '<leader>rd'
" By default when you press *<C-C>g* on any object in your code you will be moved
" to definition.
let g:pymode_rope_goto_definition_bind = '<leader>g'
" Organize imports sorts imports, too. It does that according to PEP8. Unused
" imports will be dropped.
let g:pymode_rope_organize_imports_bind = '<leader>ro'
" Keymap for rename method/function/class/variables under cursor
let g:pymode_rope_rename_bind = '<leader>rr'
let g:pymode_python = 'python3'
"自动检测并启用virtualenv
let g:pymode_virtualenv = 1
"使用PEP8风格的缩进
let g:pymode_indent = 1
"取消代码折叠
let g:pymode_folding = 0
"不在父目录下查找.ropeproject,能提升响应速度
let g:pymode_rope_lookup_project = 0
"项目修改后重新生成缓存
let g:pymode_rope_regenerate_on_write = 0
"开启python所有的语法高亮
let g:pymode_syntax = 1
let g:pymode_syntax_all = 1
"高亮缩进错误
let g:pymode_syntax_indent_errors = g:pymode_syntax_all
let g:pymode_rope_complete_on_dot = 0
let g:pymode_rope_completion = 0