aboutsummaryrefslogtreecommitdiff
path: root/vim/vimrc
blob: 1d5518353a5e16d9fcacf8c78dde16e45233945c (plain) (blame)
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
if !exists('$LANG') && &encoding ==# 'latin1'
  set encoding=utf-8
endif
scriptencoding utf-8
function! s:OptionSplit(string) abort
  return map(
        \ split(&runtimepath, '\\\@<!,[, ]*'),
        \ 'substitute(v:val, ''\\,'', '','', ''g'')',
        \)
endfunction
if exists('$MYVIM')
  execute 'set runtimepath^='.s:EscItemExec($MYVIM)
else
  let s:runtimepath = s:OptionSplit(&runtimepath)
  let $MYVIM = s:runtimepath[0]
endif
let s:cache = $MYVIM.'/cache'
if !isdirectory(s:cache)
  call mkdir(s:cache, 'p', 0700)
endif
let &viminfo .= ',n'.s:cache.'/viminfo'
set backup
let s:backupdir = s:cache.'/backup'
if !isdirectory(s:backupdir)
  call mkdir(s:backupdir, 'p', 0700)
endif
execute 'set backupdir^='.escape(escape(
      \ s:backupdir.(has('patch-8.1.251') ? '//' : ''),
      \ ','), '\ %#|"')
