-
Notifications
You must be signed in to change notification settings - Fork 13
/
.vimrc
313 lines (261 loc) · 11.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
" Eevee's vimrc
" vim mode preferred!
set nocompatible
" set xterm title, and inform vim of screen/tmux's syntax for doing the same
set titlestring=vim\ %{expand(\"%t\")}
if &term =~ "^screen"
" pretend this is xterm. it probably is anyway, but if term is left as
" `screen`, vim doesn't understand ctrl-arrow.
if &term == "screen-256color"
set term=xterm-256color
else
set term=xterm
endif
" gotta set these *last*, since `set term` resets everything
set t_ts=k
set t_fs=\
endif
set title
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" backups and other junky files
set backupdir=~/.vim/backup " get backups outta here
set directory=~/.vim/swap " get swapfiles outta here
set writebackup " temp backup during write
set undodir=~/.vim/undo " persistent undo storage
set undofile " persistent undo on
" user interface
set history=1000 " remember command mode history
set laststatus=2 " always show status line
set lazyredraw " don't update screen inside macros, etc
set matchtime=2 " ms to show the matching paren for showmatch
set number " line numbers
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set showmatch " show matching brackets while typing
set relativenumber " line numbers spread out from 0
set cursorline " highlight current line
set display=lastline,uhex " show last line even if too long; use <xx>
" regexes
set incsearch " do incremental searching
set ignorecase " useful more often than not
set smartcase " case-sens when capital letters
set gdefault " s///g by default
" whitespace
set autoindent " keep indenting on <CR>
set shiftwidth=4 " one tab = four spaces (autoindent)
set softtabstop=4 " one tab = four spaces (tab key)
set expandtab " never use hard tabs
set shiftround " only indent to multiples of shiftwidth
set smarttab " DTRT when shiftwidth/softtabstop diverge
set fileformats=unix,dos " unix linebreaks in new files please
set listchars=tab:↹·,extends:⇉,precedes:⇇,nbsp:␠,trail:␠,nbsp:␣
" appearance of invisible characters
set formatoptions=crqlj " wrap comments, never autowrap long lines
" Normally I would say tabstop is always 8, because tabs are 8, by definition.
" However, I have vim-sleuth installed, which forces tabstop to 8 when files
" are NOT indented with tabs -- so this is really only used for files that
" indent with tabs, the only place I actually want to use 4.
set tabstop=4
" wrapping
"set colorcolumn=+1 " highlight 81st column
set linebreak " break on what looks like boundaries
set showbreak=↳\ " shown at the start of a wrapped line
"set textwidth=80 " wrap after 80 columns
set virtualedit=block " allow moving visual block into the void
" gui stuff
set ttymouse=xterm2 " force mouse support for screen
set mouse=a " terminal mouse when possible
set guifont=Source\ Code\ Pro\ 9
" nice fixedwidth font
" unicode
set encoding=utf-8 " best default encoding
setglobal fileencoding=utf-8 " ...
set nobomb " do not write utf-8 BOM!
set fileencodings=ucs-bom,utf-8,iso-8859-1
" order to detect Unicodeyness
" tab completion
set wildmenu " show a menu of completions like zsh
set wildmode=full " complete longest common prefix first
set wildignore+=.*.sw*,__pycache__,*.pyc
" ignore junk files
set complete-=i " don't try to tab-complete #included files
set completeopt-=preview " preview window is super annoying
" miscellany
set scrolloff=2 " always have 2 lines of context on the screen
set foldmethod=indent " auto-fold based on indentation. (py-friendly)
set foldlevel=99
set timeoutlen=1000 " wait 1s for mappings to finish
set ttimeoutlen=100 " wait 0.1s for xterm keycodes to finish
set nrformats-=octal " don't try to auto-increment 'octal'
set autoread " reload changed files
" NOTE: 'autoread' seems to not check for changes very often; mostly after
" doing a shell command and when focus is /lost/. (My reading of the source
" code suggests it ought to happen during a buffer switch, but vim in practice
" disagrees?) Even the 'focus lost' check — a strange choice — doesn't
" actually work in a terminal!
" So I use tmux's focus-events setting, the tmux-focus-events plugin, AND the
" following autocommands to check for changes when gaining focus (from tmux's
" point of view), when entering a buffer, and when idling.
autocmd FocusGained * if mode() != 'c' | checktime | endif
autocmd BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | execute 'checktime' expand("<abuf>") | endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins
" Pathogen; load all bundles
call pathogen#infect()
" Denite (searcher for files in the current dir, but also ag, buffers, ...)
" Most of this comes straight from the documentation.
" Use up/down to browse the suggestions
" TODO i wish there were a "post-search" mode? is that what normal mode is?
call denite#custom#map('insert', '<Down>', '<denite:move_to_next_line>', 'noremap')
call denite#custom#map('insert', '<Up>', '<denite:move_to_previous_line>', 'noremap')
" TODO: cpsm? ctrlp-based very fast file matching
"call denite#custom#source( 'file_mru', 'matchers', ['matcher_fuzzy', 'matcher_project_files'])
call denite#custom#option('default', 'prompt', '» ')
call denite#custom#option('default', 'auto_resize', v:true)
if executable('rg')
call denite#custom#var('file_rec', 'command', ['rg', '--files', '--glob', '!.git'])
call denite#custom#var('grep', 'command', ['rg'])
call denite#custom#var('grep', 'default_opts', ['--vimgrep', '--no-heading'])
call denite#custom#var('grep', 'recursive_opts', [])
call denite#custom#var('grep', 'pattern_opt', ['--regexp'])
call denite#custom#var('grep', 'separator', ['--'])
call denite#custom#var('grep', 'final_opts', [])
elseif executable('ag')
call denite#custom#var('file_rec', 'command', ['ag', '--follow', '--nocolor', '--nogroup', '-g', ''])
call denite#custom#var('grep', 'command', ['ag'])
call denite#custom#var('grep', 'default_opts', ['-i', '--vimgrep'])
call denite#custom#var('grep', 'recursive_opts', [])
call denite#custom#var('grep', 'pattern_opt', [])
call denite#custom#var('grep', 'separator', ['--'])
call denite#custom#var('grep', 'final_opts', [])
endif
" TODO mappings for file_mru? buffers?
nnoremap <silent> <c-p> :Denite file_rec<cr>
nnoremap <silent> g/ :Denite grep<cr>
" YouCompleteMe
" Search PATH to find the right Python, so that it works in a Python 2 venv
let g:ycm_python_binary_path = 'python'
" ALE (linter)
" Only use flake8 for Python, because pylint is huge and impossible to appease
let g:ale_linters = {
\ 'python': ['flake8'],
\}
" Stupid Unicode tricks
let g:ale_sign_info = "🚩"
let g:ale_sign_warning = "🚨"
let g:ale_sign_error = "💥"
let g:ale_sign_style_warning = "💈" " get it? /style/ issues? wow tough crowd
let g:ale_sign_style_error = "🚨"
" Airline; use powerline-style glyphs and colors
let g:airline_powerline_fonts = 1
" ALE
let g:airline#extensions#ale#error_symbol = "🚨"
let g:airline#extensions#ale#warning_symbol = "🚩"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Bindings
" Stuff that clobbers default bindings
" Force ^U and ^W in insert mode to start a new undo group
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
" Leader
let mapleader = ","
let g:mapleader = ","
" Swaps selection with buffer
vnoremap <C-X> <Esc>`.``gvP``P
" ctrl-arrow in normal mode to switch windows; overrides ctrl-left/right for
" moving by words, but i tend to use those only in insert mode
noremap <C-Left> <C-W><Left>
noremap <C-Right> <C-W><Right>
noremap <C-Up> <C-W><Up>
noremap <C-Down> <C-W><Down>
" -/= to navigate tabs
nnoremap - :tabprevious<CR>
nnoremap = :tabnext<CR>
" Bind gb to toggle between the last two tabs
map gb :exe "tabn ".g:ltv<CR>
function! Setlasttabpagevisited()
let g:ltv = tabpagenr()
endfunction
augroup localtl
autocmd!
autocmd TabLeave * call Setlasttabpagevisited()
augroup END
autocmd VimEnter * let g:ltv = 1
" Abbreviation to make `:e %%/...` edit in same directory
cabbr <expr> %% expand('%:.:h')
""" For plugins
" gundo
noremap ,u :GundoToggle<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Miscellaneous autocmds
" Automatically delete swapfiles older than the actual file.
" Look at this travesty. vim already has this information but doesn't expose
" it, so I have to reparse the swap file. Ugh.
function! s:SwapDecide()
python << endpython
import os
import struct
import vim
# Format borrowed from:
# https://github.com/nyarly/Vimrc/blob/master/swapfile_parse.rb
SWAPFILE_HEADER = "=BB10sLLLL40s40s898scc"
size = struct.calcsize(SWAPFILE_HEADER)
with open(vim.eval('v:swapname'), 'rb') as f:
buf = f.read(size)
(
id0, id1, vim_version, pagesize, writetime,
inode, pid, uid, host, filename, flags, dirty
) = struct.unpack(SWAPFILE_HEADER, buf)
try:
# Test whether the pid still exists. Could get fancy and check its name
# or owning uid but :effort:
os.kill(pid, 0)
except OSError:
# NUL means clean, \x55 (U) means dirty. Yeah I don't know either.
if dirty == b'\x00':
# Appears to be from a crash, so just nuke it
vim.command('let v:swapchoice = "d"')
endpython
endfunction
if has("python")
augroup eevee_swapfile
autocmd!
autocmd SwapExists * call s:SwapDecide()
augroup END
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Colors and syntax
" in GUI or color console, enable coloring and search highlighting
if &t_Co > 2 || has("gui_running")
syntax enable
set background=dark
set hlsearch
endif
set t_Co=256 " force 256 colors
colorscheme molokai
if has("autocmd")
" Filetypes and indenting settings
filetype plugin indent on
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif " has("autocmd")
" trailing whitespace and column; must define AFTER colorscheme, setf, etc!
hi ColorColumn ctermbg=black guibg=darkgray
hi WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+\%#\@<!$/
" molokai's diff coloring is terrible
highlight DiffAdd ctermbg=22
highlight DiffDelete ctermbg=52
highlight DiffChange ctermbg=17
highlight DiffText ctermbg=53
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Last but not least, allow for local overrides
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif