2013年2月19日火曜日

最新版.vimrc晒し

" .vimrc
" #############################################
" ######           NeoBundle               ####
" #############################################
" neobundle"{{{
filetype plugin indent off " required!

" initialize"{{{
if has('vim_starting')
let bundle_dir = '~/.bundle'
if !isdirectory(bundle_dir.'/neobundle.vim')
call system( 'git clone https://github.com/Shougo/neobundle.vim.git '.bundle_dir.'/neobundle.vim')
endif

exe 'set runtimepath+='.bundle_dir.'/neobundle.vim'
call neobundle#rc(bundle_dir)
endif

augroup MyNeobundle
au!
au Syntax vim syntax keyword vimCommand NeoBundle NeoBundleLazy NeoBundleSource NeoBundleFetch
augroup END
"}}}

" 暫定customize {{{
function! Neo_al(ft) "{{{
return { 'autoload' : {
\ 'filetype' : a:ft
\ }}
endfunction"}}}
function! Neo_operator(mappings) "{{{
return {
\ 'depends' : 'kana/vim-textobj-user',
\ 'autoload' : {
\ 'mappings' : a:mappings
\ }}
endfunction"}}}
function! BundleLoadDepends(bundle_names) "{{{
if !exists('g:loaded_bundles')
let g:loaded_bundles = {}
endif

" bundleの読み込み
if !has_key( g:loaded_bundles, a:bundle_names )
execute 'NeoBundleSource '.a:bundle_names
let g:loaded_bundles[a:bundle_names] = 1
endif
endfunction"}}}
"}}}

" コマンドを伴うやつの遅延読み込み
function! BundleWithCmd(bundle_names, cmd) "{{{
call BundleLoadDepends(a:bundle_names)

" コマンドの実行
if !empty(a:cmd)
execute a:cmd
endif
endfunction "}}}
"bundle"{{{
" その他 {{{
NeoBundle 'Shougo/vimproc', {
\ 'build' : {
\ 'mac' : 'make -f make_mac.mak',
\ 'unix' : 'make -f make_unix.mak',
\ },
\ }
NeoBundleLazy 'taichouchou2/vim-endwise.git', {
\ 'autoload' : {
\ 'insert' : 1,
\ } }
" }}}

" 補完 {{{
NeoBundleLazy 'Shougo/neocomplcache', {
\ 'autoload' : {
\ 'insert' : 1,
\ }}
NeoBundleLazy 'Shougo/neosnippet', {
\ 'autoload' : {
\ 'insert' : 1,
\ }}
NeoBundle 'Shougo/neocomplcache-rsense', {
\ 'depends': 'Shougo/neocomplcache',
\ 'autoload': { 'filetypes': 'ruby' }}
NeoBundleLazy 'taichouchou2/rsense-0.3', {
\ 'build' : {
\ 'mac': 'ruby etc/config.rb > ~/.rsense',
\ 'unix': 'ruby etc/config.rb > ~/.rsense',
\ } }
" }}}

" 便利 {{{
" 範囲指定のコマンドが使えないので、tcommentのLazy化はNeoBundleのアップデートを待ちましょう...
NeoBundle 'tomtom/tcomment_vim'
NeoBundleLazy 'tpope/vim-surround', {
\ 'autoload' : {
\ 'mappings' : [
\ ['nx', '<Plug>Dsurround'], ['nx', '<Plug>Csurround'],
\ ['nx', '<Plug>Ysurround'], ['nx', '<Plug>YSurround'],
\ ['nx', '<Plug>Yssurround'], ['nx', '<Plug>YSsurround'],
\ ['nx', '<Plug>YSsurround'], ['vx', '<Plug>VgSurround'],
\ ['vx', '<Plug>VSurround']
\ ]}}
" }}}

" ruby / railsサポート {{{
NeoBundle 'tpope/vim-rails'
NeoBundleLazy 'ujihisa/unite-rake', {
\ 'depends' : 'Shougo/unite.vim' }
NeoBundleLazy 'basyura/unite-rails', {
\ 'depends' : 'Shjkougo/unite.vim' }
NeoBundleLazy 'taichouchou2/unite-rails_best_practices', {
\ 'depends' : 'Shougo/unite.vim',
\ 'build' : {
\ 'mac': 'gem install rails_best_practices',
\ 'unix': 'gem install rails_best_practices',
\ }
\ }
NeoBundleLazy 'taichouchou2/unite-reek', {
\ 'build' : {
\ 'mac': 'gem install reek',
\ 'unix': 'gem install reek',
\ },
\ 'autoload': { 'filetypes': ['ruby', 'eruby', 'haml'] },
\ 'depends' : 'Shougo/unite.vim' }
NeoBundleLazy 'taichouchou2/alpaca_complete', {
\ 'depends' : 'tpope/vim-rails',
\ 'build' : {
\ 'mac': 'gem install alpaca_complete',
\ 'unix': 'gem install alpaca_complete',
\ }
\ }

let s:bundle_rails = 'unite-rails unite-rails_best_practices unite-rake alpaca_complete'

function! s:bundleLoadDepends(bundle_names) "{{{
" bundleの読み込み
execute 'NeoBundleSource '.a:bundle_names
au! MyAutoCmd
endfunction"}}}
aug MyAutoCmd
au User Rails call <SID>bundleLoadDepends(s:bundle_rails)
aug END

" reference環境
NeoBundleLazy 'vim-ruby/vim-ruby', {
\ 'autoload' : { 'filetypes': ['ruby', 'eruby', 'haml'] } }
NeoBundleLazy 'taka84u9/vim-ref-ri', {
\ 'depends': ['Shougo/unite.vim', 'thinca/vim-ref'],
\ 'autoload': { 'filetypes': ['ruby', 'eruby', 'haml'] } }
NeoBundleLazy 'skwp/vim-rspec', {
\ 'autoload': { 'filetypes': ['ruby', 'eruby', 'haml'] } }
NeoBundleLazy 'ruby-matchit', {
\ 'autoload' : { 'filetypes': ['ruby', 'eruby', 'haml'] } }
" }}}

" }}}

" 追加プラグイン
NeoBundle "thinca/vim-quickrun"
NeoBundle "vim-scripts/SingleCompile"

" Installation check. "{{{
if neobundle#exists_not_installed_bundles()
echomsg 'Not installed bundles : ' .
\ string(neobundle#get_not_installed_bundle_names())
echomsg 'Install Plugins'
NeoBundleInstall
endif
"}}}
filetype plugin indent on
"}}}
"


" #############################################
" ######               SET                 ####
" #############################################
" vi互換モードオフ
set nocompatible

" ファイル操作系
set fileformat=unix
set encoding=UTF-8
set fileencoding=UTF-8
set termencoding=UTF-8
set hidden                  " 編集中でもバッファを切り替えられる
set autoread                " ファイル内容が変更されると自動読み込みする

" インデント系
set smarttab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set autoindent              " オートインデントを有効
set expandtab               " Tabを空白で表示

" バックアップ系
set backupdir=$HOME/.vim/backup     " バックアップディレクトリを指定
" set browsedir=buffer
" set directory=$HOME/.vim/backup     " スワップファイルディレクトリを指定する
set history=1000

" 検索系
set incsearch               " インクリメンタル検索を有効
set wrapscan                " 検索を循環させる
set hlsearch                " 検索結果をハイライト
set ignorecase              " 検索で大文字、小文字を区別しない
set smartcase               " 検索で大文字なら区別する

" 入力移動系
set whichwrap=b,s,<,>,[,]   " カーソル移動時、行末で折り返す
set backspace=indent,eol,start      " 行をまたいでbackspace

" 表示系
set number                  " 行番号を表示
set ruler                   " ルーラーを表示
set title                   " ファイル名を表示する
set showcmd                 " 入力中のコマンドを表示
set laststatus=2            " ステータスラインを常に表示
set cmdheight=2             " コマンド欄の高さ
set list                    " タブや改行を表示
set listchars=tab:>-,trail:-,extends:>
set matchtime=3             " showmatchの表示時間
set showmode                " 現在のモードを表示
set showmatch               " 対応する括弧を強調
set wildmenu                " ファイル名補完を見やすく


" その他
set clipboard+=unnamed      " yankをクリップボードへ送る
set virtualedit+=block      " 短形選択で行末を越えてブロックを選択できるようにする
set splitbelow              " 横分割時は下へ、縦分割時は右へ新しいウィンドウを開く
set splitright              "
set showtabline=2           " タブエディタ化
set modifiable
set write


" #############################################
" ######            MAPPING                ####
" #############################################
" 削除でレジスタに格納しない
nnoremap x "_x
nnoremap dd "_dd
" ESCでハイライトをオフ
nnoremap <silent> <ESC> <ESC>:noh<CR>
" 見た目行で移動
nnoremap j gj
nnoremap k gk
" yyで改行をヤンクしない
nnoremap yy ^y
" タブ移動
nnoremap <silent> <C-h> :tabN<CR>
nnoremap <silent> <C-l> :tabn<CR>
" 文字の色を変化させる
syntax on
" カーソル行を目立たせる
augroup cch
    autocmd! cch
    autocmd WinLeave * set nocursorline
    autocmd WinEnter,Bufread * set cursorline
augroup END
" C-c,C-v,C-x,C-z,C-y,C-a,C-sをWindowsの動きへ
:source $VIMRUNTIME/mswin.vim
" INSERTモードでのカーソル移動
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-h> <Left>
inoremap <C-l> <Right>






" plugin settings"{{{
"------------------------------------
" endwise.vim
"------------------------------------
"{{{
let g:endwise_no_mappings=1
"}}}

"------------------------------------
" vim-surround
"------------------------------------
" {{{
nmap ds <Plug>Dsurround
nmap cs <Plug>Csurround
nmap ys <Plug>Ysurround
nmap yS <Plug>YSurround
nmap yss <Plug>Yssurround
nmap ySs <Plug>YSsurround
nmap ySS <Plug>YSsurround
xmap S <Plug>VSurround
xmap gS <Plug>VgSurround
vmap s <Plug>VSurround

" surround_custom_mappings.vim"{{{
let g:surround_custom_mapping = {}
let g:surround_custom_mapping._ = {
\ 'p': "<pre> \r </pre>",
\ 'w': "%w(\r)",
\ }
let g:surround_custom_mapping.help = {
\ 'p': "> \r <",
\ }
let g:surround_custom_mapping.ruby = {
\ '-': "<% \r %>",
\ '=': "<%= \r %>",
\ '9': "(\r)",
\ '5': "%(\r)",
\ '%': "%(\r)",
\ 'w': "%w(\r)",
\ '#': "#{\r}",
\ '3': "#{\r}",
\ 'e': "begin \r end",
\ 'E': "<<EOS \r EOS",
\ 'i': "if \1if\1 \r end",
\ 'u': "unless \1unless\1 \r end",
\ 'c': "class \1class\1 \r end",
\ 'm': "module \1module\1 \r end",
\ 'd': "def \1def\1\2args\r..*\r(&)\2 \r end",
\ 'p': "\1method\1 do \2args\r..*\r|&| \2\r end",
\ 'P': "\1method\1 {\2args\r..*\r|&|\2 \r }",
\ }
let g:surround_custom_mapping.javascript = {
\ 'f': "function(){ \r }"
\ }
let g:surround_custom_mapping.lua = {
\ 'f': "function(){ \r }"
\ }
let g:surround_custom_mapping.python = {
\ 'p': "print( \r)",
\ '[': "[\r]",
\ }
let g:surround_custom_mapping.vim= {
\'f': "function! \r endfunction"
\ }
"}}}
"}}}

"------------------------------------
" neocomplcache
"------------------------------------
" 補完・履歴 neocomplcache "{{{
set infercase

"----------------------------------------
" neocomplcache
let g:neocomplcache_enable_at_startup = 1

" default config"{{{
let g:neocomplcache_force_overwrite_completefunc = 1
let g:neocomplcache#sources#rsense#home_directory = expand('~/.bundle/rsense-0.3')
let g:neocomplcache_enable_camel_case_completion = 1
let g:neocomplcache_enable_underbar_completion = 1
let g:neocomplcache_skip_auto_completion_time = '0.3'
let g:neocomplcache_min_keyword_length = 20
"}}}

" keymap {{{
imap <expr><C-g> neocomplcache#undo_completion()
imap <expr><CR> neocomplcache#smart_close_popup() . "<CR>" . "<Plug>DiscretionaryEnd"
imap <silent><expr><S-TAB> pumvisible() ? "\<C-P>" : "\<S-TAB>"
" imap <silent><expr><TAB> pumvisible() ? "\<C-N>" : "\<TAB>"
imap <expr><TAB> neosnippet#expandable() ? "\<Plug>(neosnippet_jump_or_expand)" : pumvisible() ? "\<C-n>" : "\<TAB>"
" }}}
"}}}

"------------------------------------
" neosnippet
"------------------------------------
" neosnippet "{{{

" snippetを保存するディレクトリを設定してください
" example
" let s:default_snippet = neobundle#get_neobundle_dir() . '/neosnippet/autoload/neosnippet/snippets' " 本体に入っているsnippet
" let s:my_snippet = '~/snippet' " 自分のsnippet
" let g:neosnippet#snippets_directory = s:my_snippet
" let g:neosnippet#snippets_directory = s:default_snippet . ',' . s:my_snippet
imap <silent><C-F> <Plug>(neosnippet_expand_or_jump)
inoremap <silent><C-U> <ESC>:<C-U>Unite snippet<CR>
nnoremap <silent><Space>e :<C-U>NeoSnippetEdit -split<CR>
smap <silent><C-F> <Plug>(neosnippet_expand_or_jump)
" xmap <silent>o <Plug>(neosnippet_register_oneshot_snippet)
"}}}

"------------------------------------
" vim-rails
"------------------------------------
""{{{
"有効化
let g:rails_default_file='config/database.yml'
let g:rails_level = 4
let g:rails_mappings=1
let g:rails_modelines=0
" let g:rails_some_option = 1
" let g:rails_statusline = 1
" let g:rails_subversion=0
" let g:rails_syntax = 1
" let g:rails_url='http://localhost:3000'
" let g:rails_ctags_arguments='--languages=-javascript'
" let g:rails_ctags_arguments = ''
function! SetUpRailsSetting()
nnoremap <buffer><Space>r :R<CR>
nnoremap <buffer><Space>a :A<CR>
nnoremap <buffer><Space>m :Rmodel<Space>
nnoremap <buffer><Space>c :Rcontroller<Space>
nnoremap <buffer><Space>v :Rview<Space>
nnoremap <buffer><Space>p :Rpreview<CR>
endfunction

aug MyAutoCmd
au User Rails call SetUpRailsSetting()
aug END

aug RailsDictSetting
au!
aug END
"}}}

"------------------------------------
" Unite-rails.vim
"------------------------------------
"{{{
function! UniteRailsSetting()
nnoremap <buffer><C-H><C-H><C-H> :<C-U>Unite rails/view<CR>
nnoremap <buffer><C-H><C-H> :<C-U>Unite rails/model<CR>
nnoremap <buffer><C-H> :<C-U>Unite rails/controller<CR>

nnoremap <buffer><C-H>c :<C-U>Unite rails/config<CR>
nnoremap <buffer><C-H>s :<C-U>Unite rails/spec<CR>
nnoremap <buffer><C-H>m :<C-U>Unite rails/db -input=migrate<CR>
nnoremap <buffer><C-H>l :<C-U>Unite rails/lib<CR>
nnoremap <buffer><expr><C-H>g ':e '.b:rails_root.'/Gemfile<CR>'
nnoremap <buffer><expr><C-H>r ':e '.b:rails_root.'/config/routes.rb<CR>'
nnoremap <buffer><expr><C-H>se ':e '.b:rails_root.'/db/seeds.rb<CR>'
nnoremap <buffer><C-H>ra :<C-U>Unite rails/rake<CR>
nnoremap <buffer><C-H>h :<C-U>Unite rails/heroku<CR>
endfunction
aug MyAutoCmd
au User Rails call UniteRailsSetting()
aug END
"}}}

"----------------------------------------
" vim-ref
"----------------------------------------
"{{{
let g:ref_open = 'split'
let g:ref_refe_cmd = expand('~/.vim/ref/ruby-ref1.9.2/refe-1_9_2')

nnoremap rr :<C-U>Unite ref/refe -default-action=split -input=
nnoremap ri :<C-U>Unite ref/ri -default-action=split -input=

aug MyAutoCmd
au FileType ruby,eruby,ruby.rspec nnoremap <silent><buffer>KK :<C-U>Unite -no-start-insert ref/ri -input=<C-R><C-W><CR>
au FileType ruby,eruby,ruby.rspec nnoremap <silent><buffer>K :<C-U>Unite -no-start-insert ref/refe -input=<C-R><C-W><CR>
aug END
"}}}

"------------------------------------
" Unite-reek, Unite-rails_best_practices
"------------------------------------
" {{{
nnoremap <silent> [unite]<C-R> :<C-u>Unite -no-quit reek<CR>
nnoremap <silent> [unite]<C-R><C-R> :<C-u>Unite -no-quit rails_best_practices<CR>
" }}}
"}}}



"------------------------------------
"   quickrun
"------------------------------------
" 横分割をするようにする
let g:quickrun_config={'*': {'split': ''}}

"------------------------------------
"   SingleCompile
"------------------------------------
nmap <F5> :SCCompile<CR>
nmap <F6> :SCCompileRun<CR>
nmap <F7> :SCChooseCompiler<CR>
imap <F5> <Esc>:SCCompile<CR>
imap <F6> <Esc>:SCCompileRun<CR>
imap <F7> <Esc>:SCChooseCompiler<CR>






















" .gimrc
set guioptions-=T
set guioptions-=m
set linespace=1

" 全角スペースの可視化
if has("syntax")
    syntax on
    " PODバグ対策
    syn sync fromstart
    function! ActivateInvisibleIndicator()
        "下の行の" "は全角スペース
        syntax match InvisibleJISX0208Space " " display containedin=ALL
        highlight InvisibleJISX0208Space term=underline ctermbg=Blue guibg=darkgray gui=underline
        "syntax match InvisibleTrailedSpace "[ \t]\+$" display containedin=ALL
        "highlight InvisibleTrailedSpace term=underline ctermbg=Red guibg=NONE gui=undercurl guisp=darkorange
        "syntax match InvisibleTab "\t" display containedin=ALL
        "highlight InvisibleTab term=underline ctermbg=white gui=undercurl guisp=darkslategray
    endf
    augroup invisible
        autocmd! invisible
        autocmd BufNew,BufRead * call ActivateInvisibleIndicator()
    augroup END
endif

" スキーマの設定
colorscheme wombat
if g:colors_name==? 'wombat'
    hi Visual gui=none guifg=khaki guibg=olivedrab
endif