dotfiles / .vimrc

  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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
" Initially based on the Vim distribution's example vimrc, with
" additional inspiration from all over the web.

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" General options {{{1
" Miscellaneous and Display {{{2

" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup                  " do not keep a backup file, use versions instead
else
  set backup                    " keep a backup file
  set backupdir=~/.autosave/vim " leave all the droppings in one place
endif

set history=500     " keep more command line history
set ruler           " show the cursor position all the time
set showcmd         " display commands as they're being entered
set incsearch       " do incremental searching
set ignorecase      " Do case insensitive matching
set smartcase       " But if search contains capitals, be sensitive
set gdefault        " Line-global substitution by default, usually what you want
set scrolloff=3     " Keep some context visible when scrolling
set sidescrolloff=4
set wildmenu        " Modern completion menu
set nowrap          " Default to no visual line
set number          " line numbers
set numberwidth=5   " a little bit of buffer is prettier

" wildmenu does shell-style completion AND tab-through
set wildmode=list:longest,full

" Ignore some extensions when tab-completing
set wildignore=*.swp,*.bak,*.pyc,*.o,*.class

" Only insert up to longest common autocomplete match
set completeopt+=longest

" Basically the default statusline when ruler is enabled, with fugitive
set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P

" automatically flush to disk when using :make, changing buffers, etc.
" Alternatively, set hidden to allow moving around and leaving dirty files be
"set autowrite
set hidden

" If file changed outside vim but not inside, just read it
set autoread

" use existing window if I try to open an already-open buffer
set switchbuf=useopen

" New h/v split window show up on bottom/right
set splitbelow splitright

" threshold for reporting number of lines changed
set report=0

" For modern standards in :TOhtml output
let html_use_css=1
let use_html=1

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp

" Silence CSApprox's gripes if running a vim without gui support
if !has('gui')
  let g:CSApprox_loaded = 1
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
  set cursorline
  colorscheme customtwilight  " last used: oceanblack
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Vundle has similar particularities about filetype initialization as
  " pathogen does
  filetype off
  runtime! include/bundles.vim

  " Enable file type detection, letting plugins, autocmds and such do all
  " their magic for custom language-dependent settings.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  augroup END

else

  set autoindent        " always set autoindenting on

endif " has("autocmd")

if has("viminfo")

  " Allow some global variables to persist between sessions
  " Plugins sometimes use this to retain useful things
  " % saves and restores buffer list when started with no args
  set viminfo^=!,%

endif

" Get a sweet :Man command to open pages in split
runtime ftplugin/man.vim
nmap K :Man <cword><CR>

" Indentation {{{2

" no-longer skinny tabs!
set tabstop=4

" set to the same as tabstop (see #4 in :help tabstop)
set shiftwidth=4

" if it looks like a tab, we can delete it like a tab
set softtabstop=4

" no tabs! spaces only..
set expandtab

" do not break lines when line length increases
set textwidth=0

" < and > will hit indentation levels instead of always -4/+4
set shiftround

" braces affect autoindentation
set smartindent

" Show matching brackets.
set showmatch
set matchtime=2

" figure out indent when ; is pressed
set cinkeys+=;

" align break with case in a switch
"set cinoptions+=b1

" Use attractive characters to show tabs & trailing spaces
set listchars=tab:»·,trail:·,eol,nbsp:␣

" Folding {{{2

set foldmethod=syntax   " try to fold in an intelligent manner based on ftplugins
set foldlevelstart=99   " default to all folds open when opening a buffer
set foldnestmax=4       " don't be absurd about how deeply to nest syntax folding
"set foldclose=all      " close a fold when I leave it
set foldopen-=block     " drives me nuts that moving with ] opens folds

" Colors {{{2

" These might be desired depending on colorscheme
"highlight LineNr  term=underline    ctermfg=grey    guifg=grey
"highlight CursorLine    guibg=Grey10
" No hideous pink default autocomplete menu
"highlight PMenu gui=bold guibg=#CECECE guifg=#444444

" Autocommands {{{2
if has("autocmd")

  augroup BufActions
    autocmd!

    " When editing a file, always jump to the last known cursor position. {{{
    " Don't do it when the position is invalid or when inside an event handler
    " (happens when dropping a file on gvim), or for commit messages.
    autocmd BufReadPost * call SetCursorPosition()
    function! SetCursorPosition()
      if &filetype !~ 'commit\c'
        if line("'\"") > 0 && line("'\"") <= line("$")
          exe "normal g`\""
          normal! zz
        endif
      end
    endfunction
    "}}}
  
    " Skeletons {{{
    autocmd BufNewFile *.py silent 0read ~/.vim/skeleton/skeleton.py   | normal G
    autocmd BufNewFile *.sh silent 0read ~/.vim/skeleton/skeleton.sh   | normal G
    "autocmd BufNewFile *.pl silent 0read ~/.vim/skeleton/perl.pl     | normal G
    "autocmd BufNewFile *.t  silent 0read ~/.vim/skeleton/perl-test.t | normal G
    "autocmd BufNewFile *.c  silent 0read ~/.vim/skeleton/c.c         | normal 4j$
    "autocmd BufNewFile *.hs silent 0read ~/.vim/skeleton/haskell.hs  | normal Gk$
    "}}}

    " Auto file perms {{{
    autocmd BufNewFile */.netrc,*/.fetchmailrc,*/.my.cnf let b:chmod_new="go-rwx"
    autocmd BufNewFile  * let b:chmod_exe=1
    autocmd BufWritePre * if exists("b:chmod_exe") |
          \ unlet b:chmod_exe |
          \ if getline(1) =~ '^#!' | let b:chmod_new="+x" | endif |
          \ endif
    autocmd BufWritePost,FileWritePost * if exists("b:chmod_new")|
          \ silent! execute "!chmod ".b:chmod_new." <afile>"|
          \ unlet b:chmod_new|
          \ endif
    "}}}

    " Automatically distribute my vimrc to the servers I use {{{
    "autocmd BufWritePost ~/.vimrc !scp ~/.vimrc valleyofwind.dyndns.org:.
    "autocmd BufWritePost ~/.vim/skeletons/* !scp % valleyofwind.dyndns.org:.vim/skeletons/
    "}}}

  augroup END

endif " has("autocmd")
" Remappings {{{1

" I'm drinkin' the comma-as-leader kool aid
let mapleader = ","

" Omni completion shortcut
imap <M-space> <C-x><C-o><C-p>

" See tpope's wicked Run() function -- I'd like to cook up something
" similar ror ruby, pyflakes/pep8, etc.
map <F2> :cprev<CR>
map <F3> :wa<Bar>make<CR>
map <F4> :cnext<CR>

" Easy paste mode toggling
set pastetoggle=<F6>

" Toggle search hilighting
map <silent> <F11> :set invhlsearch<CR>
imap <silent> <F11> <C-o>:set invhlsearch<CR>
vmap <silent> <F11> :<C-u>set invhlsearch<CR>gv

" It's a fast-moving world these days -- does your scrolling keep up?
noremap <C-y> 2<C-y>
noremap <C-e> 2<C-e>

" Yank from cursor to end of line, to be consistent with C and D.
nnoremap Y y$

" Why so much hand lifting pain for command editing?
" Allow Emacs/readline-like keys.
cnoremap <C-A>      <Home>
cnoremap <C-B>      <Left>
cnoremap <C-E>      <End>
cnoremap <C-F>      <Right>
cnoremap <C-N>      <Down>
cnoremap <C-P>      <Up>
if has('mac')
  cnoremap <M-b>      <S-Left>
  cnoremap <M-f>      <S-Right>
  cnoremap <M-BS>     <C-W>
else
  cnoremap <ESC>b     <S-Left>
  cnoremap <ESC><C-B> <S-Left>
  cnoremap <ESC>f     <S-Right>
  cnoremap <ESC><C-F> <S-Right>
  cnoremap <ESC><C-H> <C-W>
endif

" Easy window split navigation {{{
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
map <C-h> <C-w>h

