-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
442 lines (359 loc) · 10.9 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
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
" This Source Code Form is subject to the terms of the Mozilla Public
" License, v. 2.0. If a copy of the MPL was not distributed with this
" file, You can obtain one at http://mozilla.org/MPL/2.0/.
set nocompatible
filetype off
set encoding=utf-8
autocmd! bufwritepost .vimrc source ~/.vimrc
autocmd! bufwritepost vimrc source ~/.vimrc
let mapleader=","
nmap <silent> <leader>rc :e ~/src/dotfiles/vimrc<CR>
nnoremap ; :
" Vundle: https://github.com/gmarik/vundle.git
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#begin()
" Run :PluginInstall to install these
Plugin 'VundleVim/Vundle.vim'
Plugin 'kien/ctrlp.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'tpope/vim-surround'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'scrooloose/nerdcommenter'
Plugin 'tpope/vim-fugitive'
Plugin 'Raimondi/delimitMate'
Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/syntastic'
Plugin 'Chiel92/vim-autoformat'
Plugin 'alvan/vim-closetag'
Plugin 'tpope/vim-rhubarb'
Plugin 'puremourning/vimspector'
call vundle#end()
filetype plugin indent on
let g:python3_host_prog = "/home/tudor/.virtualenvs/nvim/bin/python"
" file explorer options
map <leader>t :Explore<CR>
let g:netrw_liststyle=3
" set xterm title
set title
" access the yank registers
map <leader>r :reg<CR>
" disable whietspace diff
set diffopt=iwhite
" ...or just use the mouse
"set mouse=a
" toggle line numbers
set number
set relativenumber
nnoremap <leader>l :set norelativenumber!<CR>
nnoremap <F10> :set number! norelativenumber!<CR>
" smart buffers
set hidden
set switchbuf=useopen
" be a man and don't use backup files
set nobackup
set nowritebackup
set noswapfile
set nowb
" display trailing white space
set list listchars=tab:▸\ ,trail:·
" use spaces
set ts=4 sts=0 sw=4
autocmd Filetype javascript,jsx,xml,bib,text,tex,plaintex,html setlocal ts=2 sts=2 sw=2
" always report yanks
set report=0
" use tabs
"set tabstop=4
"set shiftwidth=4
" display right margin
set colorcolumn=80,100,120
" display current line
"set cursorline
" don't redraw screen if not necessary
set lazyredraw
" syntax highlighting and auto/smart-indenting
syntax on
filetype on
set synmaxcol=200
set background=light
set autoindent
set smartindent
set smarttab
set expandtab " for using spaces
"set noexpandtab " for using tabs
set copyindent
" clear screen when exiting VIM
"au VimLeave * :!clear
" map keys for buffer management
map <leader>< :bp<CR>
map <leader>> :bn<CR>
map <leader>/ :bd<CR>
" spell-check toggle
inoremap <silent> <F6> <c -O>:call SpellToggle()<CR>
map <silent> <F6> :call SpellToggle()<CR>
function! SpellToggle()
if &spell == 1
set nospell
else
set spell spelllang=en_gb
endif
endfunction
" somewhat better spell-checker
map <F3> :!aspell -l en_gb -c %<CR>
" press leader key twice to enter visual mode
"map <Leader><Leader> V
" colorscheme toggle
color default
let g:icantsee=1
highlight ColorColumn ctermbg=LightGray
set background=light
inoremap <silent> <F12> <c -O>:call ColorToggle()<CR>
map <silent> <F12> :call ColorToggle()<CR>
function! ColorToggle()
if g:icantsee == 1
color evening
let g:icantsee=0
highlight ColorColumn ctermbg=LightGray
set bg=dark
else
color default
let g:icantsee=1
highlight ColorColumn ctermbg=LightGray
set background=light
endif
endfunction
" don't use "thin" cursor in insert mode (neovim)
set guicursor=
" code paste toggle (no indenting)
set pastetoggle=<F2>
" :w!! will save the file as root (when forgetting to sudo vim)
cmap w!! %!sudo tee > /dev/null %
:map <leader>; :w<CR>
:map <leader>' :wa<CR>
" reload/open document shortcut
:map <F5> :edit
" custom status bar
set noruler
set laststatus=2
set statusline=%n\|%F
"" make it really obvious that the file was modifed
set statusline+=\ %m%m%m%m%m%m%m%m%m%m%m%m%m%m
set statusline+=%=
set statusline+=[%{mode()}%{mode()}%{mode()}]
set statusline+=%{fugitive#statusline()}
set statusline+=%y
set statusline+=[%c,%p\|%L]
" smarter search
set ignorecase
set smartcase
set hlsearch
set incsearch
nnoremap <leader><space> :noh<cr>
" allows to insert one single character when pressing Space
:nmap <Space> i_<Esc>r
" exuberant ctags binding
"set tags=tags
" persistent undo
set undofile
set undodir=~/var/vim
set undolevels=1000
" display completion options
set wildmenu
" tweaked scrolling
set scrolloff=5
nnoremap <C-e> 5<C-e>
nnoremap <C-y> 5<C-y>
" Yes, I know!
set shortmess=atI
" don't be obnoxious
set visualbell
" command history size
set history=10000
" display incomplete commands
set showcmd
" paste on a newline
map <leader>o :pu<CR>
" quickly open a temp file
map <leader>q :e ~/var/scrapbook.txt<CR>
" remember cursor and buffers states
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
set viminfo^=%
set nostartofline
" (un)indent
vnoremap < <gv
vnoremap > >gv
" cd to directory of current file
cmap cd. lcd %:p:h
" don't wrap lines
set nowrap
" search for selected text, forwards (*) or backwards (#).
vnoremap <silent> * :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy/<C-R><C-R>=substitute(
\escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy?<C-R><C-R>=substitute(
\escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
" NERDTree: https://github.com/scrooloose/nerdtree
map <leader>n :NERDTreeToggle<CR>
map <leader>ntf :NERDTreeFind<CR>
let NERDTreeShowHidden=1
let NERDTreeWinPos="right"
let NERDTreeShowLineNumbers=0
" disable buffer delete in NERDTree
autocmd FileType nerdtree cnoreabbrev <buffer> bd <nop>
let g:NERDTreeWinPos = "left"
" Syntastic: https://github.com/scrooloose/syntastic
map <leader>e :Errors<CR>
map <leader>sr :SyntasticReset<CR>
map <leader>. :lnext<CR>
map <leader>z :lclose<CR>
let g:syntastic_python_checkers = ['flake8']
let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_less_checkers = ['lessc']
let g:syntastic_quiet_messages = {"!level": "errors"}
let g:syntastic_python_pylint_post_args = '--rcfile=.pylintrc'
let g:syntastic_python_flake8_args='--max-line-length=120'
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 0
let g:syntastic_check_on_wq = 1
let g:syntastic_auto_jump = 0
" detect JSON files correctly
au BufRead,BufNewFile *.json set filetype=json
" detect LESS files correctly
au BufRead,BufNewFile *.less set filetype=less
" CTRLP: http://kien.github.io/ctrlp.vim/#installation
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/.git/*,*/node_modules/*,*.pyc,*/bower_components/*,*/*.egg-info/*
map <leader>b :CtrlPBuffer<CR>
map <leader>p :CtrlP<CR>
let g:ctrlp_match_window_bottom = 0
let g:ctrlp_match_window_reversed = 0
" don't set readonly mode in diff
if &diff
set noro
endif
" copy/ paste to X system clipboard
map <leader>xx :w !xsel -i -b<CR><CR>
map <leader>vv :r!xsel -b<CR>
" LaTeX-Box: https://github.com/LaTeX-Box-Team/LaTeX-Box
map <leader>mkk :Latexmk<CR>
map <leader>mkc :LatexmkClean<CR>
map <leader>mke :LatexErrors<CR>
map <leader>mkv :LatexView<CR>
let g:tex_flavor = "latex"
" remove trailling whitespace
nnoremap <Leader>rtw :%s/\s\+$//<cr>:let @/=''<CR>
" use Q for formatting the current selection or paragraph
vmap Q gq
nmap Q gqap
" sane wrapped line navigation
nnoremap j gj
nnoremap k gk
" easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" use tab to see matching bracket
nnoremap <tab> %
vnoremap <tab> %
" split vertically and switch to split
nnoremap <leader>w <C-w>v<C-w>l
map <leader>3 :n#<CR>
" YouCompleteMe: https://github.com/Valloric/YouCompleteMe
let g:ycm_confirm_extra_conf=0
nnoremap <leader>jd :YcmCompleter GoTo<CR>
" DelimitMate: https://github.com/Raimondi/delimitMate
function! BreakLine()
if (mode() == 'i')
return ((getline(".")[col(".")-2] == '{' && getline(".")[col(".")-1] == '}') ||
\(getline(".")[col(".")-2] == '(' && getline(".")[col(".")-1] == ')'))
else
return 0
endif
endfun
inoremap <expr> <CR> BreakLine() ? "<CR><ESC>O" : "<CR>"
let delimitMate_excluded_ft = "html"
" vim-autoformat: https://github.com/Chiel92/vim-autoformat
noremap <leader>f :Autoformat<CR><CR>
" Git commit messages helpers
au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
autocmd Filetype gitcommit setlocal textwidth=72
" code folding settings
set foldmethod=indent " fold by syntax highlighting
set foldnestmax=10 " deepest fold is 10 levels
set nofoldenable " dont fold by default
" even faster ESC-aping (https://powerline.readthedocs.org/en/latest/tipstricks.html#vim)
if ! has('gui_running')
set ttimeoutlen=10
augroup FastEscape
autocmd!
au InsertEnter * set timeoutlen=0
au InsertLeave * set timeoutlen=1000
augroup END
endif
" ask before leaving with unsaved changes
set confirm
" hide omnifunc scratch window after cursor move
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" use dictionary completion in spelling mode
set complete+=kspell
" don't higlight CSV collumns
let g:csv_no_column_highlight = 1
" virtualenv support for Python
"py << EOF
"import os
"import sys
"if 'VIRTUAL_ENV' in os.environ:
"project_base_dir = os.environ['VIRTUAL_ENV']
"activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
"execfile(activate_this, dict(__file__=activate_this))
"EOF
" HTML tags jumping
runtime macros/matchit.vim
" Use arrows for pane resizing (note that this disables arrow scroll, use HJKL)
map <Up> <C-W>-
map <Down> <C-W>+
map <Right> <C-W>>
map <Left> <C-W><
" get full path to current file (like readlink -f)
map <leader>rlf :echo expand('%:p')<CR>
" Github Copilot
map <leader>cp :Copilot panel<CR>
let g:copilot_filetypes = {
\ 'rust': v:false,
\ }
" vimspector
nmap <Leader>do <Plug>VimspectorStepOver
nmap <Leader>di <Plug>VimspectorStepInto
nmap <Leader>dc <Plug>VimspectorContinue
nmap <Leader>dr <Plug>VimspectorRestart
nmap <Leader>ds :VimspectorReset<CR>
nmap <Leader>dd :call vimspector#Launch()<CR>
nmap <F9> <Plug>VimspectorToggleBreakpoint
" expansions
iab tes$ Tested-by: <@>
iab rev$ Reviewed-by: <@>
iab ack$ Acked-by: <@>
iab rep$ Reported-by: <@>
iab cab$ Co-authored-by: <@>
iab sob$ Signed-off-by: <@>
iab fix$ Fixes:
iab hw$ "Hello World!"
iab ipdb$ import ipdb; ipdb.set_trace(); pass
iab cl$ console.log(
iab st$ console.log(new Error().stack);
iab tdt$ # TODO(adrianp):
iab fmt$ # FIXME(adrianp):
iab dbg$ /* eslint-disable no-debugger */ debugger;
iab #$ ####################################################################################################
iab -$ #---------------------------------------------------------------------------------------------------
iab ptb$ import traceback; traceback.print_exc()
iab rdb$ from celery.contrib import rdb; rdb.set_trace(); pass