-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
386 lines (316 loc) · 8.99 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
"==========================================
" Initial Plugin
"==========================================
" change the leader key
let mapleader = "\<space>"
let g:mapleader = "\<space>"
" syntax highlighting
syntax on
set ttyfast
set lazyredraw
" set re=0
" install bundles
if filereadable(expand("~/.plugins.vim"))
source ~/.plugins.vim
elseif filereadable(expand("~/.config/nvim/plugins.vim")) " neovim
source ~/.config/nvim/plugins.vim
endif
lua require "config"
" ensure ftdetect et al work by including this after the bundle stuff
filetype plugin indent on
"==========================================
" General Settings
"==========================================
" history size
set history=2000
" detect filetype
filetype on
filetype indent on
filetype plugin on
filetype plugin indent on
" autoread
set autoread
" i don't help uganda
set shortmess+=c
set updatetime=300
" disable backup
set nobackup
set nowritebackup
" disable swapfile
set noswapfile
set wildignore=*.swp,*.bak,*.pyc,*.class,.svn
set mouse=nvi
" change the terminal's title
set title
" open new split window below current window
set splitbelow
" disable sound
set novisualbell
set noerrorbells
set t_vb=
set tm=500
set shada=!,'100,<50,s100,h,%
" For regular expressions turn magic on
set magic
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
"==========================================
" Display Settings
"==========================================
" show current row and col num
set display-=msgsep
set ruler
set showcmd
set showmode
" 在上下移动光标时,光标的上方或下方至少会保留显示的行数
set scrolloff=7
" show current col
" set cursorcolumn
" show current row
" set cursorline
set number
set wrap
set showmatch
set matchtime=2
" Highlight search
set hlsearch
set incsearch
set inccommand=nosplit
set ignorecase
set smartcase
" fold code
set foldenable
" Smart indent
set smartindent
" never add copyindent, case error " copy the previous indentation on autoindenting
set autoindent
" tab related
set tabstop=4
set shiftwidth=4
set softtabstop=4
set smarttab
set expandtab
set shiftround
" A buffer becomes hidden when it is abandoned
set hidden
" 相对行号: 行号变成相对,可以用 nj/nk 进行跳转
set relativenumber number
autocmd InsertEnter * :set norelativenumber number
autocmd InsertLeave * :set relativenumber
function! NumberToggle()
if(&relativenumber == 1)
set norelativenumber number
else
set relativenumber
endif
endfunc
nnoremap <C-n> :call NumberToggle()<cr>
"==========================================
" File Encoding Settings
"==========================================
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set termencoding=utf-8
"==========================================
" others
"==========================================
" autocompleting for exmode
set wildmenu
set wildmode=list:longest,full
" Ignore compiled files
set wildignore=*.o,*~,*.pyc,*.class
" auto reload
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
"==========================================
" Shortcut Settings
"==========================================
" turn off arrow keys
map <Left> <Nop>
map <Right> <Nop>
map <Up> <Nop>
map <Down> <Nop>
"Treat long lines as break lines (useful when moving around in them)
nnoremap k gk
nnoremap gk k
nnoremap j gj
nnoremap gj j
" I can type :help on my own, thanks. Protect your fat fingers from the evils of <F1>
noremap <F1> <Esc>"
" F2 line number on/off
function! HideNumber()
if(&relativenumber == &number)
set relativenumber! number!
elseif(&number)
set number!
else
set relativenumber!
endif
set number?
endfunc
nnoremap <leader><F2> :call HideNumber()<CR>
" F4 line wrapping on/off
nnoremap <leader><F4> :set wrap! wrap?<CR>
" F6 syntax highlighting on/off
nnoremap <leader><F6> :exec exists('syntax_on') ? 'syn off' : 'syn on'<CR>
set pastetoggle=<leader><F5> " when in insert mode, press <F5> to go to
" paste mode, where you can paste mass data
" that won't be autoindented
" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
map <leader>wj <C-W>j
map <leader>wk <C-W>k
map <leader>wh <C-W>h
map <leader>wl <C-W>l
" Go to home and end using capitalized directions
noremap H g^
noremap L g$
" Map ; to : and save a million keystrokes
nnoremap ; :
" exmode,ctrl-a to the line beginning, c-e to the end
cnoremap <C-j> <t_kd>
cnoremap <C-k> <t_ku>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
" searching related
" nnoremap / /\v
" vnoremap / /\v
" Keep search pattern at the center of the screen.
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
" disable highlighting
noremap <silent><leader>/ :nohls<CR>
" nnoremap gd *``zz
nnoremap * *``zz
" for # indent, python文件中输入新行时#号注释不切回行首
autocmd BufNewFile,BufRead *.py inoremap # X<c-h>#
" tab/buffer related
" switch buffer
nnoremap [b :bprevious<cr>
nnoremap ]b :bnext<cr>
" arraw key switch tabs
noremap <left> :tabprev<CR>
noremap <right> :tabnext<CR>
noremap <up> :bprevious<CR>
noremap <down> :bnext<CR>
" tabs
map <leader>th :tabfirst<cr>
map <leader>tl :tablast<cr>
map <leader>tj :tabnext<cr>
map <leader>tk :tabprev<cr>
" switch to specific tab
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
noremap <leader>0 :tablast<cr>
" Toggles between the active and last active tab "
" The first tab is always 1 "
let g:last_active_tab = 1
nnoremap <silent> <leader>tt :execute 'tabnext ' . g:last_active_tab<cr>
autocmd TabLeave * let g:last_active_tab = tabpagenr()
" => 选中及操作改键
" 调整缩进后自动选中,方便再次操作
vnoremap < <gv
vnoremap > >gv
" y$ -> Y Make Y behave like other capitals
map Y y$
" 复制选中区到系统剪切板中
vnoremap <leader>y "+y
vnoremap <leader>c "+y
" select all
map <Leader>sa ggVG
" select block
nnoremap <leader>v V`}
" kj to Esc
" inoremap kj <Esc>
" Quickly close the current window
nnoremap <leader>q :q<CR>
" Quickly save the current file
nnoremap <leader>w :w<CR>
" Quickly reload the current file
nnoremap <leader>e :e<CR>
" switch ' `, for the convenience of jumping to marks
nnoremap ' `
nnoremap ` '
nnoremap <leader><leader>p :pc<cr>
" remap U to <C-r> for easier redo
nnoremap U <C-r>
" lazy boi doesn't want to switch modes
" inoremap <C-h> <Left>
" inoremap <C-l> <Right>
vnoremap // y/\V<C-R>=escape(@",'/\')<CR><CR>
"==========================================
" FileType Settings
"==========================================
autocmd FileType c,python,cs,java set tabstop=4 shiftwidth=4 expandtab ai
autocmd FileType cpp set tabstop=2 shiftwidth=2 expandtab ai
autocmd FileType json,ruby,javascript,typescript,typescript.tsx,typescriptreact,javascriptreact,html,css,xml,haskell,vue set tabstop=2 shiftwidth=2 softtabstop=2 expandtab ai
autocmd FileType vue syntax sync fromstart
autocmd BufRead,BufNewFile *.md,*.mkd,*.markdown set filetype=markdown.mkd
autocmd BufRead,BufNewFile *.part set filetype=html
au BufNewFile,BufRead *.j,*.J set filetype=jasmin
" au BufNewFile,BufRead *.tsx,*.jsx set filetype=typescript.tsx
au BufNewFile,BufRead *.camkes set filetype=camkes
" autocmd FileType typescript.tsx syntax sync fromstart
au BufNewFile,BufRead *.tex set filetype=tex
" AutoSetFileHead
autocmd BufNewFile *.sh,*.py,*.java exec ":call AutoSetFileHead()"
function! AutoSetFileHead()
if &filetype == 'sh'
call setline(1, "\#!/bin/bash")
endif
if &filetype == 'python'
call setline(1, "\#!/usr/bin/env python3")
endif
if &filetype == 'java'
call setline(1,"/**")
call setline(2," * ". expand('%:t:r'))
call setline(3," */")
call setline(4,"public class " . expand('%:t:r'). " {" )
call setline(5,"")
call setline(6,"}")
endif
normal G
normal o
endfunc
"==========================================
" Highlighting and CursorShape
"==========================================
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
hi! link SignColumn LineNr
hi! link ShowMarksHLl DiffAdd
hi! link ShowMarksHLu DiffChange
hi link ALEError Error
hi Warning term=underline cterm=underline ctermfg=Yellow gui=undercurl guisp=Gold
hi link ALEWarning Warning
hi link ALEInfo SpellCap
let java_highlight_functions = 1
let java_highlight_all = 1
" let java_highlight_debug=1
let java_highlight_java_io=1
let java_highlight_java_lang_ids=1
set completeopt=menu,menuone
set display-=msgsep
" disable the annoying omni sql mapping
let g:omni_sql_no_default_maps = 1
" Neovim specific
" let g:python3_host_prog = '/Users/hyman/.pyenv/versions/neovim/bin/python3.7'
" let g:netrw_nogx = 1
"
set showtabline=2