" Toggle a window's height stickiness, so C-w = doesn't equalize it
nmap <leader>` :set invwinfixheight winfixheight?<CR>

" QuickLook the current file. With Brett Terpstra's awesome CSS fork of
" the MMD QuickLook plugin, this sure beats browser-based Markdown preview.
if has('mac')
  nnoremap <Leader>ql :write<CR>:sil !qlmanage -p % >& /dev/null &<CR>:redraw!<CR>
  nnoremap <Leader>qlk :sil !killall qlmanage >& /dev/null<CR>
endif

" Gross, but I'm tired of trying to get various terminal emulators to emit
" consistent fucking escape sequences. These, for now, are whatever iTerm2 in
" xterm-256color mode emits for function keys...
"
" http://stackoverflow.com/questions/3519532/mapping-function-keys-in-vim
" http://stackoverflow.com/questions/9950944/binding-special-keys-as-vim-shortcuts
if has('mac') && ($TERM == 'xterm-256color' || $TERM == 'screen-256color')
  map <Esc>OP <F1>
  map <Esc>OQ <F2>
  map <Esc>OR <F3>
  map <Esc>OS <F4>
  map <Esc>[16~ <F5>
  map <Esc>[17~ <F6>
  map <Esc>[18~ <F7>
  map <Esc>[19~ <F8>
  map <Esc>[20~ <F9>
  map <Esc>[21~ <F10>
  map <Esc>[23~ <F11>
  map <Esc>[24~ <F12>

  imap <Esc>[17~ <F6>
  imap <Esc>[23~ <F11>
endif
"}}}

" Lotsa TextMate-inspired Mappings
runtime include/textmate-mappings.vim

" Language- and plugin-specific Preferences {{{1
if has("autocmd")

  augroup FiletypeSets "{{{
    autocmd!
    autocmd BufNewFile,BufRead jquery.*.js set ft=javascript syntax=jquery
    autocmd BufNewFile,BufRead *.mako set ft=mako
    autocmd BufNewFile,BufRead Rakefile,Capfile,Gemfile,Vagrantfile set ft=ruby
    " Keep the multiplying zombie virus-infected fugitive buffer hoard at bay
    autocmd BufReadPost fugitive://* set bufhidden=delete
  augroup END "}}}

  " TODO: might soon want to start organizing this ballooning group of stuff
  " in after/ftplugin files :-)
  augroup FToptions "{{{
    autocmd!
    autocmd FileType html,xhtml,xml,htmldjango,htmljinja,eruby,mako,cucumber setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
    autocmd FileType coffee,ruby,vim,yaml setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
    autocmd FileType javascript setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4
    autocmd User Rails.javascript* setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4

    " Use leader+space to write and execute
    autocmd FileType vim map <buffer> <leader><space> :w!<cr>:source %<cr>
    autocmd FileType sh map <buffer> <leader><space> :w!<cr>:!/bin/sh %<cr>
    autocmd FileType ruby map <buffer> <leader><space> :w!<cr>:!ruby %<cr>
    autocmd FileType python map <buffer> <leader><space> :w!<cr>:!python %<cr>

    " Be trusting about Ruby code being evaluated for autocompletion
    autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
    autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
    autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
    " Easily lookup documentation on apidock
    autocmd FileType ruby noremap <buffer> <leader>rb :OpenURL http://apidock.com/rails/<cword><CR>
    autocmd FileType ruby noremap <buffer> <leader>rr :OpenURL http://apidock.com/ruby/<cword><CR>

    autocmd FileType python nnoremap <silent> <buffer> K :call ShowPyDoc(expand("<cword>"), 1)<CR>
    autocmd FileType python nnoremap <silent> <buffer> <F5> :call Pep8()<CR>
    " autocmd FileType python setlocal cinwords=if,elif,else,for,while,try,except,finally,def,class,with

    autocmd FileType javascript let javascript_enable_domhtmlcss=1
    autocmd FileType xml let xml_use_xhtml = 1 " default xml to self-closing tags
    autocmd FileType vim setlocal keywordprg=:help

    autocmd FileType markdown nnoremap <buffer> <leader>1 yypVr=
    autocmd FileType markdown nnoremap <buffer> <leader>2 yypVr-
    autocmd FileType markdown setlocal linebreak

    autocmd FileType vimwiki setlocal foldlevel=2 textwidth=78 linebreak
    autocmd FileType vimwiki map <buffer> <M-Space> <Plug>VimwikiToggleListItem
    autocmd FileType vimwiki map <buffer> <Leader>wg :VimwikiGoto<space>
    autocmd FileType vimwiki map <buffer> <Leader>w/ :VimwikiSearch<space>/

    autocmd FileType text,markdown,gitcommit,vimwiki setlocal spell
    autocmd FileType help,man,qf nnoremap <silent><buffer> q :q<CR>
  augroup END "}}}

  let python_highlight_all = 1

  " TagBar
  runtime include/tagbar-types.vim
  let g:tagbar_autoclose = 1

  " Shifted version of NERDTree toggle
  map <Leader>< :TagbarToggle<CR>

  " NERDTree
  let NERDTreeWinPos          = 'right'
  let NERDTreeShowBookmarks   = 1
  let NERDTreeQuitOnOpen      = 1      " hide after opening a file
  let NERDTreeHijackNetrw     = 0      " I like netrw when I `:e somedir`
  let NERDTreeIgnore          = ['\.git','\.hg','\.svn','\.DS_Store']

  " NERDCommenter
  let NERDSpaceDelims         = 1      " use a space after comment chars
  let NERDDefaultAlign        = 'left'
  " Not cool when end-of-line comments break when uncommenting /* */ blocks:
  let NERDRemoveAltComs       = 0

  " TagmaTasks
  let g:TagmaTasksHeight   = 8
  let g:TagmaTasksTokens   = ['FIXME', 'TODO', 'NOTE', 'XXX', 'OPTIMIZE', 'PONY']
  let g:TagmaTasksJumpTask = 0
  " The plugin's jump mappings conflict with Unimpaired's tag nav
  let g:TagmaTasksJumpKeys = 0
  " Defaults to lowercase t, which would make CommandT slow
  let g:TagmaTasksPrefix = '<Leader>T'

  " Open the YankRing window
  nnoremap <silent> <M-v> :YRShow<CR>
  let g:yankring_history_dir = '$HOME/.autosave/vim'

  " Make sure YankRing plays nice with custom remapping.
  " See `:h yankring-custom-maps`
  function! YRRunAfterMaps()
    nnoremap <silent> Y   :<C-U>YRYankCount 'y$'<CR>
  endfunction

  let g:dbext_default_history_file = '$HOME/.autosave/vim'

  " Lusty Juggler buffer switcher
  let g:LustyJugglerShowKeys = 'a'
  let g:LustyJugglerSuppressRubyWarning = 1
  nmap <silent> <leader>b :LustyJuggler<CR>

  " Gist
  let g:gist_put_url_to_clipboard_after_post  = 1
  let g:gist_show_privates                    = 1
  " detect filetype if vim failed autodetection
  let g:gist_detect_filetype                  = 1
  if has('mac')
    let g:gist_clip_command                   = 'pbcopy'
  endif

  " Don't want this, and it fucks up LustyJuggler and Endwise
  let g:SuperTabCrMapping = 0

  " Vimwiki {{{
  " My custom functions below define a web link handler
  let g:vimwiki_menu      = 'Plugin.Vimwiki'
  let g:vimwiki_use_mouse = 1  " A rare case where I may actually use the mouse :-)
  let g:vimwiki_folding   = 1

  let main_wiki           = {}
  let main_wiki.path      = '~/src/vimwiki'
  let main_wiki.path_html = '~/src/vimwiki/html'
  let main_wiki.nested_syntaxes =
    \ {'python': 'python', 'ruby': 'ruby', 'sh': 'sh', 'vimscript': 'vim'}

  " 'diary' makes me feel like a teenage girl
  let main_wiki.diary_rel_path = 'journal/'
  let main_wiki.diary_index    = 'journal'
  let main_wiki.diary_header   = 'Journal'

  let g:vimwiki_list      = [main_wiki]
  " }}}

endif " has("autocmd")

" Plugin Mappings {{{2

" Ack Search
map <Leader>a :Ack!<space>
map <Leader>n :AckFromSearch!<CR>

" NERD tree - double-leader
map <Leader><Leader> :NERDTreeToggle<cr>

" Command-T's <Leader>t default is good for files, but I use <Leader>b already
map <Leader>f :CommandTBuffer<CR>

" Ready for tab-completion of named Tabular patterns
" Choosing 'gq' since it's similar function to the format command
map <Leader>gq :Tabularize<space>

if has('python')
  " UltiSnips
  let g:UltiSnipsExpandTrigger       = "<tab>"
  let g:UltiSnipsJumpForwardTrigger  = "<tab>"
  let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
  nmap <Leader>rs :py UltiSnips_Manager.reset()<CR>

  " Gundo
  nnoremap <F7> :GundoToggle<CR>
  let g:gundo_preview_bottom = 1     " force wide window across bottom

  " Sparkup
  " Way to default to a mapping that conflicts with scrolling, guy (<C-e>)...
  let g:sparkupExecuteMapping = "<M-s>"

  " ConqueTerm - namespace of 'q' kinda makes sense to me
  " mnemonic: terminal - don't like 'shell' because 'qs' is slow to type
  nmap <Leader>qt :ConqueTermSplit bash<CR>
  " mnemonic: command
  nmap <Leader>qc :ConqueTermSplit<space>
  let g:ConqueTerm_CloseOnEnd = 1
  " Exec current file in new split term. By default this conflicts with my
  " <F11> mapping for toggling hlsearch. <F10> execs current file in last-used
  " existing term, so let's use the shifted version of that
  let g:ConqueTerm_ExecFileKey = '<S-F10>'

else

  let g:gundo_disable = 1

endif

" VCSCommand {{{3

" The defaults (prefix of <leader>c) conflict with NERDCommenter, and
" I don't really like them anyway...
" FIXME: the bang commands don't work
map <Leader>va :VCSAdd<CR>
" 'Blame' is the most natural mnemonic for me
map <Leader>vb :VCSAnnotate<CR>
map <Leader>vB :VCSAnnotate!<CR>
map <Leader>vc :VCSCommit<CR>
map <Leader>vD :VCSDelete<CR>
map <Leader>vd :VCSDiff<CR>
map <Leader>vv :VCSVimDiff<CR>
" Close VCS scratch buffer and return - mnemonic: eXit :-)
map <silent> <Leader>vx :VCSGotoOriginal!<CR>
map <Leader>vl :VCSLog<CR>
" I think I'm far too likely to try 'r' for 'remove' all the time...
map <Leader>vR :VCSReview<CR>
map <Leader>vs :VCSStatus<CR>

" Fugitive
noremap <C-g>s :Gstatus<CR>
noremap <C-g>c :Gcommit<CR>
noremap <C-g>d :Gdiff<CR>
noremap <C-g>l :Glog<CR>
noremap <C-g>w :Gwrite<CR>
noremap <C-g>b :Gblame<CR>

noremap <C-g>v :Gitv --all<CR>
noremap <C-g>V :Gitv! --all<CR>

" Specky - RSpec plugin {{{3

let g:speckyBannerKey = "<C-S>b"
let g:speckyQuoteSwitcherKey = "<C-S>'"
let g:speckyRunRdocKey = "<C-S>r"
let g:speckySpecSwitcherKey = "<C-S>x"
let g:speckyRunSpecKey = "<C-S>s"
"let g:speckyRunSpecCmd = "spec -fs"
let g:speckyRunRdocCmd = "qri -f plain"
let g:speckyWindowType = 1      " Horizontal split

" Custom Functions {{{1

" Mappings below use this generalized function to strip trailing white space,
" or reformat the file, preserving cursor position, etc.
" Hat tip: http://vimcasts.org/episodes/tidying-whitespace/
function! Preserve(command)
  " Preserve cursor position and last search
  let _s=@/
  let l = line(".")
  let c = col(".")
  " Do the damn thang
  execute a:command
  " Restore the saved bits
  let @/=_s
  call cursor(l, c)
endfunction
nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
nmap _= :call Preserve("normal gg=G")<CR>

" Rails.vim and others call this by naming convention for various
" browser-opening functions
function! OpenURL(url)
  if has('mac')
    let g:browser = 'open '
  endif
  exec 'silent !'.g:browser.' '.a:url
endfunction
command! -nargs=1 OpenURL :call OpenURL(<q-args>)

nnoremap gG :OpenURL http://www.google.com/search?q=<cword><CR>
nnoremap gW :OpenURL http://en.wikipedia.org/wiki/Special:Search?search=<cword><CR>

function! VimwikiWeblinkHandler(weblink)
  call OpenURL(a:weblink)
endfunction

if has('python')
  " Just starting to play with possibilities here :-)
  function! MyConqueStartup(term)
    let syntax_associations = { 'mongo': 'javascript' }

    if has_key(syntax_associations, a:term.program_name)
      execute 'setlocal syntax=' . syntax_associations[a:term.program_name]
    endif
  endfunction

  call conque_term#register_function('after_startup', 'MyConqueStartup')
endif

" Commands {{{1

" Stolen shamelessly from tpope
if has("eval")
  command! -bar -nargs=1 -complete=file E :exe "edit ".substitute(<q-args>,'\(.*\):\(\d\+\):\=$','+\2 \1','')
  command! -bar -nargs=0 SudoW   :setl nomod|silent exe 'write !sudo tee % >/dev/null'|let &mod = v:shell_error
  command! -bar -nargs=* -bang W :write<bang> <args>
  command! -bar -nargs=0 -bang Scratch :silent edit<bang> \[Scratch]|set buftype=nofile bufhidden=hide noswapfile buflisted
  command! -bar -count=0 RFC     :e http://www.ietf.org/rfc/rfc<count>.txt|setl ro noma
  command! -bar -nargs=* -bang -complete=file Rename :
        \ let v:errmsg = ""|
        \ saveas<bang> <args>|
        \ if v:errmsg == ""|
        \   call delete(expand("#"))|
        \ endif
endif

" Plugin distributed with Vim to bring forward existing session w/ open file
runtime! macros/editexisting.vim

" vim:foldmethod=marker commentstring="%s
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.