Source

myhome / .vimrc

The default branch has multiple heads

Full commit
   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
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
" How To Setup vim:"{{{
"       mkdir ~/.bundle
"       cd ~/.bundle
"       git clone https://github.com/Shougo/neobundle.vim.git
"
"       start vim.  :NeoBundleInstall
" }}}
"
" TODO :"{{{
" query-replace
" neocomplcache & tafile 補完  VTB P189
" Japanese man
" ref && unite, ruby, python
" erlang man
" erlangでomniのC-x C-oをneocomplcacheと連携させる
" }}}

" Initialize:"{{{
"
fun! MySys()
  return "linux"
endfun

let s:iswin = has('win32') || has('win64')

" Set augroup.
augroup MyAutoCmd
  autocmd!
augroup END

filetype off
if has('vim_starting')
  " Load neobundle.
  if &runtimepath !~ '/neobundle.vim'
    execute 'set runtimepath+=' . expand('~/.bundle/neobundle.vim')
  endif
  call neobundle#rc(expand('~/.bundle'))
endif

" vimshell
NeoBundle 'https://github.com/Shougo/vimshell.git'

" filer
NeoBundle 'https://github.com/Shougo/vimfiler.git'

" binary editor
NeoBundle 'https://github.com/Shougo/vinarise.git'

" Unite
NeoBundle 'https://github.com/Shougo/unite.vim.git'
NeoBundle 'https://github.com/h1mesuke/unite-outline.git'
NeoBundle 'https://github.com/tsukkee/unite-tag.git'
NeoBundle 'https://github.com/tsukkee/unite-help.git'
NeoBundle 'https://github.com/thinca/vim-unite-history.git'
NeoBundle 'https://github.com/tacroe/unite-mark.git'

" vimdoc
NeoBundle 'https://github.com/vim-jp/vimdoc-ja.git'

" tasklist
NeoBundle 'https://github.com/vim-scripts/TaskList.vim.git'

" source Reading
NeoBundle 'https://github.com/vim-scripts/Source-Explorer-srcexpl.vim'
NeoBundle 'https://github.com/vim-scripts/taglist.vim.git'
NeoBundle 'https://github.com/vim-scripts/trinity.vim.git'

" Programing
NeoBundle 'https://github.com/vim-scripts/errormarker.vim.git'
NeoBundle 'https://github.com/vim-scripts/bash-support.vim.git'
NeoBundle 'https://github.com/oscarh/vimerl.git'
NeoBundle 'https://github.com/tpope/vim-rails.git'
NeoBundle 'https://github.com/thinca/vim-quickrun.git'
NeoBundle 'https://github.com/anyakichi/vim-surround'
NeoBundle 'https://github.com/mattn/zencoding-vim.git'
NeoBundle 'https://github.com/hail2u/vim-css3-syntax.git'
NeoBundle 'https://github.com/cakebaker/scss-syntax.vim.git'
NeoBundle 'https://github.com/thinca/vim-ref.git'
NeoBundle 'https://github.com/msanders/snipmate.vim.git'

" text
NeoBundle 'https://github.com/vim-scripts/VimOutliner.git'

" markdown
NeoBundle 'https://github.com/plasticboy/vim-markdown/' "http://vim-users.jp/2009/08/hack52/
NeoBundle 'https://github.com/mattn/mkdpreview-vim.git'
NeoBundle 'https://github.com/mattn/webapi-vim.git'

" open-browser
NeoBundle 'https://github.com/tyru/open-browser.vim.git'

" object
NeoBundle 'https://github.com/kana/vim-textobj-indent.git'
NeoBundle 'https://github.com/kana/vim-textobj-user.git'
NeoBundle 'https://github.com/kana/vim-textobj-fold.git'

" environmnt
NeoBundle 'https://github.com/Shougo/vimproc.git'
NeoBundle 'https://github.com/thinca/vim-poslist.git'
NeoBundle 'https://github.com/tpope/vim-repeat.git'
NeoBundle 'https://github.com/tomtom/tcomment_vim.git'
NeoBundle 'https://github.com/vim-scripts/sudo.vim.git'
NeoBundle 'https://github.com/Shougo/neocomplcache.git'
NeoBundle 'https://github.com/Shougo/neobundle.vim.git'
NeoBundle 'https://github.com/kana/vim-tabpagecd.git'
NeoBundle 'https://github.com/Lokaltog/vim-powerline.git'
NeoBundle 'https://github.com/thinca/vim-fontzoom.git'
NeoBundle 'https://github.com/vim-scripts/ShowMarks.git'
NeoBundle 'https://github.com/vim-scripts/number-marks.git'
NeoBundle 'https://github.com/chrismetcalf/vim-yankring.git'
NeoBundle 'https://github.com/houtsnip/vim-emacscommandline.git'
NeoBundle 'https://github.com/Lokaltog/vim-easymotion.git'
NeoBundle 'https://github.com/vim-scripts/matchit.zip.git'
NeoBundle 'https://github.com/nathanaelkane/vim-indent-guides.git'
NeoBundle 'https://github.com/tpope/vim-speeddating.git'
NeoBundle 'https://github.com/gregsexton/VimCalc.git'
NeoBundle 'https://github.com/tsaleh/vim-align.git'


" filetype plugin on
" filetype indent on
"}}}

" => General {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=300

" Enable filetype plugin
filetype on
filetype plugin on
filetype indent on

" Set to auto read when a file is changed from the outside
set autoread

" https://sites.google.com/site/vimdocja/fold-html
" Enable folding.
set foldenable
" set foldmethod=expr
set foldmethod=marker
" Show folding level.
set foldcolumn=3

" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","

" Fast saving
nmap <leader>w :w!<cr>

" Fast editing of the .vimrc
map <leader>e :e! ~/.vimrc<cr>

" When vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/.vimrc

" set system $PATH
" http://vim.1045645.n5.nabble.com/setting-vim-path-to-coincide-always-with-the-system-path-td1171918.html
" let &path=tr(expand("$PATH"),":",",") 
let &path=tr(expand("$PATH"),":",",") 
"}}}

" => edit {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
:au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
"}}}

" => move {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" poslist.vim VTB P106
map <C-o> <Plug>(poslist-prev-pos)
map <C-i> <Plug>(poslist-next-pos)
map <Leader><C-o> <Plug>(poslist-prev-buf)
map <Leader><C-i> <Plug>(poslist-next-buf)
let g:poslist_histsize = 1000

" Context sensitive H,L."{{{
nnoremap <silent> H :<C-u>call HContext()<CR>
nnoremap <silent> L :<C-u>call LContext()<CR>
xnoremap <silent> H <ESC>:<C-u>call HContext()<CR>mzgv`z
xnoremap <silent> L <ESC>:<C-u>call LContext()<CR>mzgv`z
function! HContext()
  let moved = MoveCursor("H")
  if !moved && line('.') != 1
    execute "normal! " . "\<pageup>H"
  endif
endfunction
function! LContext()
  let moved = MoveCursor("L")

  if !moved && line('.') != line('$')
    execute "normal! " . "\<pagedown>L"
  endif
endfunction
function! MoveCursor(key)
  let cnum = col('.')
  let lnum = line('.')
  let wline = winline()

  execute "normal! " . v:count . a:key
  let moved =  cnum != col('.') || lnum != line('.') || wline != winline()

  return moved
endfunction
"}}}

" Smart home and smart end."{{{
nnoremap <silent> gh  :<C-u>call SmartHome("n")<CR>
nnoremap <silent> gl  :<C-u>call SmartEnd("n")<CR>
xnoremap <silent> gh  <ESC>:<C-u>call SmartHome("v")<CR>
xnoremap <silent> gl  <ESC>:<C-u>call SmartEnd("v")<CR>
nnoremap <expr> gm    (virtcol('$')/2).'\|'
xnoremap <expr> gm    (virtcol('$')/2).'\|'
" Smart home function"{{{
function! SmartHome(mode)
  let curcol = col('.')

  if &wrap
    normal! g^
  else
    normal! ^
  endif
  if col('.') == curcol
    if &wrap
      normal! g0
    else
      normal! 0
    endif
  endif

  if a:mode == "v"
    normal! msgv`s
  endif

  return ""
endfunction"}}}

" Smart end function"{{{
function! SmartEnd(mode)
  let curcol = col('.')
  let lastcol = a:mode ==# 'i' ? col('$') : col('$') - 1

  " Gravitate towards ending for wrapped lines
  if curcol < lastcol - 1
    call cursor(0, curcol + 1)
  endif

  if curcol < lastcol
    if &wrap
      normal! g$
    else
      normal! $
    endif
  else
    normal! g_
  endif

  " Correct edit mode cursor position, put after current character
  if a:mode == "i"
    call cursor(0, col(".") + 1)
  endif

  if a:mode == "v"
    normal! msgv`s
  endif

  return ""
endfunction "}}}
"}}}
"}}}

" => copy/paste to/from clipboard. {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"copy yankbuffer to system clipboard.
set clipboard+=unnamed
command! Fy let @+=@"

" 行末までyank
nnoremap Y y$

" http://d.hatena.ne.jp/Riverman/20090217/1234884855
if has('unix')
  vmap <C-c> "+y
  nmap <C-c> "+y
  " 挿入モード時、クリップボードから貼り付け
  imap <C-V> <ESC>"+pa
  " 選択部分をクリップボードの値に置き換え
  vmap <C-V> d"+P
  " コマンドライン時、クリップボードから貼り付け
  cmap <C-V> <C-R>+
  " 選択部分をクリップボードに切り取り
  vmap <C-X> "+d<ESC>
endif
if has('win32')
  vmap <C-c> "*y
  nmap <C-c> "*y
  " 挿入モード時、クリップボードから貼り付け
  imap <C-V> <ESC>"*pa
  " 選択部分をクリップボードの値に置き換え
  vmap <C-V> d"*P
  " コマンドライン時、クリップボードから貼り付け
  cmap <C-V> <C-R>*
  " 選択部分をクリップボードに切り取り
  vmap <C-X> "*d<ESC>
endif

" Convert slashes to backslashes for Windows.
" http://vim.wikia.com/wiki/Copy_filename_to_clipboard
if has('win32')
  nmap <leader>cs :let @*=substitute(expand("%"), "/", "\\", "g")<CR>
  nmap <leader>cl :let @*=substitute(expand("%:p"), "/", "\\", "g")<CR>

  " This will copy the path in 8.3 short format, for DOS and Windows 9x
  nmap <leader>c8 :let @*=substitute(expand("%:p:8"), "/", "\\", "g")<CR>
else
  nmap <leader>cs :let @+=expand("%")<CR>
  nmap <leader>cl :let @+=expand("%:p")<CR>
endif
"}}}

" => VIM user interface {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the curors - when moving vertical..
set so=7

set wildmenu "Turn on WiLd menu

set ruler "Always show current position

set cmdheight=2 "The commandbar height

set hid "Change buffer - without saving

" Set backspace config
set backspace=eol,start,indent
set whichwrap+=<,>,h,l

set ignorecase "Ignore case when searching

set hlsearch "Highlight search things

set incsearch "Make search act like search in modern browsers

set magic "Set magic on, for regular expressions

set showmatch "Show matching bracets when text indicator is over them
set mat=2 "How many tenths of a second to blink

" No sound on errors
set noerrorbells
set novisualbell
set t_vb=

" Escを2回押したらハイライトをやめる
nnoremap <Esc><Esc> :<C-u>set nohlsearch<Return>
nnoremap / :<C-u>set hlsearch<Return>/
nnoremap ? :<C-u>set hlsearch<Return>?
nnoremap * :<C-u>set hlsearch<Return>*
nnoremap # :<C-u>set hlsearch<Return>#

" word complete like zsh
set wildmode=longest,list
"}}}

" => Colors and Fonts {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable "Enable syntax hl

set gfn=Inconsolata:h18

" Set font according to system
"if MySys() == "mac"
"  set gfn=Bitstream\ Vera\ Sans\ Mono:h13
"  set shell=/bin/bash
"elseif MySys() == "windows"
"  set gfn=Bitstream\ Vera\ Sans\ Mono:h10
"elseif MySys() == "linux"
 " set gfn=Monospace\ 10
  " set gfn=VL\ ゴシック\ 10
set guifont=VL\ ゴシック\ 10

"  set shell=/bin/bash
"endif

if has("gui_running")
  set guioptions-=T
  set guioptions+=m
  set background=dark
  set t_Co=256
  set background=dark
  "colorscheme moria
  "colorscheme twilight
  colorscheme candy
  set nu
else
  colorscheme zellner
  set background=dark

  set nonu
endif

"set encoding=utf8
"try
"    lang en_US
"catch
"endtry

"set ffs=unix,dos,mac "Default file types
"}}}

" エンコーディング関連 Encoding {{{
"-------------------------------------------------------------------------------
set ffs=unix,dos,mac  " 改行文字
set encoding=utf-8    " デフォルトエンコーディング

" 文字コード関連
" from ずんWiki http://www.kawaz.jp/pukiwiki/?vim#content_1_7
" 文字コードの自動認識
if &encoding !=# 'utf-8'
  set encoding=japan
  set fileencoding=japan
endif
if has('iconv')
  let s:enc_euc = 'euc-jp'
  let s:enc_jis = 'iso-2022-jp'
  " iconvがeucJP-msに対応しているかをチェック
  if iconv("\x87\x64\x87\x6a", 'cp932', 'eucjp-ms') ==# "\xad\xc5\xad\xcb"
    let s:enc_euc = 'eucjp-ms'
    let s:enc_jis = 'iso-2022-jp-3'
  " iconvがJISX0213に対応しているかをチェック
  elseif iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb"
    let s:enc_euc = 'euc-jisx0213'
    let s:enc_jis = 'iso-2022-jp-3'
  endif
  " fileencodingsを構築
  if &encoding ==# 'utf-8'
    let s:fileencodings_default = &fileencodings
    let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932'
    let &fileencodings = &fileencodings .','. s:fileencodings_default
    unlet s:fileencodings_default
  else
    let &fileencodings = &fileencodings .','. s:enc_jis
    set fileencodings+=utf-8,ucs-2le,ucs-2
    if &encoding =~# '^\(euc-jp\|euc-jisx0213\|eucjp-ms\)$'
      set fileencodings+=cp932
      set fileencodings-=euc-jp
      set fileencodings-=euc-jisx0213
      set fileencodings-=eucjp-ms
      let &encoding = s:enc_euc
      let &fileencoding = s:enc_euc
    else
      let &fileencodings = &fileencodings .','. s:enc_euc
    endif
  endif
  " 定数を処分
  unlet s:enc_euc
  unlet s:enc_jis
endif
" 日本語を含まない場合は fileencoding に encoding を使うようにする
if has('autocmd')
  function! AU_ReCheck_FENC()
    if &fileencoding =~# 'iso-2022-jp' && search("[^\x01-\x7e]", 'n') == 0
      let &fileencoding=&encoding
    endif
  endfunction
  autocmd BufReadPost * call AU_ReCheck_FENC()
endif
" 改行コードの自動認識
set fileformats=unix,dos,mac
" □とか○の文字があってもカーソル位置がずれないようにする
if exists('&ambiwidth')
  set ambiwidth=double
endif

" cvsの時は文字コードをeuc-jpに設定
autocmd FileType cvs :set fileencoding=euc-jp
" 以下のファイルの時は文字コードをutf-8に設定
autocmd FileType svn :set fileencoding=utf-8
autocmd FileType js :set fileencoding=utf-8
autocmd FileType css :set fileencoding=utf-8
autocmd FileType html :set fileencoding=utf-8
autocmd FileType xml :set fileencoding=utf-8
autocmd FileType java :set fileencoding=utf-8
autocmd FileType scala :set fileencoding=utf-8

" ワイルドカードで表示するときに優先度を低くする拡張子
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc

" 指定文字コードで強制的にファイルを開く
command! Cp932 edit ++enc=cp932
command! Eucjp edit ++enc=euc-jp
command! Iso2022jp edit ++enc=iso-2022-jp
command! Utf8 edit ++enc=utf-8
command! Jis Iso2022jp
command! Sjis Cp932
"}}}

" => Files and backups {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile
"}}}

" => Text, tab and indent related {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set expandtab
set shiftwidth=4
set tabstop=4
set smarttab

set textwidth=0

set lbr
set tw=500

set ai "Auto indent
set si "Smart indet
set wrap "Wrap lines

map <leader>t2 :setlocal shiftwidth=2<cr>
map <leader>t4 :setlocal shiftwidth=4<cr>
map <leader>t8 :setlocal shiftwidth=4<cr>
"}}}

" => Visual mode related {{{
""""""""""""""""""""""""""""""
set virtualedit=block " VTD P154

vnoremap < <gv
vnoremap > >gv

" Really useful!
"  In visual mode when you press * or # to search for the current selection
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>

" When you press gv you vimgrep after the selected text
vnoremap <silent> gv :call VisualSearch('gv')<CR>
map <leader>g :vimgrep // **/*.<left><left><left><left><left><left><left>

function! CmdLine(str)
    exe "menu Foo.Bar :" . a:str
    emenu Foo.Bar
    unmenu Foo
endfunction

" From an idea by Michael Naumann
function! VisualSearch(direction) range
    let l:saved_reg = @"
    execute "normal! vgvy"

    let l:pattern = escape(@", '\\/.*$^~[]')
    let l:pattern = substitute(l:pattern, "\n$", "", "")

    if a:direction == 'b'
        execute "normal ?" . l:pattern . "^M"
    elseif a:direction == 'gv'
        call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
    elseif a:direction == 'f'
        execute "normal /" . l:pattern . "^M"
    endif

    let @/ = l:pattern
    let @" = l:saved_reg
endfunction
"}}}

" => Command mode related {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Smart mappings on the command line
cno $h e ~/
cno $d e ~/Desktop/
cno $j e ./
cno $c e <C-\>eCurrentFileDir("e")<cr>

" $q is super useful when browsing on the command line
cno $q <C-\>eDeleteTillSlash()<cr>

" Bash like keys for the command line
cnoremap <C-A>    <Home>
cnoremap <C-E>    <End>
cnoremap <C-K>    <C-U>

cnoremap <C-P> <Up>
cnoremap <C-N> <Down>

func! Cwd()
  let cwd = getcwd()
  return "e " . cwd
endfunc

func! DeleteTillSlash()
  let g:cmd = getcmdline()
  if MySys() == "linux" || MySys() == "mac"
    let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "")
  else
    let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "")
  endif
  if g:cmd == g:cmd_edited
    if MySys() == "linux" || MySys() == "mac"
      let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "")
    else
      let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "")
    endif
  endif
  return g:cmd_edited
endfunc

func! CurrentFileDir(cmd)
  return a:cmd . " " . expand("%:p:h") . "/"
endfunc
"}}}

" => Moving around, tabs and buffers {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" http://d.hatena.ne.jp/yuroyoro/20101104/1288879591
" カーソル行をハイライト
set cursorline
" カレントウィンドウにのみ罫線を引く
augroup cch
autocmd! cch
autocmd WinLeave * set nocursorline
autocmd WinEnter,BufRead * set cursorline
augroup END
hi clear CursorLine
hi CursorLine gui=underline
" highlight CursorLine ctermbg=black guibg=black

" Smart way to move btw. windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

" Close the current buffer
map <leader>bd :Bclose<cr>

" Close all the buffers
map <leader>ba :1,300 bd!<cr>

" Use the arrows to something usefull
map <right> :bn<cr>
map <left> :bp<cr>

"map <C-right> :tabnext<cr>
"map <C-left> :tabprevious<cr>

" Tab configuration
map <leader>tn :tabnew %<cr>
map <leader>te :tabedit
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove

map <leader>th :tabprevious<cr>
map <leader>tl :tabnext<cr>

" When pressing <leader>cd switch to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>

" Move last modified text.
nnoremap gb `.zz
nnoremap g, g;
nnoremap g; g,

command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
   let l:currentBufNum = bufnr("%")
   let l:alternateBufNum = bufnr("#")

   if buflisted(l:alternateBufNum)
     buffer #
   else
     bnext
   endif

   if bufnr("%") == l:currentBufNum
     new
   endif

   if buflisted(l:currentBufNum)
     execute("bdelete! ".l:currentBufNum)
   endif
endfunction

" Specify the behavior when switching between buffers
try
  set switchbuf=usetab
  set stal=2
catch
endtry
"}}}

" => Statusline {{{
""""""""""""""""""""""""""""""
" Always hide the statusline
set laststatus=2

" Format the statusline
set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c\ %{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}

function! CurDir()
    let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
    return curdir
endfunction
"}}}

" => Parenthesis/bracket expanding  {{{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vnoremap $1 <esc>`>a)<esc>`<i(<esc>
vnoremap $2 <esc>`>a]<esc>`<i[<esc>
vnoremap $3 <esc>`>a}<esc>`<i{<esc>
vnoremap $$ <esc>`>a"<esc>`<i"<esc>
vnoremap $q <esc>`>a'<esc>`<i'<esc>
vnoremap $e <esc>`>a"<esc>`<i"<esc>

" Map auto complete of (, ", ', [
inoremap $1 ()<esc>i
inoremap $2 []<esc>i
inoremap $3 {}<esc>i
inoremap $4 {<esc>o}<esc>O
inoremap $q ''<esc>i
inoremap $e ""<esc>i
"}}}

" => General Abbrevs {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
"}}}

" => Editing mappings {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Remap VIM 0
map 0 ^

"Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z

if MySys() == "mac"
  nmap <D-j> <M-j>
  nmap <D-k> <M-k>
  vmap <D-j> <M-j>
  vmap <D-k> <M-k>
endif

"Delete trailing white space, useful for Python ;)
func! DeleteTrailingWS()
  exe "normal mz"
  %s/\s\+$//ge
  exe "normal `z"
endfunc

" 行末の空白文字を削除
autocmd BufWrite *.scala :call DeleteTrailingWS()
autocmd BufWrite *.rb :call DeleteTrailingWS()
"}}}

"
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()

" => Cope {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Do :help cope if you are unsure what cope is. It's super useful!
map <leader>o :botright copen<cr>
map <leader>c :botright cclose<cr>
map <leader>n :cn<cr>
map <leader>p :cp<cr>
"}}}

" => Omni complete functions {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
"}}}

" => for make {{{
""""""""""""""""""""""""""""""
nnoremap <leader>m  :make<Return>
nnoremap <Leader>M  :make<Space>
"http://d.hatena.ne.jp/cooldaemon/20090119/1232344701
"autocmd FileType javascript set makeprg=~/work/js/bin/jslint.sh\ %
"autocmd FileType ruby set makeprg=ruby\ -c\ %
"}}}

" => MISC {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Quickly open a buffer for scripbble
map <leader>q :e ~/buffer<cr>
"}}}

" => for ctags {{{
""""""""""""""""""""""""""""""
" tags-and-searchはtに統一
" http://whileimautomaton.net/2008/08/vimworkshop3-kana-presentation

" tを解除
nnoremap t  <Nop>

nnoremap tc  :!/opt/local/bin/ctags<space>-R<CR>

"「飛ぶ」
nnoremap tt  <C-]>
nnoremap tT  g]
"「進む」
nnoremap tj  :<C-u>tag<CR>
"「戻る」
nnoremap tk  :<C-u>pop<CR>
"履歴一覧
" nnoremap tl  :<C-u>tags<CR>

nnoremap tg  :tag<space>
" タグが複数の時にリストを表示
nnoremap ts  :tselect<Return>
nnoremap tS  :tselect<space>/^

" タグが複数の時にリストを表示
nnoremap tn  :tnext<Return>
nnoremap tp  :tprevious<Return>

"nnoremap ,L  :tlast<Return>
"nnoremap ,F  :tfirst<Return>
"
set tags=./tags,tags

" Tlist
nnoremap tl  :TlistToggle<Return><C-w>=

" Triniy
nnoremap tr  :TrinityToggleAll<Return><C-w>=
"}}}

" => Haskell section {{{
""""""""""""""""""""""""""""""
let g:haddock_browser="/usr/bin/google-chrome"
let g:haddock_docdir="/usr/lib/ghc-6.12.1/html"
"}}}

" => Erlang section {{{
" vimerl : https://github.com/oscarh/vimerl
""""""""""""""""""""""""""""""
let g:erlangManPath="/home/kanbe/local/r14b04/man"

let g:ref_erlang_manpath="/home/kanbe/local/r14b04/man"
"}}}

" => Scala section {{{
""""""""""""""""""""""""""""""
autocmd BufNewFile,BufRead *.scala set filetype=scala

" => for OracleParser Project
nnoremap cdo  :cd /home/kanbe/work/kanvi_backup/scala/OracleParser

augroup scala
  autocmd FileType scala
      \ set tags+=/usr/local/src/scala-2.8.0.final-sources/tags
      \| set tags+=/home/kanbe/work/kanvi_backup/scala/OracleParser/tags
augroup END
"}}}

" For SBT {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
au FileType scala set makeprg=sbt_no_color\ test-compile

"set makeprg=sbt-no-color\ test-compile
"if exists("current_compiler")
"  finish
"endif
au FileType scala let current_compiler = "sbt"

au FileType scala set errorformat=%E[error]\ %f:%l:\ %m,%C[error]\ %p^,%-C%.%#,%Z,
               \%W[warn]\ %f:%l:\ %m,%C[warn]\ %p^,%-C%.%#,%Z,
               \%-G%.%#
"set efm=%E\ %#[error]\ %f:%l:\ %m,%C\ %#[error]\ %p^,%-C%.%#,%Z,
"       \%W\ %#[warn]\ %f:%l:\ %m,%C\ %#[warn]\ %p^,%-C%.%#,%Z,
"       \%-G%.%#
au FileType scala set errorfile=target/error
"}}}

" => Ruby section {{{
""""""""""""""""""""""""""""""
augroup ruby
      autocmd FileType ruby
        \   setlocal makeprg=ruby\ -cdw\ %
        \|  setlocal errorformat=%f:%l:%m
        \|  setlocal softtabstop=2 shiftwidth=2 tabstop=2 expandtab
        \|  setlocal tags+=/home/kanbe/local/vee/ruby/tags
augroup END
        " \|  au BufWritePost <buffer> silent make
"}}}

" => Python section {{{
""""""""""""""""""""""""""""""
au FileType python set nocindent
let python_highlight_all = 1
" au BufNewFile,BufRead *.jinja set syntax=htmljinja
" au BufNewFile,BufRead *.mako set ft=mako

augroup python
  autocmd FileType python
        \   setlocal makeprg=python\ %
        \|  setlocal foldlevel=0 softtabstop=4 shiftwidth=4 tabstop=4 expandtab
        \|  setlocal commentstring=\ #\ %s
augroup END

"        \|  au BufWritePost <buffer> silent make

autocmd FileType python set errorformat=
            \%A\ \ File\ \"%f\"\\\,\ line\ %l\\\,%m,
            \%C\ \ \ \ %.%#,
            \%+Z%.%#Error\:\ %.%#,
            \%A\ \ File\ \"%f\"\\\,\ line\ %l,
            \%+C\ \ %.%#,
            \%-C%p^,
            \%Z%m,
            \%-G%.%#
"}}}

" => JavaScript section {{{
"""""""""""""""""""""""""""""""
au FileType javascript call JavaScriptFold()
au FileType javascript setl fen
au FileType javascript setl nocindent

au FileType javascript imap <c-t> AJS.log();<esc>hi
au FileType javascript imap <c-a> alert();<esc>hi

au FileType javascript inoremap <buffer> $r return
au FileType javascript inoremap <buffer> $f //--- PH ----------------------------------------------<esc>FP2xi

function! JavaScriptFold()
    setl foldmethod=syntax
    setl foldlevelstart=1
    syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend

    function! FoldText()
    return substitute(getline(v:foldstart), '{.*', '{...}', '')
    endfunction
    setl foldtext=FoldText()
endfunction
"}}}

" => Vim grep {{{
""""""""""""""""""""""""""""""
let Grep_Skip_Dirs = 'RCS CVS SCCS .svn generated'
set grepprg=/bin/grep\ -nH

" http://d.hatena.ne.jp/yuroyoro/20101104/1288879591
" :Gb <args> でGrepBufferする
command! -nargs=1 Gb :GrepBuffer <args>
" カーソル下の単語をGrepBufferする
nnoremap <C-g><C-b> :<C-u>GrepBuffer<Space><C-r><C-w><Enter>
"}}}

" => neocomplcache {{{
""""""""""""""""""""""""""""""
" 起動時に有効
let g:neocomplcache_enable_at_startup = 1
" snippet ファイルの保存先
"let g:neocomplcache_snippets_dir='~/.vim_runtime/snippets'
" 補完候補の数
let g:neocomplcache_max_list = 100 
" 1番目の候補を自動選択
let g:neocomplcache_enable_auto_select = 1
" Define dictionary.
let g:neocomplcache_dictionary_filetype_lists = {
    \ 'default' : '',
    \ 'vimshell' : $HOME.'/.vimshell/command-history',
    \ 'scala' : $HOME.'/.vim_runtime/dict/scala.dict'
    \ }
" 日本語をキャッシュしない
"let g:neocomplcache_keyword_patterns['default'] = '\h\w*'
" C-jでオムニ補完
inoremap <expr> <C-j> &filetype == 'vim' ? "\<C-x>\<C-v>\<C-p>" : "\<C-x>\<C-o>\<C-p>"
" C-kを押すと行末まで削除
inoremap <C-k> <C-o>D
" C-nでneocomplcache補完
inoremap <expr><C-n>  pumvisible() ? "\<C-n>" : "\<C-x>\<C-u>\<C-p>"
" C-pでkeyword補完
inoremap <expr><C-p> pumvisible() ? "\<C-p>" : "\<C-p>\<C-n>"
" 補完候補が表示されている場合は確定。そうでない場合は改行
inoremap <expr><CR>  pumvisible() ? neocomplcache#close_popup() : "<CR>"
" 補完をキャンセル
inoremap <expr><C-e>  neocomplcache#close_popup()
"}}}

" YankRing.vim {{{
"------------------------------------
nmap <leader>y :YRShow<CR>
"}}}   

" Align {{{
" http://d.hatena.ne.jp/yuroyoro/20101104/1288879591
"------------------------------------
" Alignを日本語環境で使用するための設定
let g:Align_xstrlen = 3
"}}}

" unite.vim {{{
" http://d.hatena.ne.jp/yuroyoro/20101104/1288879591
"------------------------------------
" The prefix key.
nnoremap    [unite]   <Nop>
nmap    <leader>f [unite]

nnoremap [unite]u  :<C-u>Unite<Space>
nnoremap <silent> ;  :<C-u>Unite history/command command<CR>
nnoremap <silent> [unite]a  :<C-u>UniteWithCurrentDir -buffer-name=files buffer file_mru bookmark file<CR>
nnoremap <silent> [unite]l  :<C-u>Unite -buffer-name=files file_rec<CR>
nnoremap <silent> [unite]f  :<C-u>Unite -buffer-name=files file_rec<CR>
nnoremap <silent> [unite]rm  :<C-u>Unite ref/man<CR>
nnoremap <silent> [unite]re  :<C-u>Unite ref/erlang<CR>
nnoremap <silent> [unite]rr  :<C-u>Unite ref/refe<CR>
nnoremap <silent> [unite]b  :<C-u>Unite buffer<CR>
nnoremap <silent> [unite]m  :<C-u>Unite file_mru<CR>
nnoremap <silent> [unite]j  :<C-u>Unite mark<CR>
nnoremap <silent> [unite]o  :<C-u>Unite outline:!<CR>
nnoremap <silent> [unite]p  :<C-u>Unite outline -auto-preview<CR>
nnoremap <silent> [unite]g  :<C-u>Unite grep<CR>
nnoremap <silent> [unite]t  :<C-u>UniteWithCursorWord -buffer-name=tag tag<CR>
nnoremap <silent> [unite]h  :<C-u>Unite help<CR>
nnoremap <silent> [unite]t  :<C-u>Unite tag<CR>

" nnoremap <silent> [unite]b  :<C-u>UniteWithBufferDir -buffer-name=files buffer file_mru bookmark file<CR>

autocmd FileType unite call s:unite_my_settings()
function! s:unite_my_settings()
  " Overwrite settings.
  imap <buffer> jj      <Plug>(unite_insert_leave)
  nnoremap <silent><buffer> <C-k> :<C-u>call unite#mappings#do_action('preview')<CR>
  imap <buffer> <C-w>     <Plug>(unite_delete_backward_path)
  " Start insert.
  let g:unite_enable_start_insert = 1
endfunction

let g:unite_source_file_mru_limit = 200

" unite-grep
let g:unite_source_grep_default_opts = '-iRHn'

" Search.
" nnoremap <silent> /  :<C-u>Unite -buffer-name=search -start-insert line<CR>
" nnoremap <silent> ?  :<C-u>Unite mapping<CR>
" nnoremap g/  /
" nnoremap <silent> *  :<C-u>UniteWithCursorWord -buffer-name=search line<CR>
" nnoremap <silent> n  :<C-u>UniteResume search -no-start-insert<CR>
"}}}

" snipmate.vim {{{
" neocomplcacheにも補完機能はあるらしいが、とりあえずsnipmate を使うことにする。
" VTB P342
"------------------------------------
let g:snippets_dir='~/.vim/snippets'

imap <Tab> <Plug>(neocomplcache_snippets_expand)
smap <Tab> <Plug>(neocomplcache_snippets_expand)
"}}}

" NERD_commenter.vim {{{
" http://d.hatena.ne.jp/yuroyoro/20101104/1288879591                                                                                                                                
" http://www.sopht.jp/blog/index.php?/archives/446-NERD_commenter.html
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:NERDCreateDefaultMappings = 0
let NERDSpaceDelims = 1
let NERDShutUp=1
map <Leader>x  <Plug>NERDCommenterComment
map <Leader>u  <Plug>NERDCommenterUncomment
"}}}

" => SrcExl.vim {{{
" http://d.hatena.ne.jp/guyon/20080409/1207737955
" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:SrcExpl_RefreshTime = 1 "自動
" " let g:SrcExpl_RefreshTime = 0 "手動<space>
" " let g:SrcExpl_GoBackMapKey = "<C-b>"
let g:SrcExpl_UpdateTags = 0
nmap <F8> :SrcExplToggle<CR>
"}}}

" => smartchr {{{
" https://github.com/kana/vim-smartchr
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
" inoremap <buffer> <expr> = smartchr#loop(' = ', ' == ', '=')
" inoremap <buffer> <expr> <S-=> smartchr#loop(' + ', '+')
" inoremap <buffer> <expr> - smartchr#loop(' - ', '-')
" inoremap <buffer> <expr> , smartchr#loop(', ', ',')
" inoremap <buffer> <expr> . smartchr#loop('.', '<%=  %>', '<%  %>')
"}}}

" => ref.vim {{{
" http://d.hatena.ne.jp/ruedap/20110426/vim_ref_plugin_ruby_reference_search_tool_refe2
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
let g:ref_use_vimproc = 1   " vimprocをインストールしてない場合は0を指定
nmap <leader>rm :<C-u>Ref man<Space>
nmap <leader>rr :<C-u>Ref refe<Space>
nmap <leader>rp :<C-u>Ref pydoc<Space>
"}}}

" => showmarks.vim {{{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
let g:showmarks_include="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"}}}

" => easymotion.vim {{{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
let g:EasyMotion_leader_key = '<space>' 
"}}}

" => indent-guides.vim {{{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
let g:indent_guides_enable_on_vim_startup = 0
let g:indent_guides_color_change_percent =20 
let g:indent_guides_guide_size = 1
"}}}

" => errormarker.vim"{{{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
let errormarker_errortext      = "!!"
let errormarker_warningtext    = "??"
let g:errormarker_errorgroup   = "Error"
let g:errormarker_warninggroup = "Todo"
let g:errormarker_erroricon    = expand('~/.vim/signs/err.bmp')
let g:errormarker_warningicon  = expand("~/.vim/signs/warn.bmp")
"}}}

" => fontzoom.vim"{{{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
nmap + <Plug>(fontzoom-larger)
nmap _ <Plug>(fontzoom-smaller)
"}}}

" => vimshell.vim"{{{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
let g:vimshell_user_prompt = 'fnamemodify(getcwd(), ":~")'
let g:vimshell_prompt = '% '

if s:iswin
  " Display user name on Windows.
  "let g:vimshell_prompt = $USERNAME."% "

  " Use ckw.
  let g:vimshell_use_terminal_command = 'ckw -e'
else
  " Display user name on Linux.
  "let g:vimshell_prompt = $USER."% "

  " Use zsh history.
  let g:vimshell_external_history_path = expand('~/.zsh-history')

  " call vimshell#set_execute_file('bmp,jpg,png,gif', 'gexe eog')
  " call vimshell#set_execute_file('mp3,m4a,ogg', 'gexe amarok')
  " let g:vimshell_execute_file_list['zip'] = 'zipinfo'
  call vimshell#set_execute_file('zip', 'zipinfo')
  call vimshell#set_execute_file('tgz,gz', 'gzcat')
  call vimshell#set_execute_file('tbz,bz2', 'bzcat')

  " Use gnome-terminal.
  let g:vimshell_use_terminal_command = 'gnome-terminal -e'
endif

call vimshell#set_execute_file('txt,vim,c,h,cpp,d,xml,java', 'vim')
let g:vimshell_execute_file_list['rb'] = 'ruby'
let g:vimshell_execute_file_list['pl'] = 'perl'
let g:vimshell_execute_file_list['py'] = 'python'

autocmd MyAutoCmd FileType vimshell call s:vimshell_settings()
function! s:vimshell_settings()
  imap <buffer><silent> &  <C-o>:call vimshell#mappings#push_and_execute('cd ..')<CR>
  " inoremap <buffer><expr>'  pumvisible() ? "\<C-y>" : "'"
  " imap <buffer><BS>  <Plug>(vimshell_another_delete_backward_char)
  " imap <buffer><C-h>  <Plug>(vimshell_another_delete_backward_char)
  " inoremap <silent><expr><buffer><C-r>  unite#sources#vimshell_history#start_complete(!0)

  call vimshell#altercmd#define('g', 'git')
  call vimshell#set_alias('l.', 'ls -d .*')
  call vimshell#set_alias('ll', 'ls -alh')
  " call vimshell#set_galias('L', 'ls -l')
endfunction

" Plugin key-mappings."{{{
nnoremap <leader>si  :VimShellInteractive<Space>
nnoremap <leader>st  :VimShellTerminal<Space>
"}}}
"}}}

" => Open-browser.vim "{{{
nmap <Leader>w <Plug>(openbrowser-smart-search)


" => test "{{{
let source = {
    \ 'name' : 'buffer_line',
    \ 'description' : 'chandidates from current buffer lines',
    \ 'action_table' : {},
    \ 'max_candidates' : 30,
    \ 'hooks' : {},
    \ }
call unite#define_source(source)

function! source.hooks.on_init(args, context)
    let a:context.source__lines = getbufline(bufnr('%'), 1, '$')
    let a:context.source__bufname = bufname('%')
endfunction
function! source.gather_candidates(args, context)
    let candidates = []
    let linenr = 1
    for line in a:context.source__lines
        call add(candidates, {
            \ 'word' : line,
            \ 'kind' : 'jump_list',
            \ 'action__line' : linenr,
            \ 'action__path' : a:context.source__bufname,
            \ })
        let linenr += 1
    endfor
    return candidates
endfunction

unlet source