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
463
464
465
466
467
468
469
470
471
472
473
474
475
|
" Tom Ryder (tejr)'s vimrc: <https://sanctum.geek.nz/cgit/dotfiles.git>
" Requires Vim 7.0 or newer with +eval.
" Set an environment variable for the user runtime directory, if not already
" set; use the first element of &runtimepath, rather like 'spellfile'
if !exists('$MYVIM')
let $MYVIM = expand(split(&runtimepath, ',')[0])
endif
" The all-important default indent settings; filetypes to tweak
set autoindent " Use indent of previous line on new lines
set expandtab " Use spaces instead of tabs
set shiftwidth=4 " Indent with four spaces
" The number of spaces the Tab key should insert should follow 'shiftwidth';
" if Vim is new enough (v7.3.693), use a negative value to automate this,
" otherwise just use its present value
if v:version > 703
\ || v:version == 703 && has('patch693')
set softtabstop=-1
else
let &softtabstop = &shiftwidth
endif
" Restore insert mode 'backspace' limits to the stringent Vim default, if a
" system vimrc or Neovim's heretical defaults has messed with it
set backspace=
" Try to keep backups in one system-appropriate directory, including full
" encoded path in filename (trailing double slash) if supported (v8.1.251)
set backup
if has('patch-8.1.251')
set backupdir^=$MYVIM/cache/backup//
else
set backupdir^=$MYVIM/cache/backup
endif
" Add some *nix paths not to back up
" /dev/shm: Shared memory RAM disk
" /usr/tmp: Hard-coded path for `sudo -e` 1/2
" /var/tmp: Hard-coded path for `sudo -e` 2/2
if has('unix')
set backupskip^=/dev/shm/*,/usr/tmp/*,/var/tmp/*
endif
" Indent wrapped lines if supported (v7.4.338)
if exists('+breakindent')
set breakindent
endif
" Clear default 'comments' and 'commentstring', filetype to handle
set comments=
set commentstring=
" Add completion options
" longest: Insert longest common substring
" menuone: Show the menu even if only one match
set completeopt+=longest,menuone
" Give me a prompt instead of just rejecting risky :write, :saveas
set confirm
" Sentence objects are separated by two spaces
set cpoptions+=J
" Try to keep swap files in one system-appropriate directory, including full
" encoded path in filename (trailing double slash)
set directory^=$MYVIM/cache/swap//
" Default to UTF-8 if $LANG didn't specify
if !exists('$LANG')
set encoding=utf-8
endif
" Don't wait for a key after Escape in insert mode
" Not in Neovim
if exists('+esckeys')
set noesckeys
endif
" Fold based on indent, but only when I ask
set foldlevelstart=99
set foldmethod=indent
" Delete comment leaders when joining lines, if supported (v7.3.541)
if v:version > 703
\ || v:version == 703 && has('patch541')
set formatoptions+=j
endif
" Don't break a single space after a period, if supported (v8.1.728)
if has('patch-8.1.728')
set formatoptions+=p
endif
" Don't load GUI menus; set here before GUI starts or any filetype or syntax
" logic is performed
if has('gui_running')
set guioptions+=M
endif
" Allow buffers to have changes without being displayed
set hidden
" Keep much more command and search history
set history=2000
" Highlight completed searches; clear on reload
set hlsearch
nohlsearch
" Don't assume I'm editing C; let the filetype set this
set include=
" Show search matches as I type my pattern
set incsearch
" Don't show a status line if there's only one window
" This is Vim's default, but not Neovim's
set laststatus=1
" Don't redraw the screen during batch execution
set lazyredraw
" Break lines at word boundaries
set linebreak
" Define extra 'list' display characters
" extends: Unwrapped text to screen right
" nbsp: Non-breaking spaces
" precedes: Unwrapped text to screen left
" tab: Tab characters, preserve width
" trail: Trailing spaces
set listchars+=extends:>,nbsp:+,precedes:<,tab:>-,trail:-
" Don't allow setting options via buffer content
set nomodeline
" Treat numbers with a leading zero as decimal, not octal
set nrformats-=octal
" Don't search /usr/include by default
set path-=/usr/include
" Disable command line display of file position if a system vimrc or Neovim
" has switched it on
set noruler
" Remove Debian's 'runtimepath' nonsense if present
set runtimepath-=/var/lib/vim/addons
set runtimepath-=/var/lib/vim/addons/after
" Make sessions usable
set sessionoptions-=localoptions " No buffer options or mappings
set sessionoptions-=options " No global options or mappings
" Don't show startup splash screen (I donated)
set shortmess+=I
" Prefix wrapped rows with three dots
set showbreak=...
" New window positioning
set splitbelow " Below the current window, not above
set splitright " Right of the current window, not left
" Don't try to syntax highlight run-on lines
set synmaxcol=500
" PuTTY is a fast terminal, but Vim doesn't know that yet
if &term =~# '^putty'
set ttyfast
endif
" No terminal mouse, even if we could; the manual says to set 't_RV', but
" doing that doesn't seem to prevent 'ttyfast' from being set; check for
" option existence as this is not an option in Neovim
if exists('+ttymouse')
set ttymouse=
endif
" Try to keep persistent undo files in one system-appropriate directory
" (v7.2.438), including full encoded path in filename (trailing double slash)
if has('persistent_undo')
set undofile
set undodir^=$MYVIM/cache/undo//
endif
" Keep the viminfo file in the ~/.vim directory, mostly to stop history
" getting clobbered when something runs Vim without using this file
if exists('+viminfofile') " Use the new method if we can (v8.1.716)
let &viminfofile = $MYVIM.'/viminfo'
else " Use old method instead; it works fine, it's just a bit clunky
execute 'set viminfo+=n'.escape($MYVIM.'/viminfo', '\ ')
endif
" Let me move beyond buffer text in visual block mode
set virtualedit+=block
" Never beep at me
set visualbell t_vb=
" Tab completion settings
set wildignore=*~,#*#
\,*.7z
\,*.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
\,.DS_Store,.git,.hg,.svn
if exists('+wildignorecase')
set wildignorecase " Case insensitive, if supported (v7.3.072)
endif
set wildmode=list:longest " Tab press completes and lists
" Load filetype settings, plugins, and maps
let maplocalleader = ','
filetype plugin indent on
" Use syntax highlighting
if !exists('syntax_on')
syntax enable
endif
" Try to use sahara color scheme with 'cursorline' set; otherwise, use the
" default color scheme with a dark background
try
colorscheme sahara
set cursorline
catch
if &background != 'dark' " Avoid reloading syntax files unnecessarily
set background=dark
endif
endtry
" Remap normal space to scroll down a page
nnoremap <Space> <PageDown>
" Do a :next after hitting the last line
if &loadplugins " Don't change the mapping if we won't be loading the plugin
nmap <Space> <Plug>(ScrollNext)
endif
" Remap insert Ctrl-C to undo the escaped insert operation
if &loadplugins " Don't break the key if we won't be loading the plugin
imap <C-C> <Plug>(InsertCancel)
endif
" Map double Ctrl-K in insert mode to search digraph names
imap <C-K><C-K> <Plug>(DigraphSearch)
" Stack normal/visual/select Ctrl-L to clear search highlight
nnoremap <silent> <C-L> :<C-U>nohlsearch<CR><C-L>
vnoremap <silent> <C-L> :<C-U>nohlsearch<CR>gv<C-L>
" Make Ctrl-L work in insert mode too; good for choppy terminals
inoremap <silent> <C-L> <C-O>:redraw<CR>
" Remap normal/visual & and g& to preserve substitution flags
nnoremap <silent> & :&&<CR>
xnoremap <silent> & :&&<CR>
nnoremap <silent> g& :<C-U>%&&<CR>
" Map g: as a 'colon operator'
nmap g: <Plug>(ColonOperator)
" Cycle through argument list
nnoremap [a :previous<CR>
nnoremap ]a :next<CR>
" Cycle through buffers
nnoremap [b :bprevious<CR>
nnoremap ]b :bnext<CR>
" Cycle through quickfix list items
nnoremap [c :cprevious<CR>
nnoremap ]c :cnext<CR>
" Cycle through location list items
nnoremap [l :lprevious<CR>
nnoremap ]l :lnext<CR>
" Insert blank lines around current line
nmap [<Space> <Plug>(PutBlankLinesAbove)
nmap ]<Space> <Plug>(PutBlankLinesBelow)
" \a toggles 'formatoptions' 'a' flag using a plugin
nnoremap <Leader>a :<C-U>ToggleFlagLocal formatoptions a<CR>
" \b toggles settings friendly to copying and pasting
nmap <Leader>b <Plug>(CopyLinebreakToggle)
" \c toggles 'cursorline'; no visual mode map as it doesn't work
nnoremap <Leader>c :<C-U>setlocal cursorline! cursorline?<CR>
" \C toggles 'cursorcolumn'; works in visual mode
nnoremap <Leader>C :<C-U>setlocal cursorcolumn! cursorcolumn?<CR>
xnoremap <Leader>C :<C-U>setlocal cursorcolumn! cursorcolumn?<CR>gv
" \d inserts the local date (POSIX date)
nnoremap <Leader>d :read !date<CR>
" \D inserts the UTC date (POSIX date)
nnoremap <Leader>D :read !date -u<CR>
" \e forces a buffer to be editable
nnoremap <Leader>e :<C-U>setlocal modifiable noreadonly<CR>
" \f shows the current 'formatoptions' at a glance
nnoremap <Leader>f :<C-U>setlocal formatoptions?<CR>
" \F reloads filetype plugins
nnoremap <Leader>F :<C-U>doautocmd filetypedetect BufRead<CR>
" \g changes directory to the current file's location
nnoremap <Leader>g :<C-U>cd %:h<Bar>pwd<CR>
" \h toggles highlighting search results
nnoremap <Leader>h :<C-U>set hlsearch! hlsearch?<CR>
" \H shows command history
nnoremap <Leader>H :<C-U>history :<CR>
" \i toggles showing matches as I enter my pattern
nnoremap <Leader>i :<C-U>set incsearch! incsearch?<CR>
" \j jumps to buffers ("jetpack")
nnoremap <Leader>j :<C-U>buffers<CR>:buffer<Space>
" \k shows my marks
nnoremap <Leader>k :<C-U>marks<CR>
" \l toggles showing tab, end-of-line, and trailing white space
nnoremap <Leader>l :<C-U>setlocal list! list?<CR>
xnoremap <Leader>l :<C-U>setlocal list! list?<CR>gv
" \L toggles 'colorcolumn' showing 'textwidth'
nnoremap <Leader>L :<C-U>ToggleFlagLocal colorcolumn +1<CR>
xnoremap <Leader>L :<C-U>ToggleFlagLocal colorcolumn +1<CR>gv
" \m shows normal maps
nnoremap <Leader>m :<C-U>map<CR>
" \M shows buffer-local normal maps
nnoremap <Leader>M :<C-U>map <buffer><CR>
" \n toggles line number display
nnoremap <Leader>n :<C-U>setlocal number! number?<CR>
xnoremap <Leader>n :<C-U>setlocal number! number?<CR>gv
" \N toggles position display in bottom right
nnoremap <Leader>N :<C-U>set ruler! ruler?<CR>
xnoremap <Leader>N :<C-U>set ruler! ruler?<CR>gv
" \o opens a line below in paste mode
nmap <Leader>o <Plug>(PasteOpenBelow)
" \O opens a line above in paste mode
nmap <Leader>O <Plug>(PasteOpenAbove)
" \p toggles paste mode
nnoremap <Leader>p :<C-U>set paste! paste?<CR>
" \P creates the path to the current file
nnoremap <Leader>P :<C-U>call mkdir(expand('%:h'), 'p')<CR>
" \q formats the current paragraph
nnoremap <Leader>q gqap
" \r acts as a replacement operator
nmap <Leader>r <Plug>(ReplaceOperator)
xmap <Leader>r <Plug>(ReplaceOperator)
" \R reloads ~/.vimrc
nnoremap <Leader>R :<C-U>source $MYVIMRC<CR>
" \s toggles spell checking
nnoremap <Leader>s :<C-U>setlocal spell! spell?<CR>
" \S shows loaded scripts
nnoremap <Leader>S :<C-U>scriptnames<CR>
" \t shows current filetype
nnoremap <Leader>t :<C-U>setlocal filetype?<CR>
" \T clears filetype
nnoremap <Leader>T :<C-U>setlocal filetype=<CR>
" \u sets US English spelling (compare \z)
nnoremap <Leader>u :<C-U>setlocal spelllang=en_us<CR>
" \v shows all global variables
nnoremap <Leader>v :<C-U>let g: v:<CR>
" \V shows all local variables
nnoremap <Leader>V :<C-U>let b: t: w:<CR>
" \w toggles wrapping
nnoremap <Leader>w :<C-U>setlocal wrap! wrap?<CR>
xnoremap <Leader>w :<C-U>setlocal wrap! wrap?<CR>gv
" \x strips trailing whitespace via a custom plugin
nmap <Leader>x :StripTrailingWhitespace<CR>
xmap <Leader>x :StripTrailingWhitespace<CR>
" \X squeezes repeated blank lines via a custom plugin
nmap <Leader>X :SqueezeRepeatBlanks<CR>
xmap <Leader>X :SqueezeRepeatBlanks<CR>
" \y shows all registers
nnoremap <Leader>y :<C-U>registers<CR>
" \z sets NZ English spelling (compare \u)
nnoremap <Leader>z :<C-U>setlocal spelllang=en_nz<CR>
" \= runs the whole buffer through =, preserving position
nnoremap <Leader>= :<C-U>call vimrc#Anchor('1G=G')<CR>
" \+ runs the whole buffer through gq, preserving position
nnoremap <Leader>+ :<C-U>call vimrc#Anchor('1GgqG')<CR>
" \. runs the configured make program into the location list
nnoremap <Leader>. :<C-U>lmake!<CR>
" \< and \> adjust indent of last edit; good for pasting
nnoremap <Leader><lt> :<C-U>'[,']<lt><CR>
nnoremap <Leader>> :<C-U>'[,']><CR>
" \_ uses last changed or yanked text as an object
onoremap <Leader>_ :<C-U>normal! `[v`]<CR>
" \% uses entire buffer as an object
onoremap <Leader>% :<C-U>normal! 1GVG<CR>
" \{ and \} move to lines with non-space chars before current column
nmap <Leader>{ <Plug>(VerticalRegionUp)
nmap <Leader>} <Plug>(VerticalRegionDown)
omap <Leader>{ <Plug>(VerticalRegionUp)
omap <Leader>} <Plug>(VerticalRegionDown)
xmap <Leader>{ <Plug>(VerticalRegionUp)
xmap <Leader>} <Plug>(VerticalRegionDown)
" \/ types :vimgrep for me ready to enter a search pattern
nnoremap <Leader>/ :<C-U>vimgrep /\c/j **<S-Left><S-Left><Right>
" \? types :lhelpgrep for me ready to enter a search pattern
nnoremap <Leader>? :<C-U>lhelpgrep \c<S-Left>
" \\ escapes regex metacharacters
nmap <Leader>\ <Plug>(RegexEscape)
xmap <Leader>\ <Plug>(RegexEscape)
" \DEL deletes the current buffer
nnoremap <Leader><Delete> :bdelete<CR>
" \INS edits a new buffer
nnoremap <Leader><Insert> :<C-U>enew<CR>
" \TAB toggles 'autoindent'
nnoremap <Leader><Tab> :<C-U>setlocal autoindent! autoindent?<CR>
" Execution mappings; each of these clobbers register z
" \@ executes line in normal mode
nnoremap <Leader>@ ^"zyg_@z
" \: executes line in command mode
nnoremap <Leader>: ^"zyg_:<C-R>z<CR>
" \! executes line with 'shell'
nnoremap <Leader>! ^"zyg_:!<C-R>z<CR>
" Things I almsot always type wrnog
inoreabbrev almsot almost
inoreabbrev wrnog wrong
inoreabbrev Fielding Feilding
|