-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
283 lines (224 loc) · 6.95 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
source ~/.vim/nonessentials/visual_replace.vim
source ~/.vim/nonessentials/find.vim
source ~/.vim/nonessentials/text_editor_like_selection.vim
" Turn on syntax highlighting
syntax on
" Turn on smart auto-indentation
set autoindent
set smartindent
filetype plugin indent on
" Turn on auto-backup before editing
set backup
" Use ~/.backup as the backup directory
set backupdir=~/.backup
" Replace all tab with spaces
set expandtab
" Wrap long line at reasonable places (only affect
" display, not content)
set wrap
set linebreak
" Make vim less like vi
set nocompatible
" Make default indent at 2 spaces
set shiftwidth=2
" Set tab stop to 2
set tabstop=2
" uncomment to turn on line number
" "set number
" vim is optimized for keyboard-only, but if you insist on using mouse,
" uncomment the following
set mouse=a
" Fix mouse not working on split screens
set ttymouse=sgr
" LMB goes into insert mode
nnoremap <LeftMouse> <LeftMouse>a
" Fix MMB copy-then-paste, instead of just pasting
vnoremap <MiddleMouse> "_dPi
" Ensures normal mode when changing tabs/windows/buffers
au BufLeave * call feedkeys("\<Esc>", 't')
" uncomment the following to show ruler (line,colum position)
" set ruler
" some advanced options requested by students. Use them only if
" you know what you are doing (I don't know what they do!)
" set hidden
set wildmenu
set wildmode=longest:list,full
" set showcmd
set hlsearch
" set confirm
" set visualbell
" set ignorecase
" set smartcase
" The following should give 16 colors on old Windows machine
"set t_AB=[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm
"set t_AF=[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm
"set t_Co=16
" The following change the backspace on old Windows machine
set t_kb=
" Highlight cursor line
set cul
" Speed boost
" set lazyredraw
set ttyfast
" Set :vert to split right
set splitright
" Set autocomplete to only search keywords in current file, '.java' files in dir
set complete=.,u
" For students who are used to using the psvm/sout/sop abbreviation, you can
" uncomment the following.
"
iab mainfn public static void main(String[] args) {<CR><Bs>
iab println System.out.println;<Left>
iab printf System.out.printf;<Left>
"" PLUGINS
" vim-rainbow
" let g:rainbow_active = 1
" For lightline
set laststatus=2
let g:lightline={ 'colorscheme': 'deus' }
" Indentation
function! InsertTabWrapper()
let col = col('.') - 1
if pumvisible()
return "\<C-Y>"
elseif !col || getline('.')[col - 1] !~ '\k'
return "\<Tab>"
else
return "\<C-P>"
endif
endfunction
nnoremap <Tab> >>
inoremap <expr> <Tab> InsertTabWrapper()
vnoremap <Tab> >gv
" Decrease indentation
nnoremap <S-Tab> <<
vnoremap <S-Tab> <gv
inoremap <S-Tab> <C-D>
" Hide compiled java files
let g:netrw_list_hide='.*\.class$,^\./$,^\.nfs[^\.]*'
" Open new split view ([V] in Netrw) on right instead of left
let g:netrw_altv=1
" Always sets current dir as working dir in Netrw
let g:netrw_keepdir=0
" [Ctrl + Backspace] deletes previous word
" Requires 'stty -ixon' in ./bash_profile
set backspace=indent,eol,start
noremap! <C-Bs> <C-W>
noremap! <C-H> <C-W>
" Fix not selecting last character if cursor at end of line
set virtualedit=onemore
" [Ctrl + D] deletes next word
inoremap <C-D> X<Esc>ce
" [C] (visual) yank
vnoremap <silent> c y
" [V] (visual) paste
vnoremap <silent> v "_dP
" [Home] (insert) goes to first non-whitespace
inoremap <silent> <Home> <C-O>^
" [Ctrl + S] save
nnoremap <silent> <C-S> :up!<CR>
vnoremap <silent> <C-S> <C-C>:up!<CR>
inoremap <silent> <C-S> <Esc>:up!<CR>a
" [Ctrl + W] quit without saving
nnoremap <silent> <C-W> :q!<CR>
vnoremap <silent> <C-W> <C-C>:q!<CR>
inoremap <silent> <C-W> <Esc>:q!<CR>
" [Ctrl + T] new explorer tab
nnoremap <silent> <C-T> :Tex<CR>
vnoremap <silent> <C-T> <C-C>:Tex<CR>
inoremap <silent> <C-T> <Esc>:Tex<CR>
" [Ctrl + G] new explorer split
nnoremap <silent> <C-G> :Vex!<CR><C-W>=
vnoremap <silent> <C-G> <C-C>:Vex!<CR><C-W>=
inoremap <silent> <C-G> <Esc>:Vex!<CR><C-W>=
" [Ctrl + Q] return to explorer
nnoremap <silent> <C-Q> :Rex<CR>
vnoremap <silent> <C-Q> <C-C>:Rex<CR>
inoremap <silent> <C-Q> <Esc>:Rex<CR>
" [Ctrl + N] swap split windows
nnoremap <silent> <C-N> <C-W>r
vnoremap <silent> <C-N> <C-C><C-W>r
inoremap <silent> <C-N> <Esc><C-W>ra
" [Ctrl + Z] undo
nnoremap <silent> <C-Z> u
vnoremap <silent> <C-Z> <C-C>u
inoremap <silent> <C-Z> <Esc>ui
" [Ctrl + Y] redo
nnoremap <silent> <C-Y> <C-R>
vnoremap <silent> <C-Y> <C-C><C-R>
inoremap <silent> <C-Y> <Esc><C-R>a
" [Ctrl + A] visually select all
nnoremap <silent> <C-A> ggVG
vnoremap <silent> <C-A> <C-Home>oVG
inoremap <silent> <C-A> <C-Home><C-O>VG
" [Ctrl + K] compile current file
nnoremap <silent> <C-K> :!clear; javac -Xlint:unchecked,rawtypes %<CR>
vnoremap <silent> <C-K> <C-C>:!clear; javac -Xlint:unchecked,rawtypes %<CR>
inoremap <silent> <C-K> <Esc>:!clear; javac -Xlint:unchecked,rawtypes %<CR>
" [Ctrl + J] vertical terminal
nnoremap <silent> <C-J> :vert ter<CR>
vnoremap <silent> <C-J> <C-C>:vert ter<CR>
inoremap <silent> <C-J> <Esc>:vert ter<CR>
" [Ctrl + B] (normal mode) vertical split diff with current file
nnoremap <silent> <C-B> :vert diffsplit
" [Ctrl + /] (visual) comment / uncomment selection
function! JavaVisualCommentAndUncomment()
let isAllCommented = 1
let [startLine, endLine] = sort([line('v'), line('.')])
" Check if every line is commented
while startLine <= endLine
if getline(startLine) !~ "^\\s*//"
let isAllCommented = 0
endif
let startLine += 1
endwhile
if isAllCommented
return ":norm ^xx\<CR>"
else
return ":norm i//\<CR>"
endif
endfunction
au FileType java vnoremap <expr> <C-_> JavaVisualCommentAndUncomment()
" [Ctrl + /] (insert) comment / uncomment line
function! JavaInsertCommentAndUncomment()
let startingCol = col('.') - 1
let isCommented = getline('.') =~ "^\\s*//"
if isCommented
return "\<Esc>I\<Del>\<Del>\<Esc>" . (startingCol - 1) . "|i"
else
return "\<Esc>I//\<Esc>" . (startingCol + 3) . "|i"
endif
endfunction
au FileType java inoremap <expr> <C-_> JavaInsertCommentAndUncomment()
" VSCode-like colorscheme
colorscheme codedark
" Highlight 80 char boundary
set colorcolumn=80
" Delete selection
vnoremap <Bs> "_d
vnoremap <Del> "_d
" Disable error bell sounds
set noerrorbells visualbell t_vb=
autocmd GUIEnter * set visualbell t_vb=
" Prevent selecting newline in visual mode
set selection=exclusive
" Auto-complete keywords from every .java file in current dir
" You'll have start vim in working directory first.
argadd ./*.java
function! LoadTemplate()
" Use .vim/templates/template.ext file, whr .ext is the new-file extension
silent! 0r ~/.vim/templates/template.%:e
" Replace all [FILE_NAME] with the new-file filename
%s/\[FILE_NAME\]/\=expand("%:t:r")/g
call cursor(3,5)
call feedkeys('a')
endfunction
" Use template when creating new .java files
au BufNewFile *.java call LoadTemplate()
" Start in insert mode
" au BufRead,BufNewFile * startinsert
" DelimitMate expand: function fn() {<CR>} gives
" function fn() {
" //cursor here
" }
let g:delimitMate_expand_cr = 1