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
|
" Tom Ryder (tejr)'s vimrc: <https://sanctum.geek.nz/cgit/dotfiles.git>
"
" This file is not truly self-contained; it should run without errors on its
" own without the accompanying plugins to which it refers near the end of this
" file, but you'll get errors for some of the leader maps, for example.
" Load filetype-specific plugins, indent settings, and syntax highlighting
if has('autocmd')
filetype plugin indent on
endif
" Options dependent on the syntax feature
if has('syntax') && !has('g:syntax_on')
" Use syntax highlighting
syntax enable
" Use my colorscheme if using the GUI or if we have 256 colors
if has('gui_running') || &t_Co >= 256
silent! colorscheme sahara
endif
" If we couldn't use 'sahara', just flag a dark background (the author is
" almost certainly using one), and we'll use the default colorscheme
if !exists('g:colors_name')
set background=dark
endif
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 shiftround " Round indenting to multiples of 'shiftwidth'
set shiftwidth=4 " Indent with four spaces
" Spaces to insert on Tab key press; use negative value to mirror 'shiftwidth'
" if supported
if v:version > 703 || v:version == 703 && has('patch693')
set softtabstop=-1
else
set softtabstop=4
endif
" Let me backspace over pretty much anything
set backspace=
set backspace+=eol " Line breaks
set backspace+=indent " Spaces from 'autoindent'
set backspace+=start " The start of current insertion
" Never use any kind of bell, visual or not
if exists('+belloff')
set belloff=all
else
set visualbell t_vb=
endif
" Clear default comment string, let the filetype handle it
set comments=
" How to deal with lines wrapping beyond the last screen row
if v:version > 704 || v:version == 704 && has('patch2109')
set display=truncate " Show '@@@' on the last line, if supported
else
set display=lastline " Just let it run off the screen
endif
" Don't wait for a key after Escape in insert mode
set noesckeys
" Delete comment leaders when joining lines, if supported
if v:version > 703 || v:version == 703 && has('patch541')
set formatoptions+=j
endif
" Don't join lines with two spaces at the end of sentences
set nojoinspaces
" Don't redraw the screen during batch execution
set lazyredraw
" Define list characters
set listchars+=extends:> " Unwrapped text to screen right
set listchars+=precedes:< " Unwrapped text to screen left
set listchars+=tab:>- " Tab characters, preserve width
set listchars+=trail:_ " Trailing spaces
" Add angle brackets to pairs of matched characters
set matchpairs+=<:>
" Don't allow setting options via buffer content
set nomodeline
" Increment/decrement numbers with a leading zero as decimal, not octal
set nrformats-=octal
" Always tell me the number of lines changed by a command
set report=0
" Abbreviate some of the regularly displayed messages
set shortmess=
set shortmess+=f " (file 3 of 5) -> (3 of 5)
set shortmess+=i " [Incomplete last line] -> [noeol]
set shortmess+=I " Don't show startup splash screen
set shortmess+=l " 999 lines, 888 characters -> 999L, 888C
set shortmess+=m " [Modified] -> [+]
set shortmess+=n " [New File] -> [New]
set shortmess+=o " Don't stack file writing messages
set shortmess+=O " Don't stack file reading messages
set shortmess+=r " [readonly] -> [RO]
set shortmess+=t " Truncate file message at start if too long
set shortmess+=T " Truncate other message in middle if too long
set shortmess+=w " written -> [w], appended -> [a]
set shortmess+=x " [dos format] -> [dos]
" Default to no swap files at all, let auto_cache_dirs.vim set it
set noswapfile
" Don't wrap by default, but use \w to toggle it on or off
set nowrap
" Show my current position in the status bar, default format is fine
if has('cmdline_info')
set ruler
endif
" Highlight settings for search, if available
if has('extra_search')
set hlsearch " Highlight completed searches...
nohlsearch " ...but clear it on startup or after re-sourcing
set incsearch " Show matches as I type
endif
" Use all ancestors of current directory for :find
if has('file_in_path')
set path+=**
endif
" Don't load menus at all in GUI mode; needs to be set here, before gVim
" actually starts up
if has('gui_running')
set guioptions+=M
endif
" Line break settings and mappings
if has('linebreak')
" Break lines at word boundaries if possible
set linebreak
" Precede continued lines with '...'
set showbreak=...
" If we have the option, indent wrapped lines as much as the first line
if exists('+breakindent')
set breakindent
endif
endif
" Use New Zealand English by default; binding later in this file allow
" masquerading as a Yankee
if has('spell')
set spelllang=en_nz
endif
" When in visual block mode, let me move the cursor anywhere in the buffer;
" don't restrict me only to regions with text
if has('virtualedit')
set virtualedit+=block
endif
" Configuration for the command completion feature; rather than merely cycling
" through possible completions with Tab, show them above the command line
if has('wildmenu')
" Use the wild menu, both completing and showing all possible completions
" with a single Tab press, just as I've configured Bash to do
set wildmenu
set wildmode=list:longest
" Complete files without case sensitivity, if the option is available
if exists('+wildignorecase')
set wildignorecase
endif
endif
" Configuration for window features
if has('windows')
" Don't resize windows we're not splitting (tmux-like; think Mondrian)
set noequalalways
" Split windows to the right and bottom
set splitbelow
if has('vertsplit')
set splitright
endif
" Get rid of visually noisy folding characters
if has('folding')
let &fillchars = 'diff: ,fold: ,vert: '
endif
endif
" Rebind insert Ctrl-C to undo the current insert operation
inoremap <C-C> <C-C>u
" Rebind normal <Space> to scroll down a page
nnoremap <Space> <C-F>
" Rebind normal & to preserve substitution flags
nnoremap <silent> & :<C-U>&&<CR>
" Stack normal Ctrl-L to clear search highlighting before redraw
nnoremap <silent> <C-L> :<C-U>nohlsearch<CR><C-L>
" Cycle through buffers
nnoremap [b :<C-U>bprevious<CR>
nnoremap ]b :<C-U>bnext<CR>
" Cycle through quicklist items (more often :helpgrep results)
nnoremap [c :<C-U>cprevious<CR>
nnoremap ]c :<C-U>cnext<CR>
" Cycle through location list items
nnoremap [l :<C-U>lprevious<CR>
nnoremap ]l :<C-U>lnext<CR>
" Insert blank lines above and below current line
nmap [<Space> <Plug>PutBlankLinesAbove
nmap ]<Space> <Plug>PutBlankLinesBelow
" Swap buffer line vs screen row motions
nnoremap j gj
nnoremap k gk
nnoremap gj j
nnoremap gk k
" Remap Y to yank to end of line (consistent with C, D)
nnoremap Y y$
" ZA does an unconditional write for all buffers
nnoremap ZA :<C-U>wall!<CR>
" ZW does an unconditional write for this buffer
nnoremap ZW :<C-U>write!<CR>
" A few very important custom digraphs
if has('digraphs')
digraph ./ 8230 " Ellipsis (HORIZONTAL ELLIPSIS U+2026)
digraph %% 8984 " Mac command key (PLACE OF INTEREST SIGN U+2318)
digraph 8: 9731 " Snowman (SNOWMAN U+2603)
endif
" Use different keys for global and local leaders for plugins
if 1
let g:mapleader = '\'
let g:maplocalleader = '_'
endif
" Leader mappings below; use a literal backslash rather than <Leader> so that
" the non-plugin mappings work on vim-tiny
" \a toggles 'formatoptions' 'a' flag using a plugin
nnoremap \a :<C-U>ToggleOptionFlagLocal formatoptions a<CR>
" \b toggles copy-pasteable linebreak settings
nmap \b <Plug>CopyLinebreakToggle
" \c toggles 'cursorcolumn', \C toggles 'cursorline'
nnoremap \c :<C-U>set cursorcolumn! cursorcolumn?<CR>
nnoremap \C :<C-U>set cursorline! cursorline?<CR>
" Current date and time insertion commands, requiring POSIX date(1)
if has('unix')
" \d inserts the local date
nnoremap \d :<C-U>read !date<CR>
" \D inserts the UTC date
nnoremap \D :<C-U>read !date -u<CR>
endif
" \f shows the current 'formatoptions' at a glance
nnoremap \f :<C-U>set formatoptions?<CR>
" \h toggles highlighting search results
nnoremap \h :<C-U>set hlsearch! hlsearch?<CR>
" \i toggles showing matches as I enter my pattern
nnoremap \i :<C-U>set incsearch! incsearch?<CR>
" \j jumps to buffers (jetpack)
nnoremap \j :<C-U>ls<CR>:buffer<Space>
" \l toggles showing tab, end-of-line, and trailing whitespace
nnoremap \l :<C-U>set list! list?<CR>
" \n toggles line numbers
nnoremap \n :<C-U>set number! number?<CR>
" \o and \O open 'pasted insert' lines
nmap \o <Plug>PasteOpenBelow
nmap \O <Plug>PasteOpenAbove
" \p toggles paste mode
nnoremap \p :<C-U>set paste! paste?<CR>
" \r reloads .vimrc
nnoremap \r :<C-U>source $MYVIMRC<CR>
" \s toggles spell checking
nnoremap \s :<C-U>setlocal spell! spell?<CR>
" \t shows current filetype
nnoremap \t :<C-U>set filetype?<CR>
" \u sets US English spelling (compare \z)
nnoremap \u :<C-U>setlocal spelllang=en_us spelllang?<CR>
" \w toggles wrapping
nnoremap \w :<C-U>set wrap! wrap?<CR>
" \x strips trailing whitespace via a custom plugin
nmap \x <Plug>StripTrailingWhitespace
" \z sets NZ English spelling (compare \u)
nnoremap \z :<C-U>setlocal spelllang=en_nz spelllang?<CR>
" Add the packaged version of matchit.vim included in the distribution, if
" supported; plugin/macros.vim loads this for older Vims
if has('packages')
packadd! matchit
endif
" Disable most core plugin stuff that I don't use; after/plugin/dist.vim
" clears these variables later
if 1
" I use tohtml.vim often
" I like matchparen.vim
" I manage plugins myself with Git and a Makefile
let g:loaded_getscriptPlugin = 1
let g:loaded_vimballPlugin = 1
" Vim is the wrong tool for reading archives or compressed text
let g:loaded_gzip = 1
let g:loaded_tarPlugin = 1
let g:loaded_zipPlugin = 1
" I prefer filtering text with Unix tools
let g:loaded_logiPat = 1
" The shell, tab completion, and 'wildmenu' are good enough
let g:loaded_netrwPlugin = 1
" I don't use Vim servers
let g:loaded_rrhelper = 1
" I don't need extra spelling files
let g:loaded_spellfile_plugin = 1
endif
" Source all .vim files from ~/.vim/config
runtime! config/*.vim
|