-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathvimrc
377 lines (305 loc) · 14.4 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
" 基于 Ubuntu 20.04 的配置, 其他发行版本未做测试
" 最新修改基于 Debian 11, 其他发行版本未做测试
"==============================================================================
" 处理 Gnome 终端不能使用 alt 快捷键, 不做这个处理无法在 vim 中映射 alt的快捷键
"==============================================================================
let c='a'
while c <= 'z'
exec "set <A-".c.">=\e".c
exec "imap \e".c." <A-".c.">"
let c = nr2char(1+char2nr(c))
endw
set timeout ttimeoutlen=50
" ======================== 一些初始配置 ===========================
" 关闭兼容模式, 如果需要使用原始的 vi 模式, 配置: set compatible
" 默认就是关闭的, 如果不关,就无法使用 vim 的高级功能,包括下面的配置
set nocompatible
" 打开文件类型检测
filetype plugin indent on
" 定义快捷键的前缀,即<Leader> , 默认是 \ , 按的时候不太方便
let mapleader=";"
" 记住上次文件打开位置
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" 行列相关配置
set number " 显示绝对行号
set relativenumber " 显示相对行号, 会覆盖上面选项
" 设置切换绝对行号和相对行号的快捷键, 这个需要的时候切换提高效率
" 这里默认是相对行号, 需要绝对行号时候可以通过快捷键修改
nmap <Leader>nn :set relativenumber<CR>
nmap <Leader>nu :set norelativenumber<CR>
set cursorline " 突出显示当前所在行
" set cursorcolumn " 突出显示当前列
" ==== tab 缩进
" 设置Tab长度为4空格, 只是显示, 真实的还是一个 tab
set tabstop=4
" 设置输入的 tab 转换成 4 个空格,这里只允许指定文件启用这个设置
au BufRead,BufNewFile *.md call SetTabToSpace()
function SetTabToSpace()
set shiftwidth=4 " 转换 4 个空格
set expandtab " 实时生效,配合 shiftwidth
set softtabstop=4 " 删除时候的行为, 也会同时删除 4 个空格
endfunction
" 继承前一行的缩进方式
set autoindent
" 开启实时搜索,随着你输入查询字串,显示不同的搜索结果
set incsearch
" 搜索时大小写不敏感
set ignorecase
" 退出插入模式指定类型的文件自动保存
au InsertLeave *.go,*.md write
" 保存文件时候自动去除行尾空格
autocmd BufWritePre *.md,*.go :%s/\s\+$//e
" 全选
nmap <leader>a ggvG$
" 系统剪切板复制粘贴, vim 使用系统剪切板需要 vim 支持
" 查询可以通过 vim --version | grep clipboard 查看
" 如果显示 +clipboard 就是支持, 如果是 -clipboard 就是不支持
" ubuntu 可以直接安装 gui 包提供支持: sudo apt install vim-gtk
" normal 模式下复制到系统剪切板, 这里没有 "+yy 这样只能复制一行
" 使用的时候可以 alt + c , 然后再输入 yy , 就是一行
" 也可以在文件顶部, alt + c , 然后再输入 yG , 就是全部内容
" 粘贴可以 alt + c ,然后输入 p, 就是为了省略不太好按的 "+ 组合
nmap <M-c> "+
" 复制 v 模式的选中区域
vmap <M-c> "+y
" 修改插入模式和普通模式光标的样式
let &t_SI.="\e[5 q" "SI = INSERT mode
let &t_SR.="\e[4 q" "SR = REPLACE mode
let &t_EI.="\e[1 q" "EI = NORMAL mode (ELSE)
" =================================================================
"==============================================================================
" 插件开始的位置
"==============================================================================
call plug#begin('~/.vim/plug')
set encoding=UTF-8
" 主题配色,下面几个可以使用哪个安装哪个
" Plug 'morhetz/gruvbox'
" Plug 'sonph/onehalf', { 'rtp': 'vim' }
Plug 'sainnhe/gruvbox-material'
" 状态栏插件,包括显示行号,列号,文件类型,文件名,以及Git状态
Plug 'vim-airline/vim-airline'
" 状态栏目插件的主题,使用后可以使颜色看起来更加突出一点
Plug 'vim-airline/vim-airline-themes'
" 用来提供一个导航目录的侧边栏
Plug 'preservim/nerdtree'
" nerdtree 中显示 git 状态
Plug 'Xuyuanp/nerdtree-git-plugin'
" 可以在导航中显示图标, 不过需要有字体支持,否则就是乱码
" https://github.com/ryanoasis/nerd-fonts
" 终端也需要字体配合,如我使用的是 https://github.com/ryanoasis/nerd-fonts/releases/download/v2.2.1/RobotoMono.zip
" 喜欢其他字体也可以,不过要使用带 nerd font 的字体
Plug 'ryanoasis/vim-devicons'
" 可以在文档中显示 git 信息
Plug 'airblade/vim-gitgutter'
" markdown 预览
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
" markdown 中 latex 数学公式支持
" Plug 'iamcco/mathjax-support-for-mkdp'
" 下面两个插件要配合使用,可以自动生成代码块
" B
" Plug 'SirVer/ultisnips' " 插件本身, 使用 coc-snippets 替换了
Plug 'honza/vim-snippets' " 代码片段仓库
" 代码自动完成插件
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" 插件结束的位置,插件全部放在此行上面
call plug#end()
"==============================================================================
" ======================== 主题配色设置 ===========================
" 开启24bit的颜色,开启这个颜色会更漂亮一些
set termguicolors
" 主题配色
" colorscheme gruvbox
colorscheme gruvbox-material
" gruvbox-material 背景色强度,可选: 'hard'`, `'medium'`, `'soft'
let g:gruvbox_material_background = 'hard' " hard 背景色会更亮一些
" 主题背景 dark-深色; light-浅色
set background=light
" =================================================================
" ======================== nerdtree 插件配置 ======================
" 设置一个打开的快捷键, 如我的就是 " + b 打开, 再按一次关闭
nnoremap <leader>b :NERDTreeToggle<CR>
" 导航目录展开的符号
let g:NERDTreeDirArrowExpandable = '▸'
" 导航目录关闭的符号
let g:NERDTreeDirArrowCollapsible = '▾'
" 默认显示行号
let NERDTreeShowLineNumbers=1
" 打开文件时是否显示目录, 1- 显示 0- 不显示
let NERDTreeAutoCenter=1
" 是否显示隐藏文件
let NERDTreeShowHidden=1
" 设置宽度
" let NERDTreeWinSize=31
" 忽略一下文件的显示, 可以定义只隐藏指定文件或目录
let NERDTreeIgnore=['\.pyc','\~$','\.swp','\.git']
" =================================================================
" ======================== nerdtree-git-plugin 插件 ===============
" 是否显示忽略文件 1- 显示 0- 不显示 默认 0
" let g:NERDTreeGitStatusShowIgnored = 1
" =================================================================
" ======================== vim-airline 插件配置 ===================
" 状态栏目使用主题, 还可以使用 dark, simple, solarized light 等
" 更多主题 https://github.com/vim-airline/vim-airline/wiki/Screenshots
let g:airline_theme='light'
" 安装字体后,启用这个选项后在状态栏可以看到图标
" 需要先安装 powerline 字体才可以 sudo apt-get install fonts-powerline
" 如果没有安装 powerline 字体不要启用这个选项,否则会显示乱码
" 如果 vim-devicons 插件配置好了就可以忽略 powerline 字体,这个插件包含
" 了字体图标,并且更加漂亮
let g:airline_powerline_fonts = 1
" 启动顶部的 tabline , 可以显示打开的 buffers, 显示多 tab 标签
let g:airline#extensions#tabline#enabled = 1
" 设置切换 tab 标签(buffer)的快捷键
let g:airline#extensions#tabline#buffer_idx_mode = 1
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
nmap <leader>0 <Plug>AirlineSelectTab0
nmap <leader>h <Plug>AirlineSelectPrevTab
nmap <leader>l <Plug>AirlineSelectNextTab
" =================================================================
" ======================== markdwon 插件配置 ======================
" 更多的配置见 https://github.com/iamcco/markdown-preview.nvim
" vim 打开markdown 文档是否自动预览, 0 - 否, 1 - 是, 默认: 0
" let g:mkdp_auto_start = 1
" 关闭 markdown 是否自动关闭预览文件, 0 - 否, 1 - 是, 默认: 1
" let g:mkdp_auto_close = 1
" 在启动 markdown 预览时是否在终端回显 url
" 如显示: Preview page: http://127.0.0.1:8472/page/1
let g:mkdp_echo_preview_url = 1
" markdwon 的快捷键
map <silent> <F5> <Plug>MarkdownPreview
map <silent> <F6> <Plug>StopMarkdownPreview
" =================================================================
" ======================== coc.nvim 插件配置 ======================
" 详细见 https://github.com/neoclide/coc.nvim#example-vim-configuration
" 不清楚作用,推荐配置里面有,详细见 https://github.com/neoclide/coc.nvim/issues/649
" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup
" 更新延时时间,默认是 4000 毫秒, 会感觉到延时,所以设置短一点
set updatetime=300
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set signcolumn=yes
" 选中下一个,默认是 tab , 不太习惯,换成了 Alt-j
inoremap <silent><expr> <M-j>
\ coc#pum#visible() ? coc#pum#next(1):
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
" 选中上一个, 默认是 Shift-Tab, 换成了 Alt-k
inoremap <expr><M-k> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" 选中,默认是回车,改成了 TAB
inoremap <silent><expr> <TAB> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
" 提示关闭之后再次唤起
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call ShowDocumentation()<CR>
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Run the Code Lens action on the current line.
nmap <leader>cl <Plug>(coc-codelens-action)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocActionAsync('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>