if has('unix')
  if !has('patch-8.1.1519')
    set backupskip&
  endif
  set backupskip^=/dev/shm/*,/usr/tmp/*,/var/tmp/*
endif
let s:directory = s:cache.'/swap'
if !isdirectory(s:directory)
  call mkdir(s:directory, 'p', 0700)
endif
execute 'set directory^='.escape(escape(
      \ s:directory,
      \ ','), '\ %#|"')
if has('persistent_undo')
  set undofile
  let s:undodir = s:cache.'/undo'
  if !isdirectory(s:undodir)
    call mkdir(s:undodir, 'p', 0700)
  endif
  execute 'set undodir^='.escape(escape(
        \ s:undodir,
        \ ','), '\ %#|"')
endif
filetype plugin indent on
function! s:ReloadFileType() abort
  if exists('g:did_load_filetypes')
    doautocmd filetypedetect BufRead
  endif
endfunction
command! -bar ReloadFileType
      \ call s:ReloadFileType()
function! s:ReloadVimrc() abort
  ReloadFileType
  redraw
  echomsg fnamemodify($MYVIMRC, ':p:~').' reloaded'
endfunction
command! -bar ReloadVimrc
      \ noautocmd source $MYVIMRC | call s:ReloadVimrc()
augroup vimrc
  autocmd!
augroup END
autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc
      \ ReloadVimrc
if exists('##SourceCmd')
  autocmd vimrc SourceCmd $MYVIMRC,$MYVIM/vimrc
        \ ReloadVimrc
endif
set history=10000
set spelllang=en_nz
let s:spellfile = s:cache.'/spell/'.join([
      \ split(&spelllang, '_')[0],
      \ &encoding,
      \ 'add',
      \], '.')
execute 'set spellfile='.escape(escape(
      \ s:spellfile,
      \ ','), '\ %#|"')
let &spellcapcheck = '[.?!]\%(  \|[\n\r\t]\)'
set dictionary^=/usr/share/dict/words
let s:ref = $MYVIM.'/ref'
let s:dictionary = s:ref.'/dictionary.txt'
execute 'set dictionary^='.escape(escape(
      \ s:dictionary,
      \ ','), '\ %#|"')
let s:thesaurus = s:ref.'/thesaurus.txt'
execute 'set thesaurus^='.escape(escape(
      \ s:thesaurus,
      \ ','), '\ %#|"')
set comments= commentstring= define= include=
set path-=/usr/include
set autoindent
set expandtab
set shiftwidth=4
set smarttab
if v:version > 703 || v:version == 703 && has('patch693')
  set softtabstop=-1
else
  let &softtabstop = &shiftwidth
endif
set backspace+=eol
set backspace+=indent
set backspace+=start
set linebreak
if has('multi_byte_encoding')
  set showbreak=else
  set showbreak=...
endif
if exists('+breakindent')
  set breakindent
endif
set confirm
set noesckeys
set formatoptions+=l
set formatoptions+=1
if v:version > 703 || v:version == 703 && has('patch541')
  set formatoptions+=j
endif
set cpoptions+=J
if has('patch-8.1.728')
  set formatoptions+=p
endif
if has('gui_running')
  set guioptions+=M
endif
set hidden
set hlsearch
nohlsearch
set incsearch
set lazyredraw
set listchars+=tab:>-
set listchars+=trail:-
set listchars+=nbsp:+
if has('multi_byte_encoding')
  set listchars+=extends:»,precedes:«
else
  set listchars+=extends:>,precedes:<
endif
set nomodeline
set nrformats-=octal
set noruler
set sessionoptions-=localoptions
set sessionoptions-=options
set noshowcmd
set shortmess+=I
if !&loadplugins || globpath(&runtimepath, 'plugin/matchparen.vim') ==# ''
  set showmatch matchtime=3
endif
set splitbelow splitright
set synmaxcol=500
if &term =~# '^putty\|^tmux'
  set ttyfast
endif
set ttymouse=
set virtualedit+=block
set visualbell t_vb=
set wildmenu
set wildmode=list:longest,full
set wildignore=*~,#*#
      \,*.7z
      \,.DS_Store
      \,.git
      \,.hg
      \,.svn
      \,*.a
      \,*.adf
      \,*.asc
      \,*.au
      \,*.aup
      \,*.avi
      \,*.bin
      \,*.bmp
      \,*.bz2
      \,*.class
      \,*.db
      \,*.dbm
      \,*.djvu
      \,*.docx
      \,*.exe
      \,*.filepart
      \,*.flac
      \,*.gd2
      \,*.gif
      \,*.gifv
      \,*.gmo
      \,*.gpg
      \,*.gz
      \,*.hdf
      \,*.ico
      \,*.iso
      \,*.jar
      \,*.jpeg
      \,*.jpg
      \,*.m4a
      \,*.mid
      \,*.mp3
      \,*.mp4
      \,*.o
      \,*.odp
      \,*.ods
      \,*.odt
      \,*.ogg
      \,*.ogv
      \,*.opus
      \,*.pbm
      \,*.pdf
      \,*.png
      \,*.ppt
      \,*.psd
      \,*.pyc
      \,*.rar
      \,*.rm
      \,*.s3m
      \,*.sdbm
      \,*.sqlite
      \,*.swf
      \,*.swp
      \,*.tar
      \,*.tga
      \,*.ttf
      \,*.wav
      \,*.webm
      \,*.xbm
      \,*.xcf
      \,*.xls
      \,*.xlsx
      \,*.xpm
      \,*.xz
      \,*.zip
if exists('+wildignorecase')
  set wildignorecase
endif
if !exists('syntax_on')
  syntax enable
endif
autocmd vimrc ColorScheme *
      \ let &cursorline = g:colors_name ==# 'sahara'
if !exists('$COLORFGBG') && get(v:, 'termrbgresp', '') ==# ''
  set background=dark
endif
if &background ==# 'dark'
      \ && (has('gui_running') || &t_Co >= 256)
      \ && globpath(&runtimepath, 'colors/sahara.vim') !=# ''
  colorscheme sahara
endif
nnoremap <Backspace> <C-^>
nnoremap <expr> <Space>
      \ line('w$') < line('$')
      \ ? "\<PageDown>"
      \ : ":\<C-U>next\<CR>"
if &loadplugins && globpath(&runtimepath, 'plugin/insert_cancel.vim') !=# ''
  imap <C-C> <Plug>(InsertCancel)
endif
imap <C-K><C-K> <Plug>(DigraphSearch)
nnoremap <C-L>
      \ :<C-U>nohlsearch<CR><C-L>
inoremap <C-L> <C-O>:execute "normal \<C-L>"<CR>
vmap <C-L> <Esc><C-L>gv
nnoremap &
      \ :&&<CR>
xnoremap &
      \ :&&<CR>
nmap g: <Plug>(ColonOperator)
nnoremap [a
      \ :previous<CR>
nnoremap ]a
      \ :next<CR>
nnoremap [b
      \ :bprevious<CR>
nnoremap ]b
      \ :bnext<CR>
nnoremap [c
      \ :cprevious<CR>
nnoremap ]c
      \ :cnext<CR>
nnoremap [l
      \ :lprevious<CR>
nnoremap ]l
      \ :lnext<CR>
nmap [<Space> <Plug>(PutBlankLinesAbove)
nmap ]<Space> <Plug>(PutBlankLinesBelow)
let mapleader = '\'
let maplocalleader = ','
if maplocalleader ==# ','
  noremap ,, ,
  sunmap ,,
endif
nnoremap <Leader><Tab>
      \ :<C-U>set autoindent! autoindent?<CR>
nnoremap <Leader>c
      \ :<C-U>set cursorline! cursorline?<CR>
nnoremap <Leader>h
      \ :<C-U>set hlsearch! hlsearch?<CR>
nnoremap <Leader>i
      \ :<C-U>set incsearch! incsearch?<CR>
nnoremap <Leader>s
      \ :<C-U>set spell! spell?<CR>
nnoremap <Leader>C
      \ :<C-U>set cursorcolumn! cursorcolumn?<CR>
xmap <Leader>C <Esc><Leader>Cgv
nnoremap <Leader>l
      \ :<C-U>set list! list?<CR>
xmap <Leader>l <Esc><Leader>lgv
nnoremap <Leader>n
      \ :<C-U>set number! number?<CR>
xmap <Leader>n <Esc><Leader>ngv
nnoremap <Leader>N
      \ :<C-U>set ruler! ruler?<CR>
xmap <Leader>N <Esc><Leader>Ngv
nnoremap <Leader>w
      \ :<C-U>set wrap! wrap?<CR>
xmap <Leader>w <Esc><Leader>wgv
nnoremap <Leader>f
      \ :<C-U>set formatoptions?<CR>
nnoremap <Leader>u
      \ :<C-U>set spelllang=en_us<CR>
nnoremap <Leader>z
      \ :<C-U>set spelllang=en_nz<CR>
nmap <Leader>b <Plug>(CopyLinebreakToggle)
nnoremap <Leader>a
      \ :<C-U>ToggleFlagLocal formatoptions a<CR>
nnoremap <Leader>L
      \ :<C-U>ToggleFlagLocal colorcolumn +1<CR>
xmap <Leader>L <Esc><Leader>Lgv
nmap <Leader>p <Plug>PasteInsert
nnoremap <Leader>F
      \ :<C-U>ReloadFileType<CR>
nnoremap <Leader>t
      \ :<C-U>set filetype?<CR>
nnoremap <Leader>T
      \ :<C-U>set filetype=<CR>
nnoremap <Leader>d
      \ :PutDate<CR>
nnoremap <Leader>D
      \ :PutDate!<CR>
nnoremap <Leader>g
      \ :<C-U>echo expand('%:p')<CR>
nnoremap <Leader>G
      \ :<C-U>cd %:h<Bar>pwd<CR>
nnoremap <Leader>P
      \ :<C-U>Establish %:h<CR>
nnoremap <Leader>H
      \ :<C-U>history :<CR>
nnoremap <Leader>k
      \ :<C-U>marks<CR>
nnoremap <Leader>K
      \ :<C-U>function<CR>
nnoremap <Leader>m
      \ :<C-U>nmap<CR>
nnoremap <Leader>M
      \ :<C-U>nmap <buffer><CR>
nnoremap <Leader>S
      \ :<C-U>scriptnames<CR>
nnoremap <Leader>U
      \ :<C-U>command<CR>
nnoremap <Leader>v
      \ :<C-U>let g: v:<CR>
nnoremap <Leader>V
      \ :<C-U>let b: t: w:<CR>
nnoremap <Leader>y
      \ :<C-U>registers<CR>
nnoremap <Leader><Delete>
      \ :bdelete<CR>
nnoremap <Leader><Insert>
      \ :<C-U>enew<CR>
nnoremap <Leader>e
      \ :<C-U>set modifiable noreadonly<CR>
nnoremap <Leader>E
      \ :<C-U>set nomodifiable readonly<CR>
nnoremap <Leader>j
      \ :<C-U>buffers<CR>:buffer<Space>
nmap <Leader>o <Plug>(SelectOldFiles)
nnoremap <Leader>x
      \ :StripTrailingWhitespace<CR>
xnoremap <Leader>x
      \ :StripTrailingWhitespace<CR>
nnoremap <Leader>X
      \ :SqueezeRepeatBlanks<CR>
xnoremap <Leader>X
      \ :SqueezeRepeatBlanks<CR>
nnoremap <Leader>=
      \ :<C-U>KeepPosition execute 'normal! 1G=G'<CR>
nnoremap <Leader>+
      \ :<C-U>KeepPosition execute 'normal! 1GgqG'<CR>
onoremap <Leader>_
      \ :<C-U>execute 'normal! `[v`]'<CR>
onoremap <Leader>%
      \ :<C-U>execute 'normal! 1GVG'<CR>
omap <Leader>5 <Leader>%
map <Leader>{ <Plug>(VerticalRegionUp)
sunmap <Leader>{
map <Leader>} <Plug>(VerticalRegionDown)
sunmap <Leader>}
noremap <Leader>\ `"
sunmap <Leader>\
nnoremap <Leader><lt>
      \ :<C-U>'[,']<lt><CR>
nnoremap <Leader>>
      \ :<C-U>'[,']><CR>
nnoremap <Leader>/
      \ :<C-U>vimgrep /\c/j **<S-Left><S-Left><Right>
nnoremap <Leader>?
      \ :<C-U>lhelpgrep \c<S-Left>
nnoremap <Leader>.
      \ :<C-U>lmake!<CR>
nnoremap <Leader>q gqap
nmap <Leader>r <Plug>(ReplaceOperator)
xmap <Leader>r <Plug>(ReplaceOperator)
nnoremap <Leader>!
      \ :<Up><Home><S-Right>!<CR>
nmap <Leader>1 <Leader>!
nmap <Leader># <Plug>(AlternateFileType)
nmap <Leader>3 <Leader>#
nmap <Leader>$ <Plug>(Fortune)
nmap <Leader>4 <Leader>$
nmap <Leader>& <Plug>(RegexEscape)
nmap <Leader>7 <Leader>&
xmap <Leader>& <Plug>(RegexEscape)
xmap <Leader>7 <Leader>&
nnoremap <silent> <Leader>* *N
nmap <Leader>8 <Leader>*
nnoremap <silent> <Leader>`
      \ :<C-U>ScratchBuffer<CR>
nnoremap <silent> <Leader>~
      \ :<C-U>vertical ScratchBuffer<CR>
nnoremap <Leader>R
      \ :<C-U>ReloadVimrc<CR>
inoreabbrev tr@ tom@sanctum.geek.nz
inoreabbrev tr/ <https://sanctum.geek.nz/>
inoreabbrev almsot almost
inoreabbrev wrnog wrong
inoreabbrev Fielding Feilding
inoreabbrev THe The
inoreabbrev THere There