-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
414 lines (336 loc) · 9.31 KB
/
init.vim
File metadata and controls
414 lines (336 loc) · 9.31 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
405
406
407
408
409
410
411
412
413
"gf go file
"gi 跳转到上次编辑位置 haha
"ctrl+o 移动到上次光标的位置 haha
"ZZ 保存退出
" _ _
"__ __ ___| |__ __ _(_)_ __ ___ _ __ ___
"\ \/ /|_ / '_ \ \ \ / / | '_ ` _ \| '__/ __|
" > < / /| |_) | \ V /| | | | | | | | | (__
"/_/\_\/___|_.__/ \_/ |_|_| |_| |_|_| \___|
"
" Author: @xiezhibin
" ===
" === Auto load for first time uses
" ===
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" ====================
" === Editor Setup ===
" ====================
" ===
" === System
" ===
let &t_ut=''
set autochdir
set fileencodings=utf8,cp936,gb18030,big5
set nocompatible
syntax on
set mouse=a
set encoding=utf-8
set t_Co=256
filetype off
" ===
" === Editor behavior
" ===
set number
"set relativenumber
"set cursorcolumn
set cursorline
set colorcolumn=80
set noshowmode
set nobackup
set ttimeoutlen=0
set notimeout
set noswapfile
set wildmenu
set showcmd
set undofile
set clipboard^=unnamed,unnamedplus
" ===高级
set regexpengine=1
"在执行宏命令时,不进行显示重绘;在宏命令执行完成后,一次性重绘,以便提高性能。
set lazyredraw
set ttyfast "should make scrolling faster
set noerrorbells "关闭错误信息响铃
set visualbell "使用可视响铃代替呼叫
silent !mkdir -p ~/.config/nvim/tmp/backup
silent !mkdir -p ~/.config/nvim/tmp/undo
silent !mkdir -p ~/.config/nvim/tmp/sessions
set backupdir=~/.config/nvim/tmp/backup,.
set directory=~/.config/nvim/tmp/backup,.
if has('persistent_undo')
set undofile
set undodir=~/.config/nvim/tmp/undo,.
endif
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" 退出插入模式时,自动保存
au InsertLeave * write
" 搜索
set hlsearch
set incsearch
set ignorecase
set smartcase
" 自动缩进
set autoindent
" 将ΤΑΒ转换成空格
set expandtab
" 在 insert 模式下,一个 TAB 键按下后,展示成几个空格
set softtabstop=4
"tabstop 有两个作用: 1.识别多少个空格形成一个TAB/ 2.显示既有文件时,将 TAB 显示成多个个空格
set tabstop=4
" >> 缩进的空格数
set shiftwidth=4
" 将ΤΑΒ显示为 | ,空格显示为▫
set listchars=tab:\|\ ,trail:▫
set list
" 自动换行
set wrap
" 只有遇到指定的符号(比如空格、连词号和其他标点符号),才发生折行。也就是说,不会在单词内部折行
set linebreak
" 指定折行处与编辑窗口的右边缘之间空出的字符数
set wrapmargin=2
" 垂直滚动时,光标距离顶部/底部的位置(单位:行)
set scrolloff=5
" 水平滚动时,光标距离行首或行尾的位置(单位:字符)。该配置在不折行时比较有用
set sidescrolloff=15
" ===
" === Cursor Movement
" ===
" New cursor movement (the default arrow keys are used for resizing windows)
" ^
" u
" < n o >
" e
" v
noremap <silent> r k
noremap <silent> n h
noremap <silent> i j
noremap <silent> o l
" 上下左右plus
noremap <silent> R 5k
noremap <silent> I 5j
noremap <silent> N 0
noremap <silent> O $
noremap <silent> l o
noremap <silent> L O
noremap <silent> k r
noremap <silent> h i
noremap <silent> H I
noremap m u
noremap M <C-r>
noremap u r
" Faster in-line navigation
noremap W 3w
noremap B 3b
noremap = n
noremap - N
" ===
" === Basic Mappings
" ===
" Set <LEADER> as <SPACE>, ; as :
let mapleader=" "
"noremap ; :
" Save & quit
nnoremap q :q<CR>
nnoremap s :w<CR>
inoremap ii <ESC>
inoremap oo <ESC>A
" Open the vimrc file anytime
noremap <LEADER>rc :e ~/.config/nvim/init.vim<CR>
noremap <LEADER>src :source ~/.config/nvim/init.vim<CR>
" Open Startify
noremap <LEADER>st :Startify<CR>
" Indentation
nnoremap < <<
nnoremap > >>
" Search
noremap <LEADER><CR> :nohlsearch<CR>
" ===
" === Other useful stuff
" ===
" 切换buffer
nnoremap ] :bn<CR>
nnoremap [ :bp<CR>
" \p to show the current buffer file path
nnoremap \p 1<C-G>
" Opening a terminal window
noremap <LEADER>/ :set splitbelow<CR>:sp<CR>:term<CR>
" 大小写转换 change case
noremap ` ~
" 括号自动补全
" inoremap ' ''<ESC>i
""inoremap " ""<ESC>i
""inoremap ( ()<ESC>i
""inoremap ) ()
""inoremap [ []<ESC>i
""inoremap < <><ESC>i
""inoremap { {<CR>}<ESC>O
""inoremap { {}<ESC>i
""inoremap } {}
""
" ===
" === Window management
" ===
" Use <space> + new arrow keys for moving the cursor around windows
noremap <LEADER>w <C-w>w
noremap <LEADER>u <C-w>k
noremap <LEADER>e <C-w>j
noremap <LEADER>n <C-w>h
noremap <LEADER>o <C-w>l
" Disable the default s key
noremap S <nop>
noremap D <nop>
noremap j <nop>
" split the screens to up (horizontal), down (horizontal), left (vertical), right (vertical)
noremap <LEADER>su :set nosplitbelow<CR>:split<CR>:set splitbelow<CR>
noremap <LEADER>se :set splitbelow<CR>:split<CR>
noremap <LEADER>sn :set nosplitright<CR>:vsplit<CR>:set splitright<CR>
noremap <LEADER>so :set splitright<CR>:vsplit<CR>
" Resize splits with arrow keys
noremap <LEADER><up> :res +5<CR>
noremap <LEADER><down> :res -5<CR>
noremap <LEADER><left> :vertical resize-5<CR>
noremap <LEADER><right> :vertical resize+5<CR>
" Place the two screens up and down
noremap <LEADER>sh <C-w>t<C-w>K
" Place the two screens side by side
noremap <LEADER>sv <C-w>t<C-w>H
" ===
" === Tab management
" ===
" Create a new tab with tu
noremap tu :tabe<CR>
" Move around tabs with tn and ti
noremap tn :-tabnext<CR>
noremap to :+tabnext<CR>
" Move the tabs with tmn and tmi
noremap tmn :-tabmove<CR>
noremap tmo :+tabmove<CR>
" ===================== Start of Plugin Settings =====================
" ===
" === Install Plugins with Vim-Plug
" ===
call plug#begin('~/.config/nvim/plugged')
Plug 'mhinz/vim-startify'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'bling/vim-bufferline'
Plug 'yggdroot/indentline'
Plug 'morhetz/gruvbox'
Plug 'vim-nerdtree/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'easymotion/vim-easymotion'
Plug 'tpope/vim-surround'
"Plug 'neoclide/coc.nvim',{'branch':'release'}
Plug 'lilydjwg/fcitx.vim'
Plug 'airblade/vim-gitgutter'
Plug 'lambdalisue/suda.vim' " do stuff like :sudowrite
Plug 'jiangmiao/auto-pairs'
Plugin 'zxqfl/tabnine-vim'
call plug#end()
" ===================== End of Plugin Settings =====================
" theme
colorscheme gruvbox
set background=dark
let g:airline_theme='deus'
let g:airline_powerline_fonts = 1 " 支持 powerline 字体
let g:bufferline_echo = 0
" ==
" == NERDTree
" ==
noremap tt :NERDTreeToggle<CR>
let NERDTreeMapOpenExpl = ""
let NERDTreeMapUpdir = "N"
let NERDTreeMapUpdirKeepOpen = "n"
let NERDTreeMapOpenSplit = ""
let NERDTreeMapOpenVSplit = "O"
let NERDTreeMapActivateNode = "o"
let NERDTreeMapOpenInTab = ""
let NERDTreeMapOpenInTabSilent = ""
let NERDTreeMapPreview = ""
let NERDTreeMapCloseDir = ""
let NERDTreeMapChangeRoot = "l"
let NERDTreeMapMenu = ","
let NERDTreeMapToggleHidden = "zh"
let NERDTreeMapRefrseh = ""
" ==
" == NERDTree-git
" ==
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ "Unknown" : "?"
\ }
" ==
" == easymotion
" ==
nmap f <Plug>(easymotion-overwin-f)
" ===
" === suda.vim
" ===
"cnoreabbrev sw w suda://%
nnoremap <LEADER>sudo :w suda://%<CR>
" ===
" === coc
" ===
"---normal mode--------------------
" 代码导航
nmap <silent> <LEADER>cgd <Plug>(coc-definition)
nmap <silent> <LEADER>cgy <Plug>(coc-type-definition)
nmap <silent> <LEADER>cgi <Plug>(coc-implementation)
nmap <silent> <LEADER>cgr <Plug>(coc-references)
" 报错导航
nmap <silent> <LEADER>c[ <Plug>(coc-diagnostic-prev)
nmap <silent> <LEADER>c] <Plug>(coc-diagnostic-next)
" 文档
nnoremap <silenLEADERt> <LEADER>cd :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" 重命名
nmap <leader>crn <Plug>(coc-rename)
" 当前行触发CodeAction
nmap <leader>ca <Plug>(coc-codeaction)
" 当前行触发AutoFix
nmap <leader>cff <Plug>(coc-fix-current)
"---input mode----------------
" 使用Tab来触发补全, 将这放在其他插件之前
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
"---setting -------------------------------
" 光标所在,高亮其引用
autocmd CursorHold * silent call CocActionAsync('highlight')
set updatetime=300
set signcolumn=yes
set shortmess+=c
set nowritebackup
" 格式化
command! -nargs=0 Format :call CocAction('format')
nmap <leader>cfm <Plug>(coc-fix-current)
" 折叠
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" import管理
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}