-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvimrc
416 lines (313 loc) · 8.57 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
"""""""""""
" Plugins "
"""""""""""
" Autoinstall vim-plug
if empty(glob('~/.vim/autoload/plug.vim')) && confirm("Install vim-plug??","Y\nn") == 1
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Plugins
call plug#begin('~/.vim/plugged')
Plug 'jamessan/vim-gnupg'
Plug 'roman/golden-ratio'
Plug 'othree/html5.vim'
Plug 'hail2u/vim-css3-syntax'
Plug 'ledger/vim-ledger'
Plug 'dhruvasagar/vim-table-mode'
Plug 'fnune/base16-vim'
Plug 'hynek/vim-python-pep8-indent'
Plug 'tpope/vim-surround'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'morhetz/gruvbox'
Plug 'junegunn/fzf.vim'
call plug#end()
"""""""""""
" General "
"""""""""""
" Make Vim more useful, but less Vi compatible
set nocompatible
" Make backspace work like other apps
set backspace=2
" Display cursor position
set ruler
" Show the status line
set laststatus=2
" Automatically save before commands like :next and :make
set autowrite
" Show the editor mode
set showmode
" Show state of keyboard input
set showcmd
" Allow mouse (is this sacrilege?)
set mouse=a
" Show whitespace characters
set list
" Use wildmenu for command line tab completion
set wildmenu
set wildmode=list:longest,full
" Underline the current line
set cursorline
" Allow modified buffers to go to the background
set hidden
" The TTY is fast
set ttyfast
" Set the minimum number of lines to keep above and below cursor
set scrolloff=5
""""""""""""""""
" Line Numbers "
""""""""""""""""
" Default to absolute line numbers.
set nu
""""""""
" Tabs "
""""""""
" Tabs should be 4-spaces
set tabstop=4
set shiftwidth=4
" Use spaces instead of tabs
set expandtab
" Show > for tab
set listchars=tab:>-
" 4 spaces is a tab, so backspace will work properly
set softtabstop=4
" Follow line indentation
set autoindent
""""""""""
" Search "
""""""""""
" Turn on search highlighting
set hlsearch
" Ignore case in searches -- but be smart!
set ignorecase
set smartcase
" Start searching as the characters are typed
set incsearch
"""""""""""
" Folding "
"""""""""""
" Auto-fold by indentation.
"set foldmethod=indent
" Limit nested folds.
"set foldnestmax=10
" Unfold folds by default.
"set nofoldenable
"set foldlevel=2
"""""""""""""""""""""
" Keyboard Shorcuts "
"""""""""""""""""""""
" Remap colon to semicolon.
nnoremap ; :
" Toggle folds with space.
nnoremap <Space> za
vnoremap <Space> za
" Redraw syntax highlighting from start of file.
nnoremap U :syntax sync fromstart<cr>:redraw!<cr>
" Disable arrow keys. Force use of <hjkl>. (Oh noes!)
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
" Move by screen line rather than file line (for wrapping).
nnoremap j gj
nnoremap k gk
" Set smooth scrolling
:map <C-U> <C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y>
:map <C-D> <C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E>
" Move between windows with CTRL and navigation keys.
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
" Switch between windows with <Leader><number>
let i = 1
while i <= 9
execute 'nnoremap <Leader>' . i . ' :' . i . 'wincmd w<CR>'
let i = i + 1
endwhile
" Disable search highlighting (<leader><space>)
nnoremap <leader><space> :noh<cr>
" Open a new tab (Ctrl+t)
nnoremap <C-t> :tabnew
" Toggle paste mode
set pastetoggle=<leader>p
" Write a file with sudo (w!!)
cmap w!! w !sudo tee % >/dev/null
" Escape (kj)
inoremap kj <Esc>
" Toggle relative line numbers (Ctrl+n)
function! g:ToggleNuMode()
if &nu == 1
set rnu
else
set nu
endif
endfunction
nnoremap <silent><C-n> :call g:ToggleNuMode()<cr>
" Paste from system clipboard in insert mode (Ctrl+v)
imap <C-V> <ESC>"+gpa
" Yank WORD to system clipboard in normal mode
nmap <leader>y "+yE
" Yank selection to system clipboard in visual mode
vmap <leader>y "+y
" Spell check
map <leader>s :setlocal spell! spelllang=en_us<cr>
" Open fzf file finder
map <leader>o :Files<cr>
" Buffer navigation
map [b :bprevious<cr>
map ]b :bnext<cr>
map <leader>b :buffers<cr>
" Insert date with cdate
:iab cdate <c-r>=strftime("%Y-%m-%d")<CR>
" Insert datetime with ctime
:iab ctime <c-r>=strftime("%Y-%m-%d %H:%M:%SZ%z")<CR>
" Move tabs left or right
map <leader>[ :tabmove-1<CR>
map <leader>] :tabmove+1<CR>
"""""""""""
" Styling "
"""""""""""
" Colorscheme
if filereadable(expand("~/.vimrc_background"))
let base16colorspace=256
source ~/.vimrc_background
else
colorscheme gruvbox
set background=dark
endif
" Syntax highlighting
syntax enable
" Spell check
highlight clear SpellBad
highlight SpellBad term=standout ctermfg=1 term=underline cterm=underline
highlight clear SpellCap
highlight SpellCap ctermfg=44 term=underline cterm=underline
highlight clear SpellRare
highlight SpellRare ctermfg=44 term=underline cterm=underline
highlight clear SpellLocal
highlight SpellLocal ctermfg=44 term=underline cterm=underline
" Default gVim window size and font.
if has("gui_running")
set lines=50 columns=100
set guifont=PragmataPro\ Mono\ Liga\ 12
endif
""""""""""""""""""""
" GnuPG Extensions "
""""""""""""""""""""
" Tell the GnuPG plugin to armor new files.
let g:GPGPreferArmor=1
" Tell the GnuPG plugin to sign new files.
let g:GPGPreferSign=1
augroup GnuPGExtra
" Set extra file options.
autocmd BufReadCmd,FileReadCmd *.\(gpg\|asc\|pgp\) call SetGPGOptions()
" Automatically close unmodified files after inactivity.
autocmd CursorHold *.\(gpg\|asc\|pgp\) quit
augroup END
function SetGPGOptions()
" Set updatetime to 1 minute.
set updatetime=60000
" Fold at markers.
set foldmethod=marker
" Automatically close all folds.
set foldclose=all
" Only open folds with insert commands.
set foldopen=insert
endfunction
""""""""
" Mutt "
""""""""
" Set the filetype on neomutt buffers
au BufRead /tmp/*mutt* setfiletype mail
" Delete quoted signatures.
au BufRead /tmp/*mutt* normal :g/^\(> \)--\s*$/,/^$/-1d/^$
"""""""""""""""""""
" Temporary Files "
"""""""""""""""""""
" https://gist.github.com/tejr/5890634
" Don't backup files in temp directories or shm
if exists('&backupskip')
set backupskip+=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*
endif
" Don't keep swap files in temp directories or shm
if has('autocmd')
augroup swapskip
autocmd!
silent! autocmd BufNewFile,BufReadPre
\ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*
\ setlocal noswapfile
augroup END
endif
" Don't keep undo files in temp directories or shm
if has('persistent_undo') && has('autocmd')
augroup undoskip
autocmd!
silent! autocmd BufWritePre
\ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*
\ setlocal noundofile
augroup END
endif
" Don't keep viminfo for files in temp directories or shm
if has('viminfo')
if has('autocmd')
augroup viminfoskip
autocmd!
silent! autocmd BufNewFile,BufReadPre
\ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*
\ setlocal viminfo=
augroup END
endif
endif
""""""""
" Pass "
""""""""
augroup passconceal
autocmd!
" Create the second line if it does not already exist
autocmd BufNewFile,BufRead */pass.*/* if line('$') == 1 | $put _ | endif
" Jump to the second line
autocmd BufNewFile,BufRead */pass.*/* 2
" Conceal the first line with an asterisk
autocmd BufNewFile,BufRead */pass.*/* syntax match Concealed '\%1l.*' conceal cchar=*
autocmd BufNewFile,BufRead */pass.*/* set conceallevel=1
augroup END
""""""""
" Goyo "
""""""""
nnoremap <silent> <leader>z :Goyo<cr>
autocmd! User GoyoEnter Limelight
autocmd! User GoyoLeave Limelight!
function! s:goyo_enter()
let b:quitting = 0
let b:quitting_bang = 0
autocmd QuitPre <buffer> let b:quitting = 1
cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
set linebreak
set scrolloff=999
Limelight
endfunction
function! s:goyo_leave()
" Quit Vim if this is the only remaining buffer
if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
if b:quitting_bang
qa!
else
qa
endif
endif
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave call <SID>goyo_leave()
""""""""""""
" Markdown "
""""""""""""
" Prefer pythonic folding
let g:vim_markdown_folding_style_pythonic = 1