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
|
set nocompatible
filetype off
" Vundle setup {{{
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Bundle 'gmarik/Vundle.vim'
Bundle 'ervandew/supertab'
Bundle 'airblade/vim-gitgutter'
Bundle 'scrooloose/syntastic'
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-surround'
Bundle 'vim-scripts/multvals.vim'
Bundle 'altercation/vim-colors-solarized'
Bundle 'vim-scripts/django.vim'
Bundle 'nelstrom/vim-markdown-folding'
Bundle 'tpope/vim-markdown'
Bundle 'amperser/proselint'
Bundle 'jgdavey/tslime.vim'
Bundle 'christoomey/vim-tmux-navigator'
Bundle 'nicholaides/words-to-avoid.vim'
Bundle 'reedes/vim-wordy'
Bundle 'vim-scripts/vim-auto-save'
Bundle 'tmhedberg/SimpylFold'
Bundle 'nvie/vim-flake8'
Bundle 'francoiscabrol/ranger.vim'
Bundle 'junegunn/fzf'
Bundle 'junegunn/fzf.vim'
Bundle 'chengzeyi/fzf-preview.vim'
Bundle 'alok/notational-fzf-vim'
call vundle#end()
filetype plugin indent on
"}}}
"
" Basic stuff {{{
set encoding=utf-8
set scrolloff=3
set modelines=0
set guifont=Inconsolata:h16
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set cursorline
set autoindent
set hidden
set number
set undofile
set cpoptions+=$
set cmdheight=1
set laststatus=1
set showcmd
set showmode
set backspace=indent,eol,start
let mapleader = ","
"save things when we turn our back
autocmd BufLeave,FocusLost * silent! wall
" save things all the time:
let g:auto_save = 1
let g:auto_save_in_insert_mode = 0
"}}}
" Abbreviations {{{
" easier markdown links:
let @a ='Sr%a()h'
let @s ='Sr%a(){: rel=nofollow}17h'
" email signature:
let @c ='icheers
Scott Gilbertson
sng@luxagraf.net '
let @w ='icheers
Scott Gilbertson
scott_gilbertson@condenast.com'
let @t ='iThank you for your help.
'
let @h ="iHello, my name is Scott Gilbertson and and I am a product writer with WIRED's Gear team. I am reaching out because we're working on an article about "
let @b ='tag=w050b-20'
let @n ='tag=wirednl-20'
let @d ='<div class="cluster">
<span class="row-2">
</span>
</div>'
" get rid of line breaks in paragraphs
let @p ='g/^./ .,/^$/-1 join'
" }}}
" Convenience mappings {{{
"for rewrapping things when composing email
map <leader>q gq}
"uppercase words
nnoremap <leader>up :%s/\<./\u&/g<cr>
"Lowercase words
nnoremap <leader>down :%s/\<./\l&/g<cr>
"conver to emdash
nnoremap <leader>- :%s/ -- /—/g<cr>
nnoremap <leader>t TlistToggle<cr>
nnoremap <leader>cd :lcd %:p:h<cr>
" sane spelling options
nnoremap <leader>sp :set spell! spelllang=en_us spell?<CR>
set spellfile=~/.vim/dict.add
map <silent> <C-U> ]s
map <silent> <C-I> z=
"quicker way to get to the thesaurus:
inoremap ;t <c-x><c-t>
nnoremap ;m :%s/
$//<cr>
"Let's just leave the whole w out of it shall we.
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
nmap <leader>n :NV!<cr>
" Convert curly quotes to straight. {{{
" Any argument causes substitute to confirm changes.
function! ToStraight(line1, line2, args)
let flags = 'eg'
let range = a:line1 . ',' . a:line2
if empty(a:args)
let range = 'silent ' . range
else
let flags .= 'c'
endif
let search = @/
exe range . "s/[‘’]/'/" . flags
exe range . 's/[“””]/"/' . flags
nohl
let @/ = search
endfunction
command! -nargs=? -range ToStraight call ToStraight(<line1>, <line2>, '<args>')
nnoremap ,str :%ToStraight<cr>
" Keep search matches in the middle of the window.
nnoremap N nzzzv
nnoremap n Nzzzv
" Easier to type, and I never use the default behavior.
noremap H ^
noremap L $
vnoremap L g_
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
nnoremap j gj
nnoremap k gk
" Make os x clipboard work
set clipboard=unnamedplus
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>
"yank a line, not a line and some more
nnoremap Y y$
nnoremap <leader>it /\vit's\|its <cr>
" Fuck you, help key.
noremap <F1> :checktime<cr>
inoremap <F1> <esc>:checktime<cr>
" zt is okay for putting something at the top of the screen, but when I'm
" writing prose I often want to put something at not-quite-the-top of the
" screen. zh is "zoom to head level"
nnoremap zh mzzt10<c-u>`z
" Easier linewise reselection of what you just pasted.
nnoremap <leader>V V`]
" HTML tag closing
inoremap <C-_> <space><bs><esc>:call InsertCloseTag()<cr>a
" Select (charwise) the contents of the current line, excluding indentation.
" Great for pasting Python lines into REPLs.
nnoremap vv ^vg_
" Sudo to write
cnoremap w!! w !sudo tee % >/dev/null
" Insert Mode Completion {{{
inoremap <c-f> <c-x><c-f>
inoremap <c-]> <c-x><c-]>
inoremap <c-l> <c-x><c-l>
" }}}
" }}}
" Searching ------------------------------------------------------------------- {{{
nnoremap / /\v
vnoremap / /\v
set ignorecase
set smartcase
set gdefault
set incsearch
set noshowmatch
set hlsearch
nnoremap <leader><space> :noh<cr>
" }}}
" Tab Completion -------------------------------------------------------------- {{{
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*
"}}}
"Trying ranger
"function! RangeChooser()
" let temp = tempname()
" " The option "--choosefiles" was added in ranger 1.5.1. Use the next line
" " with ranger 1.4.2 through 1.5.0 instead.
" "exec 'silent !ranger --choosefile=' . shellescape(temp)
" if has("gui_running")
" exec 'silent !xterm -e ranger --choosefiles=' . shellescape(temp)
" else
" exec 'silent !ranger --choosefiles=' . shellescape(temp)
" endif
" if !filereadable(temp)
" redraw!
" " Nothing to read.
" return
" endif
" let names = readfile(temp)
" if empty(names)
" redraw!
" " Nothing to open.
" return
" endif
" " Edit the first item.
" exec 'edit ' . fnameescape(names[0])
" " Add any remaning items to the arg list/buffer list.
" for name in names[1:]
" exec 'argadd ' . fnameescape(name)
" endfor
" redraw!
"endfunction
"command! -bar RangerChooser call RangeChooser()
nnoremap <leader>nt :<C-U>Ranger<CR>
" Backups ----------------------------------------------------------------------{{{
set backup " enable backups
set noswapfile " it's 2013, Vim.
set undodir=~/.vimtmp/undo// " undo files
set backupdir=~/.vimtmp/backup// " backups
set directory=~/.vimtmp/swap// " swap files
" Make those folders automatically if they don't already exist.
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
if !isdirectory(expand(&backupdir))
call mkdir(expand(&backupdir), "p")
endif
if !isdirectory(expand(&directory))
call mkdir(expand(&directory), "p")
endif
" Make Vim able to edit crontab files again.
set backupskip=/tmp/*,/private/tmp/*"
" }}}
"Thesaurus
set thesaurus+=/home/lxf/.mthesaur.txt
"}}}
" Notes (AKA NValt in Vim){{{
" NValt style searching with Ack to quicklist
command! -nargs=1 Nvs :Ack -i -n "<args>" $NOTES_DIR
command! -nargs=1 Ngrep vimgrep "<args>" $NOTES_DIR/*.txt|:cw
"noremap <leader>n :Ngrep
noremap <leader>v :Nvs
" }}}
" Filetype stuff {{{
augroup ft_vim
au!
au FileType vim setlocal foldmethod=marker
au FileType help setlocal textwidth=78
augroup END
" If the current buffer has never been saved, it will have no name,
" call the file browser to save it, otherwise just save it.
nnoremap <silent> <C-S> :if expand("%") == ""<CR>browse confirm w<CR>else<CR>confirm w<CR>endif<CR>
autocmd BufRead,BufNewFile *.css,*.scss,*.less setlocal foldmethod=marker foldmarker={,}
" turn on sentences level undo for prose:
function s:undosentences ()
inoremap . .<C-g>u
inoremap ! !<C-g>u
inoremap ? ?<C-g>u
inoremap : :<C-g>u
setl wrap linebreak textwidth=0 wrapmargin=0 synmaxcol=999 filetype=markdown spell
endfunction
" txt, text, md and markdown are markdown files
au BufEnter,BufRead,BufNewFile *.{text,txt,md,markdown} call s:undosentences()
" syntastic and proselint
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_markdown_checkers = ['proselint']
" wrap python and other files:
function s:mypythonsettings()
highlight BadWhitespace ctermbg=red guibg=red
"set foldmethod=indent
"set textwidth=79
endfunction
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h call s:mypythonsettings()
"}}}
" Colors {{{
syntax on
set background=dark
let g:solarized_termtrans = 1
colorscheme solarized
set t_Co=256 " force vim to use 256 colors
let g:solarized_termcolors=256
"}}}" Folding {{{
set foldlevelstart=0
" Space to toggle folds.
nnoremap <Space> za
vnoremap <Space> za
" Make zO recursively open whatever fold we're in, even if it's partially open.
nnoremap zO zczO
" "Focus" the current line. Basically:
"
" 1. Close all folds.
" 2. Open just the folds containing the current line.
" 3. Move the line to a little bit (15 lines) above the center of the screen.
" 4. Pulse the cursor line. My eyes are bad.
"
" This mapping wipes out the z mark, which I never use.
"
" I use :sus for the rare times I want to actually background Vim.
nnoremap <c-z> mzzMzvzz8<c-e>`z:Pulse<cr>
function! MyFoldText() " {{{
let line = getline(v:foldstart)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
endfunction " }}}
set foldtext=MyFoldText()
augroup javascript_folding
au!
au FileType javascript setlocal foldmethod=syntax
augroup END
" Disable commands for creating and deleting folds.
"noremap zf <Nop>
"noremap zF <Nop>
"noremap zd <Nop>
"noremap zD <Nop>
noremap zE <Nop>
" }}}
" Plugins {{{
"Ctrl P {{{
"nnoremap <leader>r :CtrlPMRU<cr>
"nnoremap <leader>m :CtrlPBuffer<cr>
"nnoremap <leader>. :CtrlP<cr>
"nnoremap <leader>w :CtrlP ~/writing/wired/<cr>
"nnoremap <leader>a :CtrlP app/<cr>
"nnoremap <leader>d :CtrlP $HOME/notes/<cr>
"nnoremap <leader>l :CtrlP $HOME/writing/luxagraf/<cr>
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|venv|site|static)$',
\ 'file': '\v\.(pyc|so|dll)$',
\ }
"}}}
"FZF {{{
let g:fzf_preview_window='right:60%'
let g:fzf_history_dir = '~/.local/share/fzf-history'
set grepprg=rg\ --vimgrep\ --smart-case\ --hidden\ --follow
nnoremap <leader>. :FZF<cr>
nnoremap <leader>r :History<cr>
nnoremap <leader>w :FZF ~/writing/conde/wired/<cr>
nnoremap <leader>a :FZF app/<cr>
nnoremap <leader>l :Rg<cr>
nnoremap <leader>g :BLines<cr>
"}}}
" FZF Notational Velocity plugin {{{
let g:nv_search_paths = ['~/notes', '~/writing/luxagraf/', '~/documents/bookmarks/']
"}}}
"
" SimpylFold Python folding plugin {{{
let g:SimpylFold_docstring_preview = 0
"}}}
" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
let g:SuperTabDefaultCompletionType = '<C-n>'
nnoremap <silent> <c-s> :NV<CR>
let g:markdown_fold_style = 'nested'
nmap <leader>i :%s/
//g
nmap <leader># :%s/### /###/g
imap jj <Esc>
vmap <silent> <leader>r <esc>:'<,'>:w !espeak &> /dev/null <CR>
nnoremap "*p :let @"=substitute(system("wl-paste --no-newline --primary"), '<C-v><C-m>', '', 'g')<cr>p
xnoremap <c-c> y:!wl-copy <C-r>"<cr><cr>gv
vnoremap <c-c> y:!wl-copy <C-r>"<cr><cr>gv
|