-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.vim
420 lines (331 loc) · 10.6 KB
/
init.vim
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
" dotvim
" A fresh take on my Vim/Neovim setup.
set nocompatible
set mouse=a
set virtualedit=onemore
" Stuff copied from vim-sensible {{
if has('autocmd')
filetype plugin indent on
endif
if has('syntax') && !exists('g:syntax_on')
syntax enable
endif
" Use :help 'option' to see the documentation for the given option.
" (Single quotes ensures :help finds the option.)
set autoindent
set backspace=indent,eol,start
set complete=.,w,b,u,t,i
set smarttab
set nrformats-=octal
set ttimeout
set ttimeoutlen=100
set incsearch
" Use <C-L> to toggle the highlighting of :set hlsearch.
if maparg('<C-L', 'n') ==# ''
nnoremap <silent> <C-L> :set invhlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
endif
set laststatus=2
set ruler
set viewoptions=folds,options,cursor
" Better Unix compatibility on Windows
set viewoptions+=unix
" Neovim defaults to block cursor, I don't like it
set guicursor=
set scrolloff=1 scrolljump=1
set sidescrolloff=5
set display=lastline
set nosplitright splitbelow
if v:version > 703 || v:version == 703 && has("patch541")
set formatoptions+=j " Delete comment character when joining commented lines
endif
set autoread
set history=1000
if !empty(&viminfo)
set viminfo^=!
endif
set noswapfile
set sessionoptions-=options
" Allow color schemes to do bright colors without forcing bold.
if &t_Co == 8 && $TERM !~# '^linux\|^Eterm'
set t_Co=16
endif
" Load matchit.vim, but only if the user hasn't installed a newer version.
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
runtime! macros/matchit.vim
endif
" }}
" Abbreviate messages, and hide the intro
set shortmess+=aoOtTI
if has('persistent_undo')
set undofile
set undolevels=1000
set undoreload=10000
" Neovim sets undodir to e.g. ~/.local/share/nvim/undo by default,
" which is nice since it won't conflict with Vim if/when I swap back
" and forth.
if !has('nvim')
let &undodir=$HOME . '/.vimundo'
endif
endif
" set spell
set hidden
set switchbuf=useopen
set list
" TODO
set listchars=tab:,\
set number
set noshowmatch " This just slows down typing if it's on.
set ignorecase
set smartcase
set wildmode=list:longest,full
set whichwrap=b,s,h,l,<,>,[,]
" Default indentation settings. Wow, so PEP-8.
" if 1 " TODO: Do this based on filetype...
setl tabstop=4
setl shiftwidth=4
setl softtabstop=4
" else
" set tabstop=2 shiftwidth=2 softtabstop=2
" endif
set expandtab
set shiftround
set colorcolumn=80
set noshowmode " This is what zipline is for
" Key mappings {
" Escape is annoying to hit.
inoremap jk <Esc>
" And I've become rather addicted to just hitting q to cancel everything...
" ... plus, nobody starts a macro while in visual mode... right?
vnoremap q <Esc>
" Stupid shift-key fixes
if has("user_commands")
command! -bang -nargs=* -complete=file E e<bang> <args>
command! -bang -nargs=* -complete=file W w<bang> <args>
command! -bang -nargs=* -complete=file Wq wq<bang> <args>
command! -bang -nargs=* -complete=file WQ wq<bang> <args>
command! -bang Wa wa<bang>
command! -bang WA wa<bang>
command! -bang Q q<bang>
command! -bang Qa qa<bang>
command! -bang QA qa<bang>
command! Bn bn
command! BN bn
command! Bp bp
command! BP bp
endif
let g:mapleader = ','
nmap <silent> <Leader>/ :set invhlsearch<CR>
" I seem to have a habit of hitting q and then leader...
nmap <silent> q, ,
" and q:. Who even uses Ex mode, I mean come on.
nnoremap <silent> q: :
" Jump to merge conflict markers.
map <leader>fc /\v^[<\|=>]{7}( .*\|$)<CR>
" Go back to visual mode after indent change.
vnoremap < <gv
vnoremap > >gv
" Allow repeat operator to work on visual selection.
" http://stackoverflow.com/a/8064607/127816
vnoremap . :normal .<CR>
" Delete to black hole register with <leader>d
nnoremap <leader>d "_dd
vnoremap <leader>d "_d
" Save some effort on having to push Shift for commands...
nnoremap ; :
" I have literally never used Ex mode. Make Q a bit more useful.
nnoremap Q @@
" vim-dirvish takes over -, but now that I know about what + does, I would
" sort of like the functionality of - (minus)! But I don't need what _
" provides, so let's override that.
noremap _ -
" switch.vim
nnoremap <silent> <BS> :Switch<CR>
" Pressing # on a visual selection will wrap it with #if/endif and leave the
" cursor after the '#if '
vnoremap # <Esc>'>o#endif<C-o>'<<C-o>O#if
" }
" Switch to current file directory automatically
autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" |
\ execute 'lcd ' . escape(fnamemodify(resolve(expand('%:p')), ':h'), ' ') |
\ endif
" TODO: cscope {
" }
" Omnicompletion {
if has("autocmd") && exists("+omnifunc")
autocmd Filetype *
\if &omnifunc == "" |
\setlocal omnifunc=syntaxcomplete#Complete |
\endif
endif
hi Pmenu ctermfg=black ctermbg=lightgray
"hi PmenuSbar ctermfg=darkcyan ctermbg=lightgray
"hi PmenuThumb ctermfg=lightgray ctermbg=darkgray
" Automatically open/close the popup menu.
augroup omnicomplete
autocmd!
autocmd CursorMovedI,InsertLeave * if pumvisible() == 0 | silent! pclose | endif
augroup END
set completeopt=menu,preview,longest
function! s:CompleteMap(key,mapping)
execute printf('inoremap <expr> %s pumvisible() ? "%s" : "%s"', a:key, a:mapping, a:key)
endfunction
" if 0
" " Doesn't work...
" call s:CompleteMap('<Esc>', '<C-e>')
" call s:CompleteMap('<CR>', '<C-y>')
" call s:CompleteMap('<Down>', '<C-n>')
" call s:CompleteMap('<Up>', '<C-p>')
" endif
" }
" TODO: neocomplete
" neovim-specific stuff {{
if exists('&inccommand')
" Live substitution. Do it in a split window with all the changing lines.
" Super cool.
set inccommand=split
endif
" }}
" Plugins! {{
set background=dark
let s:dotvim_path = fnamemodify(resolve(expand('<sfile>:p')), ':h')
function! DotvimPath()
return s:dotvim_path
endfunction
function! LoadDotvimFile(name)
let l:fpath = s:dotvim_path . '/' . a:name
if filereadable(l:fpath)
execute "source " . l:fpath
" else
" echo "not readable: " . l:fpath
endif
endfunction
" If there's a preplug.work.vim file, load it first. Lets us make settings for
" plugins, etc.
call LoadDotvimFile('preplug.work.vim')
call LoadDotvimFile('preplug.local.vim')
" Find the plugins.vim alongside this init.vim file!
call LoadDotvimFile('plugins.vim')
" }}
" Colorscheme {{
" Disable Background Color Erase, per http://superuser.com/a/562423
set t_ut=
let g:solarized_termcolors=256
let g:solarized_termtrans = 0
let g:solarized_contrast="high"
let g:solarized_italics = 0
try
set background=dark
" colorscheme solarized
set termguicolors
colorscheme solarized8
catch /E185:/
echo "solarized colorscheme not found, let's do a PlugInstall"
PlugInstall
colorscheme solarized8
endtry
" hi LineNR ctermbg=NONE ctermfg=237
hi VertSplit ctermbg=236 ctermfg=236 guibg=#262626 guifg=#262626
" Make listchars tab more visible
hi Whitespace ctermbg=237 guibg=#363636
hi! link SpecialKey Whitespace
hi Normal guibg=#1c1c1c
hi ColorColumn ctermbg=236 guibg=#262626
hi LineNr guibg=#262626
" The following content provided by:
" howivim airblade
hi clear StatusLine
hi clear StatusLineNC
" hi StatusLine term=bold cterm=bold ctermfg=White ctermbg=235
hi User1 ctermfg=4 guifg=#40ffff " Identifier
hi User2 ctermfg=2 gui=bold guifg=#ffff60 " Statement
hi User3 term=bold cterm=bold ctermfg=1 guifg=White guibg=Red " Error
hi User4 ctermfg=1 guifg=Orange " Special
hi User5 ctermfg=10 guifg=#80a0ff " Comment
hi User6 term=bold cterm=bold ctermfg=1 guifg=Red " WarningMsg
set laststatus=2
if has('signs')
hi SignColumn ctermbg=235 guibg=#262626
endif
" My own personal statusline 'plugin'
call LoadDotvimFile('zipline.vim')
" }}
" Filetypes {
" 99% of my C++ use (at work) is in unit tests, and scanning the includes
" there can take a second or two each time. Don't do this.
autocmd! Filetype cpp setlocal complete-=i
autocmd! Filetype cpp,html,xml let b:AutoPairs = extend({'<': '>'}, g:AutoPairs, 'keep')
autocmd! Filetype vim setl ts=2 sw=2 sts=2
autocmd! Filetype help setl colorcolumn=0
" }
" TODO total hack
augroup mikeInitReload
autocmd!
" After each write to this init.vim file, source it.
execute printf('autocmd! BufWritePost %s source %%', resolve(expand('<sfile>:p')))
augroup END
augroup restoreCursor
autocmd!
autocmd! BufWinEnter *
\ if &filetype != "netrw" && line("'\"") > 1 && line("'\"") <= line("$") |
\ execute 'normal! g`"' |
\ endif
augroup END
" scriptease-lite {
" TODO: figure out what to do with this
function! s:get_visual_selection()
let sel_save = &selection
let cb_save = &clipboard
let reg_save = @@
try
set selection=inclusive clipboard-=unnamed clipboard-=unnamedplus
silent exe "normal! gvy"
redraw
let foo = substitute(@@, '\v\C\n%(\s*\\)=', '', 'g')
let b:vis = foo
return foo
finally
let @@ = reg_save
let &selection = sel_save
let &clipboard = cb_save
endtry
endfunction
" Scan current line and up for any continuation lines,
" then down, joining continuations. Returns full string.
function! s:grab_code_here()
let l:curline = line('.')
let l:continuation = '\v\C^%(\s*\\)'
while l:curline > -1 && (match(getline(l:curline), l:continuation) != -1)
let l:curline -= 1
endwhile
if l:curline <= 1
echoerr "grab_code_here(): got to top of file!"
return ""
endif
let l:content = getline(l:curline)
let l:curline += 1
while l:curline <= line('$')
let l:line = getline(l:curline)
if -1 == match(l:line, l:continuation)
break
else
let l:content .= substitute(getline(l:curline), l:continuation, '', 'g')
let l:curline += 1
endif
endwhile
" let b:code = l:content
echom l:content
return l:content
endfunction
" xnoremap <silent> gz :<C-U>call <SID>get_visual_selection()<CR>
" Execute the line of vimscript under the cursor (as found by scanning for
" continuations) -- intended for use when hacking on statusline format.
autocmd Filetype vim nnoremap <buffer> <silent> gz :execute <SID>grab_code_here()<CR>
" }
if filereadable(expand('~/.vimrc.digi'))
source ~/.vimrc.digi
endif
if has('nvim')
let &runtimepath = s:dotvim_path . ',' . &runtimepath
lua require 'dotvim'
endif
" vim: set ft=vim et sw=2 ts=2 sts=2: