-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
345 lines (280 loc) · 8 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
" ====================
" === Editor Setup ===
" ====================
" ===
" === System
" ===
set nocompatible
filetype on
filetype indent on
filetype plugin on
filetype plugin indent on
set mouse=a
set encoding=utf-8
set autoread
nnoremap q: <Nop>
set clipboard=unnamed
set hidden
" ctags -R --langmap=c++:+.cu -f cuda.tags <path to cuda/include>
" ctags -R -f c++.tags /usr/include/c++
set tags=./.tags;,.tags
for tagfile in split(globpath('~/.cache/tags/lib/', '*'), '\n')
let &tags .=',' . tagfile
endfor
" Prevent delay when O after <esc>
set timeout timeoutlen=1000 ttimeoutlen=100
" Prevent incorrect backgroung rendering
let &t_ut=''
set background=dark
" true color enable
if has("termguicolors")
" enable true color
set termguicolors
endif
if &term =~# '^screen'
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
" ===
" === Main code display
" ===
set number
set relativenumber
set ruler
set cursorline
syntax enable
syntax on
" ===
" === Editor behavior
" ===
" Better tab
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set list
set listchars=tab:▸\ ,trail:▫
set scrolloff=5
" Prevent auto line split
set nowrap
set tw=0
set indentexpr=
" Better backspace
set backspace=indent,eol,start
set foldmethod=indent
set foldlevel=99
if &term =~ "screen."
let &t_ti.="\eP\e[2 q\e\\"
let &t_SI.="\eP\e[6 q\e\\"
let &t_EI.="\eP\e[2 q\e\\"
let &t_te.="\eP\e[0 q\e\\"
else
let &t_ti.="\<Esc>[2 q"
let &t_SI.="\<Esc>[6 q"
let &t_EI.="\<Esc>[2 q"
let &t_te.="\<Esc>[0 q"
endif
" ===
" === Window behaviors
" ===
set splitright
set splitbelow
" ===
" === Status/command bar
" ===
set laststatus=2
"set autochdir
set showcmd
set formatoptions-=tc
" Show command autocomplete
set wildignore=log/**,node_modules/**,target/**,tmp/**,*.rbc
set wildmenu " show a navigable menu for tab completion
set wildmode=longest,list,full
" Searching options
set hlsearch
exec "nohlsearch"
set incsearch
set ignorecase
set smartcase
" ===
" === Restore Cursor Position
" ===
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" ===
" === Basic Mappings
" ===
" Set <LEADER> as <SPACE>
let mapleader=" "
" 搜索当前选中的内容
vnoremap // y/\V<C-R>=escape(@",'/\')<CR><CR>
nmap <leader>fs :w<cr>
nmap <leader>ff :e
nmap <leader><cr> :noh<cr>
inoremap jk <esc>
inoremap <c-f> <right>
inoremap <c-b> <left>
inoremap <c-g> <esc>
nmap j gj
nmap k gk
nmap <leader>w <c-w>
nmap <leader>wd <c-w>c
nmap <leader>h :bp<CR>
nmap <leader>l :bn<CR>
nmap <leader>rc :e ~/.vim/vimrc<CR>
nmap <leader>rr :source ~/.vim/vimrc<CR>
map <leader>y "+y
map <leader>p "+p
" ===
" === Install Plugins with Vim-Plug
" ===
call plug#begin('~/.vim/plugged')
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" theme
Plug 'connorholyday/vim-snazzy'
Plug 'sickill/vim-monokai'
Plug 'liuchengxu/space-vim-dark'
" Git
Plug 'rhysd/conflict-marker.vim'
Plug 'mhinz/vim-signify'
Plug 'gisphm/vim-gitignore', { 'for': ['gitignore', 'vim-plug'] }
"Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-surround' " type ysks' to wrap the word with '' or type cs'` to change 'word' to `word`
Plug 'godlygeek/tabular' " type ;Tabularize /= to align the =
Plug 'gcmt/wildfire.vim' " in Visual mode, type i' to select all text in '', or type i) i] i} ip
Plug 'scrooloose/nerdcommenter' " in <space>cc to comment a line
Plug 'kana/vim-textobj-user'
Plug 'kana/vim-textobj-indent' "i
Plug 'kana/vim-textobj-syntax'
Plug 'kana/vim-textobj-function', { 'for':['c', 'cpp', 'vim', 'java'] } "f
Plug 'sgur/vim-textobj-parameter'
Plug 'kana/vim-textobj-entire'
Plug 'easymotion/vim-easymotion'
Plug 'ludovicchabant/vim-gutentags'
Plug 'derekwyatt/vim-fswitch'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" 剪切板图片粘贴到本地
"Plug 'img-paste-devs/img-paste.vim'
"Plug 'preservim/vim-markdown'
" 在当前光标后生成目录
" :GenTocMarked
" 更新目录
" :UpdateToc
"Plug 'mzlogin/vim-markdown-toc'
"Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' }
Plug 'vim-scripts/LargeFile'
Plug 'rickhowe/spotdiff.vim'
call plug#end()
" =========
" = Plug config
" =========
colorscheme space-vim-dark
"colorscheme monokai
"colorscheme snazzy
" =========
" = airline
" =========
let g:airline#extensions#whitespace#enabled = 0
let g:airline_symbols_ascii = 1
" ========
" = tabularize
" ========
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
" ========
" = commenter
" ========
"nmap gcc <leader>cc
" ========
" = esaymotion
" ========
let g:EasyMotion_do_mapping = 0 " Disable default mappings
nmap s <Plug>(easymotion-s2)
vmap s <Plug>(easymotion-s2)
" Turn on case-insensitive feature
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
nmap <Leader>j <Plug>(easymotion-j)
nmap <Leader>k <Plug>(easymotion-k)
vmap <Leader>j <Plug>(easymotion-j)
vmap <Leader>k <Plug>(easymotion-k)
hi EasyMotionTarget ctermbg=none ctermfg=blue
" ========
" = fzf
" ========
nmap <leader>df :Files<CR>
nmap <leader>dg :GFiles<CR>
nmap <leader>bb :Buffers<CR>
nmap <leader>de :Lines<CR>
nmap <leader>dl :BLines<CR>
nmap <leader>t :Tags<CR>
nmap <leader>e :BTags<CR>
nmap <leader>s :GGrep<CR>
nmap <leader>fr :History<CR>
imap <c-x><c-f> <plug>(fzf-complete-path)
imap <c-x><c-l> <plug>(fzf-complete-line)
command! -bang -nargs=* GGrep
\ call fzf#vim#grep(
\ 'grep -r -i -n --exclude-dir={.svn,.git,TAGS} --binary-files=without-match -- '.shellescape(<q-args>), 1,
\ fzf#vim#with_preview(), <bang>0)
command! -bang -nargs=* BTags
\ call fzf#vim#buffer_tags('',
\ printf('ctags -f - --sort=no --excmd=number --c++-kinds=+p --fields=+iaS %s 2> null',
\ fzf#shellescape(expand('%'))), fzf#vim#with_preview({ "placeholder": "{2}:{3..}" }), <bang>0)
function! MyTags()
let identifier = expand('<cword>')
let relevant_fields = taglist(identifier)
if len(relevant_fields) == 0
echohl WarningMsg
echo 'Tag not found: ' . identifier
echohl None
elseif len(relevant_fields) == 1
execute 'tag' identifier
else
call fzf#vim#tags(identifier, fzf#vim#with_preview({ "placeholder": "--tag {2}:{-1}:{3..}" }))
endif
endfunction
" 查找当前光标下的tag
nmap <silent> <C-]> :call MyTags()<CR>
" grep 查找选中的内容
vnoremap <silent> <leader>s "vy:call
\ fzf#vim#grep(
\ 'grep -r -i -n --exclude-dir={.svn,.git,TAGS} --binary-files=without-match -- ' . getreg('v'), 1,
\ fzf#vim#with_preview())<CR>
" ========
" = gutentags
" ========
" gutentags 搜索工程目录的标志,碰到这些文件/目录名就停止向上一级目录递归
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']
" 所生成的数据文件的名称
let g:gutentags_ctags_tagfile = '.tags'
" 将自动生成的 tags 文件全部放入 ~/.cache/tags 目录中,避免污染工程目录
let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
" 配置 ctags 的参数
" ctags --fields=+nkisazS --extra=+q --sort=no --tag-relative=yes --c++-kinds=+px --c-kinds=+px -R $(pwd)
let g:gutentags_ctags_extra_args = ['--fields=+nkisazS', '--extra=+q', '--sort=no', '--tag-relative=yes']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
let g:gutentags_ctags_extra_args += ['--langmap=c++:+.cu']
let g:gutentags_ctags_extra_args += ['--langmap=c++:+.cuh']
" 检测 ~/.cache/tags 不存在就新建
if !isdirectory(s:vim_tags)
silent! call mkdir(s:vim_tags, 'p')
endif
" ========
" = fswitch
" ========
nmap <silent> <leader>fo :FSHere<CR>
" ========
" = markdown
" ========
"autocmd FileType markdown nmap <buffer><silent> <leader>i :call mdip#MarkdownClipboardImage()<CR>
"let g:vim_markdown_math = 1
"let g:mkdp_path_to_chrome = 'chromium'
vmap <A-w> <Plug>OSCYankVisual
map <leader>dd :Diffthis<CR>
map <leader>do :Diffoff<CR>