-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
315 lines (255 loc) · 7.42 KB
/
vimrc
File metadata and controls
315 lines (255 loc) · 7.42 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
" share clipboard
set clipboard=unnamedplus
" make backspace behave naturally
set backspace=indent,eol,start
" switching to another buffer without saving or discarding
set hidden
" syntax
syntax on
" indendation
set ts=2 softtabstop=0 expandtab sw=2 smarttab
" line wrapping
set wrap
set breakindent
" switch tabs by using Tab keys
map <Tab> gt
map <S-Tab> gT
" don't show banner in vim file explorer
let g:netrw_banner = 0
" set column guideline
set cc=100
highlight ColorColumn ctermbg=254
" command and search history
set history=1000
" ignore case in search by default
set ignorecase
" make search results highlighted
set hlsearch
highlight Search ctermbg=119
set incsearch
" Make wildmenu behave like similar to Bash completion.
set wildmode=list:longest
set wildignore=*.docx,*.jpg,*.png,*.gif,*.pdf,*.pyc,*.exe,*.flv,*.img,*.xlsx,*.tar,*.gz
" disable swapfile creation
set noswapfile
" maximum of tabs
set tabpagemax=100
" set gnome terminal title to currently edited file
set title
set titlestring=vim:\ %t
" set max text width
set textwidth=100
set formatoptions-=t
" show gutter, mainly for ALE functionality
set signcolumn=yes
" change color of signcolumn (gutter)
highlight SignColumn ctermbg=lightgrey
" disable '~' symbols
set fillchars=eob:\
" set highlight color
hi Visual cterm=none ctermbg=153 ctermfg=black
" Spell-check Markdown files and Git Commit Messages
autocmd FileType markdown setlocal spell
autocmd FileType gitcommit setlocal spell
hi SpellBad ctermbg=224
hi link markdownError Normal
" tabnew shortcut
nnoremap t :tabnew .<CR>
" delete word with ctrl-backspace
inoremap <C-H> <C-W>
cnoremap <C-H> <C-W>
" Remap ctrl+w+cursor to ctrl+cursor
nnoremap <S-Right> <C-w><Right>
nnoremap <S-Left> <C-w><Left>
nnoremap <S-Up> <C-w><Up>
nnoremap <S-Down> <C-w><Down>
inoremap <S-Right> <Esc><C-w><Right>i
inoremap <S-Left> <Esc><C-w><Left>i
inoremap <S-Up> <Esc><C-w><Up>i
inoremap <S-Down> <Esc><C-w><Down>i
" autosave when leaving insert mode or switching buffers
autocmd InsertLeave,TextChanged * silent! wall
" map ctrl+down and ctrl-up to Ctrl+e and Ctrl+y to scroll down or up
nnoremap <C-Down> <C-e>
inoremap <C-Down> <C-o><C-e>
nnoremap <C-Up> <C-y>
inoremap <C-Up> <C-o><C-y>
" xml autocomplete
set omnifunc=xmlcomplete#CompleteTags
autocmd FileType html,xml inoremap <buffer> </ </<C-X><C-O>
" always show fold column
set foldcolumn=1
" move soft-wrapped lines by one
noremap <Up> gk
noremap <Down> gj
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<C-o>gk"
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<C-o>gj"
" resize window splits
noremap <M-Left> <C-w><
noremap <M-Right> <C-w>>
noremap <M-Up> <C-w>-
noremap <M-Down> <C-w>+
inoremap <M-Left> <C-o><C-w><
inoremap <M-Right> <C-o><C-w>>
inoremap <M-Up> <C-o><C-w>-
inoremap <M-Down> <C-o><C-w>+
" automatically change to dir of file
set autochdir
" select popup menu entry with enter
inoremap <expr> <CR> pumvisible() ? "\<C-Y>" : "\<CR>"
" ----------------------- highlight and replacement shortcuts and function
" highlight function
" Map s in Visual mode to append the highlighted text to the current search
xnoremap s :<C-u>call AppendToSearch()<CR>
" Map S to delete the current search pattern
nnoremap S :let @/ = ''<CR>
" Function to append the highlighted text to the current search
function! AppendToSearch()
" Get the visually selected text
let l:selected_text = getline("'<")[col("'<")-1 : col("'>")-1]
" Escape the selected text for search
let l:escaped_text = escape(l:selected_text, '\\/')
" Check if there's an existing search pattern
if @/ !=# ''
" Append the new text to the current search pattern with \| for 'OR'
let @/ = @/ . '\|\V' . l:escaped_text
else
" Start a new search pattern
let @/ = '\V' . l:escaped_text
endif
call histadd('/', @/)
" Perform the search
normal! n
endfunction
" replacment shortcut
vnoremap r y:%s/<C-r>"//gc<left><left>
" ----------------------- marks function
function! NextMark()
let l:current_line = line('.')
let l:marks = 'abcdefghijklmnopqrstuvwxyz'
let l:best_line = -1
let l:best_mark = ''
for l:m in split(l:marks, '\zs')
let l:pos = getpos("'" . l:m)
if l:pos[1] > l:current_line
if l:best_line == -1 || l:pos[1] < l:best_line
let l:best_line = l:pos[1]
let l:best_mark = l:m
endif
endif
endfor
if l:best_mark == ''
for l:m in split(l:marks, '\zs')
let l:pos = getpos("'" . l:m)
if l:pos[1] > 0
if l:best_line == -1 || l:pos[1] < l:best_line
let l:best_line = l:pos[1]
let l:best_mark = l:m
endif
endif
endfor
endif
if l:best_mark != ''
execute "normal! '" . l:best_mark
endif
endfunction
function! PreviousMark()
let l:current_line = line('.')
let l:marks = 'abcdefghijklmnopqrstuvwxyz'
let l:best_line = -1
let l:best_mark = ''
for l:m in split(l:marks, '\zs')
let l:pos = getpos("'" . l:m)
if l:pos[1] > 0 && l:pos[1] < l:current_line
if l:pos[1] > l:best_line
let l:best_line = l:pos[1]
let l:best_mark = l:m
endif
endif
endfor
if l:best_mark == ''
for l:m in split(l:marks, '\zs')
let l:pos = getpos("'" . l:m)
if l:pos[1] > 0
if l:pos[1] > l:best_line
let l:best_line = l:pos[1]
let l:best_mark = l:m
endif
endif
endfor
endif
if l:best_mark != ''
execute "normal! '" . l:best_mark
endif
endfunction
function! AddMark()
let l:marks = 'abcdefghijklmnopqrstuvwxyz'
let l:next_mark = ''
for l:m in split(l:marks, '\zs')
let l:pos = getpos("'" . l:m)
if l:pos[1] == 0
let l:next_mark = l:m
break
endif
endfor
if l:next_mark == ''
echohl ErrorMsg | echo "No more marks available (a-z exhausted)" | echohl None
return
endif
execute "normal! m" . l:next_mark
echo "Mark '" . l:next_mark . "' set on line " . line('.')
endfunction
function! RemoveMark()
let l:current_line = line('.')
let l:marks = 'abcdefghijklmnopqrstuvwxyz'
for l:m in split(l:marks, '\zs')
let l:pos = getpos("'" . l:m)
if l:pos[1] == l:current_line
execute "delmarks " . l:m
echo "Mark '" . l:m . "' removed from line " . l:current_line
return
endif
endfor
echo "No mark on current line"
endfunction
nnoremap mm :call NextMark()<CR>
nnoremap M :call PreviousMark()<CR>
nnoremap ma :call AddMark()<CR>
nnoremap md :call RemoveMark()<CR>
" ----------------------- plugins
call plug#begin()
Plug 'vim-airline/vim-airline'
" don't show file type and environment stuff (git)
let g:airline_section_x=''
let g:airline_section_b=''
" show full path
let g:airline_section_c='%F'
Plug 'dense-analysis/ale'
let g:airline#extensions#ale#enabled = 1
let g:ale_fixers = {
\ 'json': ['jq'],
\ 'xml': ['xmllint'],
\ 'python': ['black'],
\}
let g:ale_python_black_options='--line-length=100'
let g:ale_completion_enabled = 1
" disable virtual text insertion
let g:ale_virtualtext_cursor = 0
let g:ale_virtualtext_prefix = ''
let g:ale_virtualtext = 0
Plug 'preservim/nerdcommenter'
filetype plugin on
"let g:NERDSpaceDelims = 1
let g:NERDDefaultAlign = 'left'
let g:NERDCommentEmptyLines = 1
nnoremap ee :call nerdcommenter#Comment(0,"toggle")<CR>
vnoremap e :call nerdcommenter#Comment(0,"toggle")<CR>
Plug 'ervandew/supertab'
let g:SuperTabDefaultCompletionType = "<c-n>"
Plug 'preservim/tagbar'
nnoremap q :TagbarOpenAutoClose<CR>
let g:tagbar_width = 60
let g:tagbar_left = 1
let g:tagbar_sort = 0
Plug 'jiangmiao/auto-pairs'
call plug#end()