-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
462 lines (387 loc) · 13.3 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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
"""""""""
" vimrc "
"""""""""
" General options {{{
"""""""""""""""""""""
set autoread " Set to auto read when a file is changed
set autowrite " Automatically save before commands like :next and :make
set backupcopy=yes " Preserve hard links when making copies
set confirm " Instead of failing a command, raise a dialog asking what to do
set encoding=utf8 " Set default encoding
set fileformats=unix,dos " Set Unix as the standard line ending
set foldlevelstart=5 " How many folds to show at file open
set hidden " Hide buffers when they are abandoned
set hlsearch " Highlight matches when searching
set incsearch " Incremental search
set lazyredraw " Don't redraw when running macros
set magic " Use traditional regular expressions (see wiki)
set matchtime=1 " How many tenths of a second to blink when matching brackets
set mouse=n " Enable mouse usage (normal mode only)
set nocompatible " Disable vi compatibility options
set noshowmode " Powerline does this for me, so disable the default mode
set nosmartindent " Prevent audo dedent on Python comment
set ruler " Display the bar at the bottom
set secure " Shell and write commands are disallowed in local vimrcs
set shell=/bin/bash " Use bash as the vim shell
set showcmd " Show (partial) command in status line
set showmatch " Show matching brackets
set smartcase " Do smart case matching
set smarttab " Use smart tabbing
set tabpagemax=500 " Maximum number of tabs
set timeoutlen=50 " To prevent the lag on 'O'
set undolevels=10000 " Allow for 10,000 undos
set wrap " Wrap long lines
" Set leader key
let mapleader = '\'
" }}}
" Appearance {{{
""""""""""""""""
" Set the colorscheme
if has("syntax")
syntax on
try
colorscheme void
catch
" Fallback colorscheme
colorscheme delek
endtry
endif
" Linebreak at 500 characters
set linebreak
set textwidth=500
" Set relative line numbers
set number
set relativenumber
" }}}
" Behavior settings {{{
"""""""""""""""""""""""
" Where split files should go
set splitbelow
set splitright
" Only time out on keybinds, not mappings
set notimeout
set ttimeout
" How many lines of history to remember
set history=1000
" Enable filetype plugins
filetype plugin on
filetype indent on
" Swap files
try
set directory=~/.vim_runtime/swap
catch
endtry
" Backup files
try
set backup
set backupdir=~/.vim_runtime/backups
set writebackup
catch
endtry
" Undo files
try
set undodir=/tmp/emmie/vim_undo
set undofile
catch
endtry
" Use 4 spaces for tabs
" See the 'file-specific settings' section for file types
" that override these settings.
set expandtab
set tabstop=4
set shiftwidth=4
" Print whitespace
set list listchars=tab:»\ ,trail:·
" Set the behavior when switching between buffers
try
set switchbuf=useopen,usetab,newtab
set showtabline=2
catch
endtry
" Enable auto indent
set ai
" Turn off physical line wrapping (i.e. the automatic insert of newlines)
set textwidth=0
set wrapmargin=0
" Have backspace actually go backwards
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" Allow tab completion in the menu
set wildmode=longest,list,full
set wildmenu
set wildignore=*.o,*.d,*.so,*~,*.pyc,.git
" Set viminfo
set viminfo=%,\"100,'10,/50,:100,h,f0,n~/.viminfo
" Have vim jump to the last location when opening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" Have vim load indent rules and plugins
if has("autocmd")
filetype plugin indent on
endif
" Set number of lines to the cursor when moving vertically
if (&lines > 35)
set scrolloff=9
else
set scrolloff=2
endif
" }}}
" Modified commands {{{
"""""""""""""""""""""""
" Have Y act like C and D rather than yy
map Y y$
" Have <C-l> also turn of search highlighting
nnoremap <C-l> :nohl<cr><C-l>
" Remove ^M from Windows newlines
noremap <leader>dos mmHmt:%s/<C-v><cr>//ge<cr>'tzt'm
" Set :grep to use ripgrep
if executable('rg')
set grepprg=rg\ --no-heading\ --vimgrep\ --smart-case
set grepformat=%f:%l:%c:%m
endif
" }}}
" New commands {{{
""""""""""""""""""
" :W is the same as w, for typos
command W w
" :Sudo does a sudo save on the file
command Sudo w !sudo tee % > /dev/null
" :Cstyle sets my preferred formatting for C programs
command Cstyle set cindent shiftwidth=8 tabstop=8 softtabstop=8 noexpandtab
" :Path prints the full path of the current buffer
command Path :echo expand('%:p')
" Save session
command SessionSave :mksession<cr>
" Search for merge conflict markers
command MergeFail :/^\(<<<<<<<\|=======\|>>>>>>>\)
" Open all buffers as separate tabs
" Useful if vim is invoked without -p
command BuffersToTabs :bufdo tab split
" Move between windows easier
nnoremap <SID> <Plug>IMAP_JumpForward
" Open a newline without going into insert mode
nmap <cr> o<esc>
" Pressing * or # when in visual mode searches for the current selection
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>
" Highlight last inserted text
nnoremap gV `[v`]
" Close all hidden buffers
function! CloseHiddenBuffers()
let visible = {}
" fetch visible tabs
for t in range(1, tabpagenr('$'))
for b in tabpagebuflist(t)
let visible[b] = 1
endfor
endfor
" close any loaded buffers that are not visible
for b in range(1, bufnr('$'))
if bufloaded(b) && !has_key(visible, b)
exe 'bd ' . b
endif
endfor
endfun
command CloseBufs :call CloseHiddenBuffers()
" Close the current buffer
cmap <leader>bd :Bclose<cr>:tabclose<cr>gT
" Close all the buffers
map <leader>ba :bufdo bd<cr>
map <leader>bn :bnext<cr>
map <leader>bp :bprevious<cr>
" Useful mappings for managing tabs
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove<Space>
" Open a new tab (\te has the current buffer's path)
map <leader>tn :tabnew<Space>
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
" Switch the cwd to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
" Move a line of text using SHIFT+ALT+[jk]
nmap <M-S-j> mz:m+<cr>`z
nmap <M-S-k> mz:m-2<cr>`z
vmap <M-S-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-S-k> :m'<-2<cr>`>my`<mzgv`yo`z
" ss toggles spellcheck
map <leader>ss :setlocal spell!<cr>
" System clipboard
nmap <leader>p "+p
nmap <leader>P "+P
nmap <leader>y "+y
nmap <leader>x "+x
nmap <leader>d "+d
vmap <leader>p "+p
vmap <leader>P "+P
vmap <leader>y "+y
vmap <leader>x "+x
vmap <leader>d "+d
" YouCompleteMe - jump to definition
nmap <leader>o :YcmCompleter GoTo<cr>
" Toggle into 'paste mode' (no indentation on new line)
set pastetoggle=<F11>
" }}}
" Plugins {{{
"""""""""""""
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Vundle itself
Plugin 'VundleVim/Vundle.vim'
" Syntax highlighting
Plugin 'Glench/Vim-Jinja2-Syntax'
Plugin 'Slava/vim-spacebars'
Plugin 'cespare/vim-toml'
Plugin 'evanleck/vim-svelte'
Plugin 'mboughaba/i3config.vim'
Plugin 'pest-parser/pest.vim'
Plugin 'rust-lang/rust.vim'
Plugin 'scpwiki/vim-wikidot'
" IDE-like
Plugin 'mhinz/vim-signify'
Plugin 'Valloric/YouCompleteMe'
" End vundle setup
call vundle#end()
filetype plugin indent on
" }}}
" Plugin settings {{{
"""""""""""""""""""""
" Settings for vim powerline
set laststatus=2
set t_Co=256
let g:powerline_pycmd = 'py3'
" rust.vim
let g:autofmt_autosave = 1
" vim-javascript
let g:javascript_plugin_jsdoc = 1
let g:javascript_plugin_ngdoc = 1
let g:javascript_plugin_flow = 1
" LaTeX settings
let g:tex_flavor = 'latex'
let g:Imap_UsePlaceHolders = 0
" YouCompleteMe options
let g:EclimCompletionMethod = 'omnifunc'
let g:tern_show_argument_hints = 'on_hold'
let g:ycm_global_ycm_extra_conf = '/usr/share/vim/vimfiles/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_keep_logfiles = 1
let g:ycm_log_level = 'debug'
let g:ycm_python_binary_path = '/usr/bin/python3'
let g:ycm_server_python_interpreter = '/usr/bin/python3'
let g:ycm_confirm_extra_conf = 0
let g:ycm_autoclose_preview_window_after_completion = 1
let g:tern_map_keys = 1
let g:ycm_rust_src_path = expand('$HOME') . '/documents/relic/git/rust/src'
let g:ycm_language_server =
\ [
\ {
\ 'name': 'rust',
\ 'cmdline': ['rust-analyzer'],
\ 'filetypes': ['rust'],
\ 'project_root_files': ['Cargo.toml']
\ }
\ ]
" }}}
" Helper functions {{{
""""""""""""""""""""""
" Delete trailing white space on save
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
" And call it on certain files
if has("autocmd")
autocmd BufWrite *.c :call DeleteTrailingWS()
autocmd BufWrite *.cc :call DeleteTrailingWS()
autocmd BufWrite *.cpp :call DeleteTrailingWS()
autocmd BufWrite *.h :call DeleteTrailingWS()
autocmd BufWrite *.hh :call DeleteTrailingWS()
autocmd BufWrite *.hpp :call DeleteTrailingWS()
autocmd BufWrite *.go :call DeleteTrailingWS()
autocmd BufWrite *.py :call DeleteTrailingWS()
autocmd BufWrite *.rs :call DeleteTrailingWS()
autocmd BufWrite *.java :call DeleteTrailingWS()
autocmd BufWrite *.php :call DeleteTrailingWS()
autocmd BufWrite *.tpl :call DeleteTrailingWS()
autocmd BufWrite *.tex :call DeleteTrailingWS()
autocmd BufWrite *.ts :call DeleteTrailingWS()
autocmd BufWrite *.txt :call DeleteTrailingWS()
autocmd BufWrite *.html :call DeleteTrailingWS()
autocmd BufWrite *.css :call DeleteTrailingWS()
autocmd BufWrite *.scss :call DeleteTrailingWS()
autocmd BufWrite *.js :call DeleteTrailingWS()
autocmd BufWrite Makefile :call DeleteTrailingWS()
endif
func! OpenTabs(...)
for filename in a:000
:tabnew &filename
endfor
endfunc
" }}}
" File-Specific Settings {{{
autocmd BufRead *.c setl cindent shiftwidth=8 tabstop=8 softtabstop=8 noexpandtab textwidth=80 foldmethod=syntax
autocmd BufRead *.cc setl cindent foldmethod=syntax
autocmd BufRead *.cpp setl cindent foldmethod=syntax
autocmd BufRead *.go setl shiftwidth=4 tabstop=4 softtabstop=4 noexpandtab textwidth=72 foldmethod=syntax
autocmd BufRead *.h setl cindent shiftwidth=8 tabstop=8 softtabstop=8 noexpandtab textwidth=80 foldmethod=syntax filetype=c
autocmd BufRead *.hh setl cindent foldmethod=syntax
autocmd BufRead *.hpp setl cindent foldmethod=syntax
autocmd BufRead *.handlebars setl shiftwidth=2 tabstop=2 foldmethod=indent
autocmd BufRead *.hbs setl shiftwidth=2 tabstop=2 foldmethod=indent
autocmd BufRead *.j2 setl shiftwidth=2 tabstop=2 foldmethod=indent
autocmd BufRead *.html setl shiftwidth=2 tabstop=2 foldmethod=indent
autocmd BufRead *.htm setl shiftwidth=2 tabstop=2 foldmethod=indent
autocmd BufRead *.mustache setl shiftwidth=2 tabstop=2 foldmethod=indent
autocmd BufRead *.mst setl shiftwidth=2 tabstop=2 foldmethod=indent
autocmd BufRead *.tera setl shiftwidth=2 tabstop=2 filetype=jinja
autocmd BufRead *.tf setl shiftwidth=2 tabstop=2
autocmd BufRead *.js setl shiftwidth=2 tabstop=2 foldmethod=syntax conceallevel=1
autocmd BufRead package*.json setl shiftwidth=2 tabstop=2
autocmd BufRead tsconfig*.json setl shiftwidth=2 tabstop=2
autocmd BufRead *eslint*.json setl shiftwidth=2 tabstop=2
autocmd BufRead *.json setl foldmethod=syntax conceallevel=2
autocmd BufRead *.ts setl shiftwidth=2 tabstop=2
autocmd BufRead *.css setl shiftwidth=2 tabstop=2 foldmethod=syntax
autocmd BufRead *.scss setl shiftwidth=2 tabstop=2 foldmethod=indent
autocmd BufRead *.svelte setl shiftwidth=2 tabstop=2 foldmethod=indent
autocmd BufRead *.py setl foldmethod=indent
autocmd BufRead *.rs setl foldmethod=syntax
autocmd BufRead *.sh setl shiftwidth=4 tabstop=4 foldmethod=indent makeprg=shellcheck\ -f\ gcc\ % noexpandtab
autocmd BufRead *.tex setl nowrap
autocmd BufRead *.yaml setl shiftwidth=2 tabstop=2 foldmethod=indent
autocmd BufRead *.yml setl shiftwidth=2 tabstop=2 foldmethod=indent
" Project-specific
autocmd BufRead ~/git/wikijump*/*/templates/*.tpl setl noexpandtab
" Secure editing of passwords with 'pass'
autocmd BufReadPre,FileReadPre /dev/shm/pass.*.txt set viminfo=
autocmd BufReadPre,FileReadPre /dev/shm/pass.*.txt set noswapfile noundofile nobackup
" Transparent GPG Encryption
augroup gpg_encrypted
au!
" Disable options that write the plaintext to disk
autocmd BufReadPre,FileReadPre *.gpg set viminfo=
autocmd BufReadPre,FileReadPre *.gpg set noswapfile noundofile nobackup
" Switch to binary mode
autocmd BufReadPre,FileReadPre *.gpg set bin
autocmd BufReadPre,FileReadPre *.gpg let ch_save = &ch|set ch=2
autocmd BufReadPost,FileReadPost *.gpg '[,']!gpg --decrypt 2> /dev/null
" Switch to normal mode for editing
autocmd BufReadPost,FileReadPost *.gpg set nobin
autocmd BufReadPost,FileReadPost *.gpg let &ch = ch_save|unlet ch_save
autocmd BufReadPost,FileReadPost *.gpg execute ":doautocmd BufReadPost " . expand("%:r")
" Encrypt all text before writing
autocmd BufWritePre,FileWritePre *.gpg '[,']!gpg --default-recipient-self -ae 2> /dev/null
" Undo the encryption so we can edit again
autocmd BufWritePost,FileWritePost *.gpg u
augroup END
" }}}
" vim: set ts=2 sw=2 fdm=marker foldlevel=0: