Source

dotfiles / vimrc

The default branch has multiple heads

  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
" Pre-Pathogen Configuration

" Zen HTML for XML, etc.
let g:user_zen_settings = {
\    'php' : {
\    'extends' : 'html',
\    'filters' : 'c',
\  },
\  'xml' : {
\    'extends' : 'html',
\  },
\  'haml' : {
\    'extends' : 'html',
\  },
\}
let g:user_zen_expandabbr_key = '<c-o>'

let g:yankring_replace_n_pkey = '<m-p>'
let g:yankring_replace_n_nkey = '<m-n>'

" Load Pathogen
" TODO: Update Pathogen; look at pathogen#infect
if $DOTFILES != ""
  set runtimepath+=~"$DOTFILES/vim/bundle/vim-pathogen"
  set runtimepath^=~"$DOTFILES/vim/bundle/vim-pathogen"
  filetype off
  source $DOTFILES/vim/bundle/vim-pathogen/autoload/pathogen.vim
  call pathogen#runtime_append_all_bundles()
  call pathogen#helptags()
else
  echoerr "DOTFILES is unset!  Plugins will be missing!  Please fix this."
endif


" Everything Else
syntax on
filetype plugin indent on

set nocompatible

set modelines=0

set background=dark
set backspace=2
set fileencodings=ucs-bom,utf-8,default
set hlsearch
set ruler
set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.info,.aux,.log,.dvi,.bbl,.out
syn on


set hlsearch

if version >= 703
  set colorcolumn=125
  set relativenumber
  set undofile
endif

" https://github.com/juanpabloaj/dotfiles/blob/master/.vimrc#L404,L405
if exists('+relativenumber')
  augroup RelativeNumbers
    au!
    autocmd InsertEnter * setl nu
    autocmd InsertLeave * setl rnu
    autocmd WinLeave *
          \ if &rnu==1 |
          \ exe "setl norelativenumber" |
          \ exe "setl nu" |
          \ endif
    autocmd WinEnter *
          \ if &rnu==0 |
          \ exe "setl rnu" |
          \ endif
  augroup END
endif


set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab

" See http://stevelosh.com/blog/2010/09/coming-home-to-vim/#important-vimrc-lines
set encoding=utf-8
set scrolloff=3
set autoindent
set showmode
set showcmd
set hidden
" Potential addition from http://stackoverflow.com/a/526940/25625
" set wildmode=longest,list,full
set wildmenu
set wildmode=list:longest
set visualbell
set cursorline
set ttyfast
set ruler
set backspace=indent,eol,start
set laststatus=2

let mapleader = ","

nnoremap / /\v
vnoremap / /\v
set ignorecase
set smartcase
set gdefault
" See http://stackoverflow.com/questions/1276403/simple-vim-commands-you-wish-youd-known-earlier/1295244#1295244
set incsearch
set showmatch
set hlsearch
nnoremap <silent><leader><space> :noh<cr>
nnoremap <tab> %
vnoremap <tab> %

set wrap
set textwidth=119
" :help fo-table
set formatoptions=qrn1

set list
" set listchars=tab:▸\ ,eol:¬
if has("gui_macvim") || has("gui_running")
  set listchars=tab:▸\
endif

if has("gui_macvim")
  "FIXME: This is un-tested!
  set guifont=Menlo
elseif has("gui_running")
  set guifont=Consolas
endif

" For when I want to finally learn hjkl
" nnoremap <up> <nop>
" nnoremap <down> <nop>
" nnoremap <left> <nop>
" nnoremap <right> <nop>
" inoremap <up> <nop>
" inoremap <down> <nop>
" inoremap <left> <nop>
" inoremap <right> <nop>
" nnoremap j gj
" nnoremap k gk

if has("gui_macvim")
  " Mac-only
  inoremap <F1> <ESC>:set invfullscreen<CR>a
  nnoremap <F1> :set invfullscreen<CR>
  vnoremap <F1> :set invfullscreen<CR>
  set fuoptions=maxvert,maxhorz
else
  inoremap <F1> <ESC>
  nnoremap <F1> <ESC>
  vnoremap <F1> <ESC>
endif

" If I ever want to auto-save
" au FocusLost * :wa

" Strip trailing whitespace
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>

nnoremap <leader>a :Ack

" Fold Tag
nnoremap <leader>ft Vatzf
" Sort CSS Properties
nnoremap <leader>S ?{<CR>jV/^\s*\}?$<CR>k:sort<CR>:noh<CR>

" Re-hard-wrap paragraphs of text
nnoremap <leader>q gqip

" Select the text I just pasted
nnoremap <leader>v V`]

" Open vimrc in a vertically-split window
nnoremap <leader>ev <C-w><C-v><C-l>:e $MYVIMRC<cr>
nnoremap <leader>eV <C-w><C-v><C-l>:e $DOTFILES/vimrc<cr>

" Thanks to http://vim.wikia.com/wiki/Open_vimrc_file
"   and http://amix.dk/vim/vimrc.html
" Fast editing of the .vimrc
nnoremap <leader>eR :source $MYVIMRC<CR>
" When vimrc is edited, reload it
" FIXME: This works with vimrc but not _vimrc
augroup vimrc
  autocmd! bufwritepost vimrc source $MYVIMRC
augroup END



" Escape from Insert mode with jj
inoremap jj <ESC>

" Open a vertical split and switch to it.
nnoremap <leader>w <C-w>v<C-w>l

" ctrl-hjkl to navigate splits
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" Color schemes I might like
" color darkblue
" color elflord
" color koehler
" color macvim
" color murphy
" color ron
" color torte
" color ir_black
" TODO: Try inkpot from https://github.com/ciaranm/inkpot
" TODO: Try vividchalk from https://github.com/tpope/vim-vividchalk
set background=dark
if has("windows") && ! has("gui")
  color elflord
else
  colorscheme solarized
endif


" Show YankRing
nnoremap <silent> <F3> :YRShow<cr>
inoremap <silent> <F3> <ESC>:YRShow<cr>

" Toggle-panes
" TODO: Test the below -- was previously inoremap.
noremap <F4> <ESC>:NERDTreeToggle<CR>
noremap <F2> <ESC>:NERDTreeToggle<CR>

" TODO: Get GUndo.  Why isn't this checked in?
noremap <F5> :GundoToggle<CR>

nnoremap <F6> Go<CR><ESC>"=strftime("%c")<CR>Po
inoremap <F6> <esc>Go<CR><C-R>=strftime("%c")<CR><CR>



" Scratch: http://www.vim.org/scripts/script.php?script_id=664
nnoremap <leader><tab> :Scratch<CR>

nnoremap <leader>R :call rainbow_parenthsis#Toggle()<CR>

" reload Pathogen bundles
nnoremap <leader>p :call pathogen#runtime_append_all_bundles()<cr>

nnoremap <leader>C :!pbpaste \| wc<cr>

"redact numbers with more than 4 digits, and certain bank reference numbers
nnoremap <leader>r :Redact<cr>
verbose command! -range=% Redact %s/\v<\d{5,}/redacted/e | %s/\n\?<REFERENCE reda[^>]*>//e

" Convert TSV to CSV
nnoremap <leader>c :CSV<cr>
verbose command! -range=% CSV <line1>,<line2>!python -c 'import csv, sys, fileinput; writer = csv.writer(sys.stdout); [writer.writerow([field.strip() for field in line.split("\t")]) for line in fileinput.input() if line.strip() \!= ""]'

nnoremap <leader>J :g/\v:$/normal J<cr>:%s/\v\tHelp$//e<cr>:FixWhitespace<cr>:%s/.*Sort By: //<cr>

" Join together the multi-line "intersted earned" items from bank statements onto one line.
nnoremap <leader>fi :g!#\v\d{2}/\d{2}/\d{4}[,\t]#normal kJ<cr>

nnoremap <leader>fw :FixWhitespace<cr>


" Thanks to http://dailyvim.blogspot.com/2007/11/macro-registers.html
":noremap qp mqGo^]"qp
":noremap qd G0"qdd'q
let @p='mqGo^]"qp'
let @d="qd G0\"qdd'q"

" Fix man-page formatting
" %s/\(.\)\1/\1/

" Fix Quotes from copy-pasta.
nnoremap <leader>fq :%s/’/'/<cr>

" Inspired by http://superuser.com/questions/197327/how-to-set-background-color-for-vims-active-window-only/241133#241133
augroup BgHighlight
    autocmd!
    autocmd WinEnter * set relativenumber
    autocmd WinLeave * set norelativenumber
augroup END

set pastetoggle=<F1>

" http://forrst.com/posts/Use_w_to_sudo_write_a_file_with_Vim-uAN
cmap w!! w !sudo tee % >/dev/null

""Fix" tabs to be a table in JIRA wiki markup.
nnoremap <leader>ftj vip:s/\\t\ze\(\t\|$\)/\t \t/e<CR>
                    \vip:s/\v^\|\t\|$/\|/<CR>
                    \'<:s/~/~~/<CR>
                    \vip:Tabularize /\|\+<CR>
                    \"+yip
"vip:s/\|\|/| |/<CR>
" This one is for MediaWiki. Not done yet.
nnoremap <leader>ftw :set paste<cr>
                    \vip:s/^/\|- style="background-color: transparent; color: inherit; "\r\|<CR>
                    \vip:s/\v\t/\|\|/<CR>
                    \{O<esc>
                    \}{jj:s/\|/!/<CR>
                    \{o{\| class="wikitable sortable collapsible"<ESC>
                    \o\|+ TODO: Caption<ESC>
                    \}o<esc>
                    \{}O\|}<ESC>
                    \:set nopaste<cr>
                    \"+yip


" sql-list for vim
nnoremap <leader>sl vip:s/.*/'\0',/<cr>)xvipJI(<esc>A)<esc>

" Prepend the lines in the selection or paragraph with line numbers followed by tab.
" This is helpful for use with diff in some situations.
" Based on:
" :'<,'>s/^/\=(1-line("'<")+line('.')) . "\t"
vnoremap <leader>n :s/^/\=(1-line("'<")+line('.')) . "\t"<cr>'<"+y'>
nnoremap <leader>n vip:s/^/\=(1-line("'<")+line('.')) . "\t"<cr>'<"+y'>

" http://vimcasts.org/episodes/aligning-text-with-tabular-vim/
if exists(":Tabularize")
  nnoremap <Leader>a= :Tabularize /=<CR>
  vnoremap <Leader>a= :Tabularize /=<CR>
  nnoremap <Leader>a: :Tabularize /:\zs<CR>
  vnoremap <Leader>a: :Tabularize /:\zs<CR>
  nnoremap <Leader>a\| :Tabularize /\|\+<CR>
  vnoremap <Leader>a\| :Tabularize /\|\+<CR>
endif

" Split/Join {{{
"
" Basically this splits the current line into two new ones at the cursor position,
" then joins the second one with whatever comes next.
"
" Example:                      Cursor Here
"                                    |
"                                    V
" foo = ('hello', 'world', 'a', 'b', 'c',
"        'd', 'e')
"
"            becomes
"
" foo = ('hello', 'world', 'a', 'b',
"        'c', 'd', 'e')
"
" Especially useful for adding items in the middle of long lists/tuples in Python
" while maintaining a sane text width.
" http://twitter.com/dotvimrc/status/103878515337859072
" https://github.com/sjl/dotfiles/blob/e7ba3ddc165eb343ff7f0d6fd09bceb265186dfb/vim/.vimrc#L591-610
nnoremap K h/[^ ]<cr>"zd$jyyP^v$h"zpJk:s/\v +$//<cr>:noh<cr>j^
" }}}


" Press <C-b> in insert mode to calculate:
"  10+24*100<c-b>
"  10+24*100=2410
" http://twitter.com/dotvimrc/status/103161175033917442
inoremap <C-B> <C-O>yiW<End>=<C-R>=<C-R>0<CR>


set pastetoggle=<f12>

if has("windows")
  set clipboard=unnamed
  inoremap <C-V> <C-V>
  noremap <C-A> <C-A>
  noremap <C-X> <C-X>
endif

" Open the file under the curor, even if it's new
nnoremap gF :e <cfile><CR>

verbose command! -range -nargs=* Figlet <line1>,<line2>!figlet <args>
verbose command! -range -nargs=* Cowsay <line1>,<line2>!cowsay <args>
verbose command! -range -nargs=* Figsay <line1>,<line2>!figlet | cowsay -n

augroup FileTypes
  au!
  " TODO: Add a mapping to CDATA the selected visual block or motion.
  au BufNewFile,BufRead *.less setf less
  au BufNewFile,BufRead *.md setf markdown
  au BufRead,BufNewFile *.j2 setf html.jinja

  " http://twitter.com/dotvimrc/status/112171196153475073
  " http://twitter.com/dotvimrc/status/112192216633573376
  au Filetype qf setlocal colorcolumn=0 nolist nocursorline nowrap


  " Fold HTML tags with <localleader>f
  " http://twitter.com/dotvimrc/status/104209301882667008
  au FileType html setlocal foldmethod=manual
  au FileType html nnoremap <buffer> <localleader>f Vatzf

  " Open :help documents in a nice, big vertical split instead of a horizontal one
  " http://twitter.com/dotvimrc/status/103460040903626752
  au FileType help wincmd L

  " Add dashes to the list of "word characters" for CSS files:
  " http://twitter.com/dotvimrc/status/114423824161837056
  au Filetype css setlocal iskeyword+=-
augroup END
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.