scriptencoding utf-8 "========================================================== " 初期設定 "========================================================== " {{{ " ユーザ名 if !exists("$VIMUSERNAME") let $VIMUSERNAME=$USERNAME endif let $VIMLOCALUSER=$VIMUSER."/local/".$VIMUSERNAME if !isdirectory($VIMLOCALUSER) call mkdir($VIMLOCALUSER, "p") endif if filereadable($VIMLOCALUSER."/vimrc") source $VIMLOCALUSER/vimrc endif " }}} "========================================================== " 環境変数 "========================================================== " {{{ " VIM データ let $VIMHOME=$VIMUSER."/.vim" "vimfiles let $VIMFILES=$VIMUSER."/vimfiles" " ユーザローカル let $VIMUSERLOCAL=$VIMUSER."/".$VIMUSERNAME "ソースディレクトリ let $SOURCE_ROOT=$WORK_ROOT."/software/src" " development let $DEVELOPMENT=$WORK_ROOT."/software/development" "c++ のテストディレクトリ let $TEST_CPP=$SOURCE_ROOT."/test/cpp" let $TEST_BOOST=$TEST_CPP."/boost" " vim のテストディレクトリ let $TEST_VIM=$SOURCE_ROOT."/test/vim" " vim plugin ディレクトリ let $VIMPLUGIN=$VIMUSER."/runtime/bundle" let $BOOST_ROOT=$BOOST_LATEST_ROOT let $BOOST_BUILD_PATH=$BOOST_ROOT."/tools/build/v2" let $CLANG_SDK=$LLVM_SDK.'/tools/clang' " }}} "========================================================== " pathogen "========================================================== " {{{ if has('vim_starting') "vim plugin の読み込み let $BUNDLE_ROOT=$VIMUSER."/runtime/bundle" set runtimepath+=$BUNDLE_ROOT/vim-pathogen call pathogen#runtime_prepend_subdirectories($BUNDLE_ROOT) call pathogen#runtime_append_all_bundles() call pathogen#helptags() endif " }}} "========================================================== " neobundle "========================================================== " {{{ set nocompatible filetype off filetype plugin indent off " required! if has('vim_starting') call neobundle#rc(expand($HOME."/neobundle")) endif source $VIMUSER/vimrcs/$VIMVIMRCNAME/bundles.vim filetype plugin on filetype indent on " }}} "========================================================== " 基本的な設定 "========================================================== " {{{ "shell のパスを設定 if has("gui_win32") set shell=C:\WINDOWS\system32\cmd.exe endif "バックアップファイルを作るディレクトリ set backupdir=$HOME/vimbackup if !isdirectory(&backupdir) call mkdir(&backupdir, "p") endif "ファイル保存の初期ディレクトリをバッファファイル位置に設定 set browsedir=buffer "スワップファイル用のディレクトリ set directory=$HOME/vimbackup if !isdirectory(&directory) call mkdir(&directory, "p") endif " Windows set splitbelow " 横分割したら新しいウィンドウは下に set splitright " 縦分割したら新しいウィンドウは右に " 常に開いているファイルと同じディレクトリをカレントディレクトリにする " http://www15.ocn.ne.jp/~tusr/vim/vim_text2.html#mozTocId567011 augroup vimrc_group__cd autocmd! autocmd BufEnter * execute ":lcd " . (isdirectory(expand("%:p:h")) ? expand("%:p:h") : "") augroup END " Undo 回数の設定 (デフォルト = 1000) set undolevels=2000 " バッファを切り替えても、undo を効くように設定 " (変更をセーブせずにバッファを切り替えたいときにも、 :set hidden は役に立つが、 " 変更に気づかないまま":qa! "するという危険も伴う、諸刃の剣) set hidden " indent eol start を超えて、 を有効にする set backspace=indent,eol,start "日本語ヘルプ helptags $VIMFILES/doc " 日本語ヘルプを引く際に無限ループになるのを防ぐ為 " http://d.hatena.ne.jp/tyru/20100409/vim_set_notagbsearch set notagbsearch " http://www.geocities.co.jp/SiliconValley-SantaClara/1183/computer/gvim.html set iminsert=0 " インサートモードで日本語入力を ON にしない set imsearch=0 " 検索モードで日本語入力を ON にしない " で英字も増減させる set nrformats=alpha,octal,hex " 折り返しを無効にする set textwidth=0 " set incsearch " }}} "========================================================== "ビジュアルの設定 "========================================================== " {{{ " 常にカーソル位置を中心に " set scrolloff=999 " 行間のピクセル数 set linespace=2 "タブ文字、改行文字を表示 set list "改行、タブ文字の設定 set listchars=tab:^-,trail:-,eol:\ "行番号を表示 set number "閉じカッコが入力されたとき、対応するカッコを表示する "set showmatch " 括弧を入力した時にカーソルが移動しないように設定 set matchtime=0 " タブページのラベルを常に表示する set showtabline=2 " ツールバーを削除 set guioptions-=T "メニューを削除 set guioptions-=m "チラツキ防止 set completeopt=menuone " menu を無効 let did_install_default_menus = 1 let did_install_syntax_menu = 1 " バッファを閉じる時にバッファリストから削除 " autocmd BufReadPre * setlocal bufhidden=delete " ウィンドウのリサイズを抑える set noequalalways " }}} "========================================================== "コーディング "========================================================== " {{{ "新しい行のインデントを同じ行にする set autoindent filetype plugin indent on set nocindent " 改行時にコメントしない set formatoptions-=ro augroup vimrc_group_formatoptions autocmd! autocmd FileType * setlocal formatoptions-=ro augroup END "クリップボードをWindowsと連携 set clipboard=unnamed "タブ文字の長さ set tabstop=4 set shiftwidth=4 set fileformat=unix set fileformats=unix,dos " }}} "================================== "文字コード "================================== " {{{ " 改行コードが unix でなければ unix にする function! s:set_fileformat() if &fileformat != "unix" \ && !get(b:, "set_fileformat_checked", 0) \ && (empty(readfile(expand("%:p"))) || input("setlocal fileformat=unix?[y/n]") == "y") try setlocal fileformat=unix catch endtry endif let b:set_fileformat_checked = 1 " try " setlocal fileformat=unix " catch " endtry endfunction augroup vimrc_group_set_fileformat autocmd! " autocmd BufRead * :call set_fileformat() autocmd BufWritePre * :call set_fileformat() augroup END "let g:verifyenc_enable = 0 setlocal encoding=utf-8 setlocal fileencodings=ucs-bom,iso-2022-jp-3,iso-2022-jp,eucjp-ms,euc-jisx0213,euc-jp,utf-8,cp932,sjis scriptencoding utf-8 setlocal termencoding=cp932 """""""""""""""""""""""""""""" "Windowsで内部エンコーディングがcp932以外の場合 "makeのメッセージが化けるのを回避 "http://sites.google.com/site/fudist/Home/vim-nihongo-ban/-vimrc-sample#make """""""""""""""""""""""""""""" if has('win32') || has('win64') || has('win95') || has('win16') au QuickfixCmdPost make call QFixCnv('cp932') endif function! QFixCnv(enc) if a:enc == &enc return endif let qflist = getqflist() for i in qflist let i.text = iconv(i.text, a:enc, &enc) endfor call setqflist(qflist) endfunction " }}} "========================================================== " キーマッピング "========================================================== " {{{ " 雑多 {{{ " nmap T % " スペースを挿入 nnoremap i " C-@ の誤爆防止 inoremap " 検索のハイライトを消す nnoremap :nohlsearch " normal モードで改行 nnoremap O nnoremap dd " カッコの補完 " inoremap "" "" " inoremap () () " inoremap {} {} " inoremap '' '' " inoremap <> <> " }}} " https://sites.google.com/site/fudist/Home/vim-nihongo-ban/tips#TOC-4 " カーソルを表示行で移動する。物理行移動は, nnoremap j gj nnoremap k gk nnoremap gj nnoremap gk " カーソルキーで行末/行頭の移動可能に設定。 set whichwrap=b,s,[,],<,> nnoremap h nnoremap l " l を に置き換えて、折りたたみを l で開くことができるようにする。 if has('folding') nnoremap l foldlevel(line('.')) ? "\zo" : "\" endif " 検索後画面の中心に。 nnoremap n nzz nnoremap N Nzz " 縦に連番を入力する nnoremap co :ContinuousNumber vnoremap co :ContinuousNumber command! -count -nargs=1 ContinuousNumber let c = col('.')|for n in range(1, ?-line('.'):1)|exec 'normal! j' . n . |call cursor('.', c)|endfor " カーソル位置の単語をヤンクした単語に置換 nnoremap ciy ciw0:let@/=@1:noh nnoremap cy ce0:let@/=@1:noh nnoremap gy "0P " 最後の編集位置へ戻る " https://sites.google.com/site/fudist/Home/vim-nihongo-ban/tips#TOC-12 map gb `.zz nnoremap g;zz nnoremap g; g, " インデントを連続で出来るように設定 vnoremap > >gv vnoremap < c :execute ":set conceallevel=".((&conceallevel==0)?"2":"0") " \ から / へ置換 vnoremap / :s/\\/\//g:nohlsearch nnoremap / :s/\\/\//g:nohlsearch " タブの移動 nnoremap :tabnext nnoremap :tabprevious " で改行した場合にインデントをスペースで揃える inoremap :set expandtaba :set noexpandtaba " q の誤爆防止用 " nnoremap q " nnoremap qq q " }}} "========================================================== " autocmd "========================================================== " {{{ augroup vimrc_group autocmd! autocmd filetype cpp :set comments-=:\/\/ autocmd BufReadPost *.scala setlocal filetype=scala autocmd BufReadPost *.txt set filetype=txt " 前回終了したカーソル行に移動 autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g`\"" | endif augroup END " }}} "========================================================== " プラグインの設定 "========================================================== " {{{ " w3m.vim{{{ " }}} " vimshell {{{ let g:vimshell_split_command = "split" " 呼び出し "nnoremap vs :VimShell nnoremap vs :execute "VimShellPop ".expand("%:p:h") nnoremap vsvp :VimShell $VIMPLUGIN " 表示形式 "let g:vimshell_prompt = " % " let g:vimshell_prompt = $VIMUSERNAME."% " augroup vimrc_group_vimshell autocmd! autocmd FileType int-* \ inoremap unite#sources#vimshell_history#start_complete(0) augroup END " }}} " ref.vim {{{ function! s:ref_init() let g:ref_use_vimproc = 1 " let g:ref_open="tabnew" " ref alc let lynx = g:lynx_dir.'/lynx.exe' let cfg = g:lynx_dir.'/lynx.cfg' " let g:ref_alc_cmd = "D:/home/work/tools/links/links.exe -dump %s" let g:ref_alc_cmd = lynx.' -cfg='.cfg.' -dump -nonumbers %s' let g:ref_alc_use_cache = 1 let g:ref_alc_start_linenumber = 39 " 余計な行を読み飛ばす let g:ref_alc_encoding = 'Shift-JIS' " let g:ref_alc_encoding = 'utf-8' if exists('*ref#register_detection') " filetypeが分からんならalc call ref#register_detection('_', 'alc') endif " let g:ref_lynx_cmd = lynx.' -cfg='.cfg.' -dump %s' let g:ref_lynx_cmd = g:ref_alc_cmd let g:ref_lynx_use_cache = 1 let g:ref_lynx_encoding = 'Shift-JIS' let g:ref_lynx_start_linenumber = 0 " 余計な行を読み飛ばす endfunction call s:ref_init() " }}} " qfixhowm {{{ let QFixHowm_Key = 'g' " let howm_dir = $HOWM let howm_dir = $VIMFILES."/howm" let howm_filename = '%Y/%m/%Y-%m-%d-%H%M%S.howm' let howm_fileencoding = 'utf-8' let howm_fileformat = 'dos' " }}} " reanimate.vim {{{ let g:reanimate_save_dir = $VIMLOCALUSER."/.vim/save_point" let g:reanimate_default_save_name = "latest" let g:reanimate_sessionoptions="curdir,folds,help,localoptions,slash,tabpages,winsize" let g:reanimate_disables = [] " ユーザで hook する event let s:event = { \ "name" : "user_event", \} " function! s:event.load_pre(...) function! s:event.load_pre_post(...) " 読み込み前に全てのバッファを保存 :wall " 復元前にタブを削除する :tabonly endfunction function! s:event.save_pre(...) " 保存前に args を削除する try :execute "argd *" catch endtry endfunction call reanimate#hook(s:event) unlet s:event function! Last_point() return reanimate#is_saved() ? reanimate#last_point() : "no save" endfunction augroup vimrc_group_reanimate autocmd! autocmd VimLeavePre * ReanimateSave autocmd BufWritePost * ReanimateSave augroup END function! s:user_test() let self = {} let self.name = "user_event" return self endfunction function! s:SID() return matchstr(expand(''), '\zs\d\+\ze_SID$') endfun let g:reanimate_vimrc_local_filename = "vimrc_local" nnoremap rl :execute ":tabnew ".g:reanimate_save_dir."/".reanimate#last_point()."/".g:reanimate_vimrc_local_filename " }}} " kaoriya {{{ """""""""""""""""""""""""""""" "Kaoriya版に添付されているプラグインの無効化 "問題があるものもあるので一律に無効化します。 "ファイルを参照(コメント部分で gf を実行)した上で、必要なプラグインは "let plugin_..._disableの設定行をコメント化(削除)して有効にして下さい。 """""""""""""""""""""""""""""" " "$VIM/plugins/kaoriya/autodate.vim " let plugin_autodate_disable = 1 " "$VIM/plugins/kaoriya/cmdex.vim " let plugin_cmdex_disable = 1 " "$VIM/plugins/kaoriya/dicwin.vim let plugin_dicwin_disable = 1 " "$VIMRUNTIME/plugin/format.vim " let plugin_format_disable = 1 " "$VIM/plugins/kaoriya/hz_ja.vim " let plugin_hz_ja_disable = 1 " "$VIM/plugins/kaoriya/scrnmode.vim " let plugin_scrnmode_disable = 1 " "$VIM/plugins/kaoriya/verifyenc.vim " let plugin_verifyenc_disable = 1 " }}} " EasyMotion {{{ let g:EasyMotion_leader_key = 'e' "let g:EasyMotion_leader_key = '' nmap f ee nmap F eb " }}} " itunes.vim {{{ " 一時停止 nnoremap i itunes#pause() " 再生 nnoremap ip itunes#play() " 停止 nnoremap is itunes#stop() " 前の曲 nnoremap ih itunes#prev() " 次の曲 nnoremap il itunes#next() " }}} " powerline{{{ let g:Powerline_theme="distinguished2" let g:Powerline_colorscheme="distinguished2" " let g:Powerline_theme="distinguished_with_tweetvim" " let g:Powerline_colorscheme="distinguished_with_tweetvim" " }}} " Syntastic {{{ " let g:syntastic_mode_map = { " \ "mode" : "active", " \ "passive_filetypes" : ["cpp"] " \} " }}} " caw.vim {{{ nmap c (caw:I:toggle) nmap C (caw:I:uncomment) vmap c (caw:I:toggle) vmap C (caw:I:uncomment) nmap gcy yypgcIk vmap gcy ygvgcIP " }}} " vim-quickhl {{{ nmap m (quickhl-toggle) xmap m (quickhl-toggle) nmap M (quickhl-reset) xmap M (quickhl-reset) nmap j (quickhl-match) " }}} " auto_source.vim {{{ let g:auto_source#exclude = ".*\/vim_script\/.*" " }}} " restart.vim {{{ let g:restart_sessionoptions = 'blank,buffers,winpos,winsize,curdir,folds,help,localoptions,tabpages,winsize' command! \ RestartWithSession \ let g:restart_sessionoptions = 'blank,buffers,winpos,winsize,curdir,folds,help,localoptions,tabpages,winsize' \ | Restart nnoremap res :Restart " }}} " textmanip.vim {{{ " vmap (Textmanip.move_selection_down) " vmap (Textmanip.move_selection_up) " vmap (Textmanip.move_selection_left) " vmap (Textmanip.move_selection_right) " }}} " copypath {{{ nnoremap cp :CopyPath " }}} " OpenBrowser {{{ nnoremap ecd :call OpenBrowser("file:/".expand("%:p:h")) nnoremap ss :OpenBrowserSearch nmap op (openbrowser-smart-search) " }}} " ref.vim {{{ nnoremap ra :Ref alc " }}} " TwitVim {{{ " " ポスト noremap ttp :PosttoTwitter "ID からブラウザを開く function! Twitter_id() let l:cword = expand("") call OpenBrowser("http://twitter.com/#!/".l:cword) return "" endfunction nnoremap top Twitter_id() let twitvim_count = 100 " }}} " TweetVim{{{ " ポスト noremap tp :TweetVimSay let g:tweetvim_display_icon = 1 let g:tweetvim_footer="[8/4(土)23:00からlingrでvimrc読書会 http://lingr.com/room/vim]" " }}} " evervim {{{ " " 新規作成 " noremap evc :EvervimCreateNote " " " タグ一覧 " noremap evt :EvervimListTags " " " 検索 " noremap evs :EvervimSearchByQuery " }}} " vimfiler {{{ let g:vimfiler_safe_mode_by_default=0 let g:unite_kind_file_use_trashbox = 1 let g:vimfiler_as_default_explorer = 1 let g:vimfiler_split_rule="botright" nnoremap vfvf :VimFilerTab $VIMFILES nnoremap vftc :VimFilerTab $TEST_CPP nnoremap vftb :VimFilerTab $TEST_BOOST nnoremap vftv :VimFilerTab $TEST_VIM nnoremap vfvp :VimFilerTab $VIMPLUGIN nnoremap vf :execute "VimFilerTab ".substitute(expand("%:p:h"), "\\", "/", "g") nnoremap vfs :VimFiler -buffer-name=explorer -split -simple -winwidth=35 -toggle -no-quit " }}} " neocomplcache {{{ " 有効にする let g:neocomplcache_enable_at_startup=1 " キーワード補完を行う入力数 let g:neocomplcache_auto_completion_start_length=2 let g:neocomplcache_enable_ignore_case=0 " 大文字、小文字を無視する "入力に大文字が含まれている場合は、大文字・小文字を無視する let g:neocomplcache_enable_smart_case=0 "大文字を入力したときに、それを単語の区切りとしてあいまい検索を行う let g:neocomplcache_enable_camel_case_completion=1 "_を入力したときに、それを単語の区切りとしてあいまい検索を行う let g:neocomplcache_enable_underbar_completion=1 "スニペットのディレクトリ if !exists("g:neocomplcache_snippets_dir") let g:neocomplcache_snippets_dir="" endif let g:neocomplcache_snippets_dir=$VIMUSER.'/snippets'.','.g:neocomplcache_snippets_dir "でスニペット補完 if g:neocomplcache_enable_at_startup imap neocomplcache#sources#snippets_complete#expandable() ? "\(neocomplcache_snippets_expand)" : pumvisible() ? "\" : "\" endif "(ENTER)で候補を閉じ改行 inoremap neocomplcache#close_popup() . "\" "1つ前の補完を取り消す inoremap neocomplcache#undo_completion() "を押したときに確実にポップアップを削除す inoremap neocomplcache#smart_close_popup()."\" inoremap neocomplcache#smart_close_popup()."\" "現在選択している候補を確定する inoremap neocomplcache#close_popup() "現在選択している候補をキャンセルし、ポップアップを閉じる inoremap neocomplcache#cancel_popup() let g:neocomplcache_enable_cursor_hold_i=0 let g:neocomplcache_max_list=1000 " }}} " unite.vim {{{ " キーマッピング {{{ nnoremap ub :Unite buffer -input=!split nnoremap ufm :Unite file_mru2 nnoremap ufm :Unite file_mru nnoremap udm :Unite directory_mru nnoremap urm :UniteResume nnoremap uff :Unite file nnoremap uol :Unite outline nnoremap unb :Unite neobundle nnoremap ugr :Unite grep nnoremap um :Unite menu nnoremap urrr :Unite rofi nnoremap url :Unite reanimate -default-action=reanimate_load nnoremap urs :Unite reanimate -default-action=reanimate_save nnoremap umes :Unite output:mes nnoremap uqh :Unite qfixhowm:nocache nnoremap uqh :Unite qfixhowm:nocache nnoremap ubb :Unite boost-online-doc -default-action=ref_lynx_tabnew " nnoremap ub :Unite bookmark " nnoremap ucmd :Unite commandsCR> " nnoremap uw :Unite window " nnoremap ut :Unite tab inoremap :Unite history/yank -direction=belowright -winheight=12 " }}} " unite-action {{{ " unite-kinds start {{{ let start = { \ 'description' : 'start', \ 'is_selectable' : 1, \} function! start.func(candidates) for l:candidate in a:candidates call system("cmd /c start ".l:candidate.action__path) endfor endfunction call unite#custom_action('openable', 'start', start) unlet start " }}} " read {{{ let read = { \ 'is_selectable' : 1, \} function! read.func(candidates) for l:candidate in a:candidates call unite#util#smart_execute_command('read', l:candidate.action__path) endfor endfunction call unite#custom_action('file', 'read', read) unlet read " }}} " OpenBrowser {{{ let openbrowser = { \ 'description' : 'OpenBrowser', \ 'is_selectable' : 1, \} function! openbrowser.func(candidates)"{{{ for l:candidate in a:candidates call openbrowser#open(l:candidate.word) endfor endfunction"}}} call unite#custom_action('common', 'openbrowser', openbrowser) unlet openbrowser " }}} " OpenBrowser file:/ {{{ let openbrowser_file = { \ 'description' : 'OpenBrowser file:/{word}', \ 'is_selectable' : 1, \} function! openbrowser_file.func(candidates)"{{{ for l:candidate in a:candidates call openbrowser#open('file:/'.l:candidate.action__path) endfor endfunction"}}} call unite#custom_action('openable', 'openbrowser_file', openbrowser_file) unlet openbrowser_file " }}} " OpenBrowserSearch {{{ let openbrowser_search = { \ 'description' : 'OpenBrowserSearch for word', \ 'is_selectable' : 1, \} function! openbrowser_search.func(candidates)"{{{ for l:candidate in a:candidates call openbrowser#search(l:candidate.word) endfor endfunction"}}} call unite#custom_action('common', 'openbrowser_search', openbrowser_search) unlet openbrowser_search " }}} " tab drop {{{ let action = { \ 'description' : 'tab drop', \ 'is_selectable' : 1, \ } function! action.func(candidates)"{{{ for candidate in a:candidates let bufpath = substitute(expand("%:p"), "\\", "\/", "g") if bufpath != candidate.action__path call unite#util#smart_execute_command('tab drop', candidate.action__path) endif call unite#take_action('open', candidate) endfor endfunction"}}} call unite#custom_action('openable', 'tabdrop', action) unlet action " }}} " }}} " unite-menu {{{ if !exists("g:unite_source_menu_menus") let g:unite_source_menu_menus = {} endif " directory {{{ let s:commands = { \ 'description' : 'Test menu', \} let s:commands.candidates = { \ "BoostTest" : "VimFiler $TEST_BOOST", \ "C++Test" : "VimFiler $TEST_CPP", \ "VimFiles" : "VimFiler $VIMFILERS", \ "Vim Test" : "VimFiler $TEST_VIM", \ "Bundle" : "VimFiler $VIMPLUGIN", \} function s:commands.map(key, value) return { \ 'word' : a:key, \ 'kind' : 'command', \ 'action__command' : a:value, \ } endfunction let g:unite_source_menu_menus["directory"] = deepcopy(s:commands) unlet s:commands " 呼び出しのキーマップ nnoremap dd :Unite menu:directory " }}} " unite-shortcut {{{ " コマンドを登録して unite.vim で選択して起動 let s:commands = { \ 'description' : 'Test menu', \} let s:commands.candidates = { \ "BoostTest" : "VimFiler $TEST_BOOST", \ "C++Test" : "VimFiler $TEST_CPP", \ "ghci" : "VimShellInteractive ghci", \ "python" : "VimShellInteractive python", \ "Unite Beautiful Attack" : "Unite -auto-preview colorscheme", \ "Boost.MPL Ref" : "OpenBrowser http://www.boost.org/doc/libs/release/libs/mpl/doc/refmanual/refmanual_toc.html", \ "VimShellPop" : "VimShellPop", \ "Blog Edit" : "OpenBrowser http://d.hatena.ne.jp/osyo-manga/edit", \ "ideone" : "OpenBrowser http://ideone.com/", \ "AllMap" : "Unite output:AllMap", \ "LastBuf.vim : open last closed buffersLastBuf" : ":LastBuf", \} function s:commands.map(key, value) return { \ 'word' : a:key, \ 'kind' : 'command', \ 'action__command' : a:value, \ } endfunction let g:unite_source_menu_menus["shortcut"] = deepcopy(s:commands) unlet s:commands " 呼び出しのキーマップ nnoremap ll :Unite menu:shortcut " }}} " }}} " 設定 {{{ call unite#custom_default_action('directory' , 'tabvimfiler') let g:unite_data_directory = $VIMLOCALUSER."/.vim/.unite" let g:unite_source_history_yank_enable=1 " file mru の保存数 let g:unite_source_file_mru_limit = 5000 let g:unite_source_file_mru2_limit = 200 " default action call unite#custom_default_action("directory_mru", "vimfiler") " }}} " unite-source {{{ " templatefiles {{{ " Unite から選択して、template file を挿入する " filetype のディレクトリから選択を行う if !exists("g:templatefiles") let g:templatefiles=$VIMUSER."/templatefiles" endif nnoremap utmp :call l:unite_templatefiles(g:templatefiles) function! l:unite_templatefiles(dir) call unite#start(['file_rec'], { \'input' : substitute(a:dir, '\', '/', 'g').'/'.&filetype, \'default_action' : 'read' \}) endfunction nnoremap vftmp :VimFiler $TEMPLAETFILES " }}} " qfixfowm {{{ let s:source = { \ "name" : "qfixhowm", \ "description" : "qfixhowm", \ "action_table" : { \ "delete" : { \ "description" : "delete qfixmemo", \ "is_selectable" : 1, \ "is_invalidate_cache" : 1, \ "is_quit" : 0 \ } \ } \} function! s:source.action_table.delete.func(candidates) let input = input("Really force delete files? [yes/no]") if input == "yes" || input == "y" for candidate in a:candidates call delete(candidate.action__path) endfor endif endfunction function! g:my_qfixhowm_sort(a, b) return getftime(a:a.filename) < getftime(a:b.filename) endfunction function! s:source.gather_candidates(args, context) " call qfixmemo#ListCmd() " if get(a:args, 0, "") == "close" " close " endif let tmp = get(g:, "QFixListAltOpen", 0) let g:QFixListAltOpen = 1 if get(a:args, 0, "") == "nocache" let list = qfixmemo#ListCmd("nocache") else let list = qfixmemo#ListCmd() endif let g:QFixListAltOpen = tmp let new_memo = [{ \ "word" : "[ new memo ]", \ "default_action" : "new_memo", \ "kind" : "qfixlist_new_memo" \ }] return new_memo + map(sort(copy(list), "g:my_qfixhowm_sort"), '{ \ "word" : "(".fnamemodify(v:val.filename, ":t:r").") ".v:val.text, \ "kind" : "file", \ "action__path" : v:val.filename \ }') endfunction call unite#define_source(s:source) unlet s:source let s:kind = { \ "name" : "qfixlist_new_memo", \ "default_action" : "new_memo", \ "action_table" : { \ "new_memo" : { \ "is_selectable" : 0, \ } \ } \} function! s:kind.action_table.new_memo.func(candidates) tabnew call qfixmemo#EditNew() endfunction call unite#define_kind(s:kind) unlet s:kind function! QFixListAltOpen(qflist, dir) return a:qflist endfunction " }}} " }}} " }}} " clang_complete {{{ if isdirectory($LLVM_ROOT) let $PAHT=$LLVM_ROOT.";".$PATH let g:clang_conceal_snippets=1 " let g:clang_snippets=1 let g:clang_complete_auto=1 let g:clang_sort_algo="none" " let g:clang_exec =$LLVM_ROOT.'/bin/clang.exe' let g:clang_exec = $LLVM_BIN."/clang.exe" let g:clang_use_library=1 let g:clang_library_path = $LLVM_BIN let g:clang_debug=0 let g:clang_auto_select = 0 let g:clang_complete_copen=1 let g:clang_user_options = \ '-fms-extensions -fgnu-runtime '. \ '-include malloc.h '. \ '-std=gnu++0x ' " let g:clang_complete_macros=1 " let g:clang_complete_patterns=0 " neocomplcache_clang {{{ " let g:neocomplcache_clang_use_library = 1 " let g:neocomplcache_clang_debug = 1 " let g:neocomplcache_clang_library_path = $LLVM_BIN " let g:neocomplcache_clang_user_options = g:clang_user_options "let g:neocomplcache_clang_user_options = \ '-I '.$LLVM_ROOT.'/lib/clang/3.1/include '. \ '-I C:/MinGW/lib/gcc/mingw32/4.5.2/include '. \ g:get_include_dirs_option(). \ '-fms-extensions -fgnu-runtime '. \ '-include malloc.h ' " }}} endif " }}} source $VIMUSER/vimrcs/default/quickrun.vim " }}} "========================================================== " Vim scirpt "========================================================== " {{{ " {{{ " }}} " vim hack {{{ " http://vim-users.jp/vim-hacks-project/ " 次の()へ移動する {{{ " http://vim-users.jp/2011/04/hack214/ onoremap ) t) onoremap ( t( vnoremap ) t) vnoremap ( t( " }}} " Hack #125: 矩形選択で自由に移動する {{{ " http://vim-users.jp/2010/02/hack125/ set virtualedit+=block " }}} " AllMaps {{{ " http://vim-users.jp/2011/02/hack203/ command! \ -nargs=* -complete=mapping \ AllMaps \ map | map! | lmap " }}} " Capture {{{ " http://d.hatena.ne.jp/tyru/20100427/vim_capture_command command! \ -nargs=+ -complete=command \ Capture \ call s:cmd_capture() function! s:cmd_capture(q_args) "{{{ redir => output silent execute a:q_args redir END let output = substitute(output, '^\n\+', '', '') belowright new silent file `=printf('[Capture: %s]', a:q_args)` setlocal buftype=nofile bufhidden=unload noswapfile nobuflisted call setline(1, split(output, '\n')) endfunction "}}} " }}} " Hack #202: 自動的にディレクトリを作成する {{{ " http://vim-users.jp/2011/02/hack202/ augroup vimrc-auto-mkdir " {{{ autocmd! autocmd BufWritePre * call s:auto_mkdir(expand(':p:h'), v:cmdbang) function! s:auto_mkdir(dir, force) " {{{ if !isdirectory(a:dir) && (a:force || \ input(printf('"%s" does not exist. Create? [y/N]', a:dir)) =~? '^y\%[es]$') call mkdir(iconv(a:dir, &encoding, &termencoding), 'p') endif endfunction " }}} augroup END " }}} " }}} " Hack #62: カーソル下のキーワードをバッファ内全体で置換する {{{ " http://vim-users.jp/2009/08/hack62/ nnoremap s* ':%substitute/\<' . expand('') . '\>/' " }}} " }}} " " "全角スペースを表示 {{{ " "http://sites.google.com/site/fudist/Home/vim-nihongo-ban/vim-color " "コメント以外で全角スペースを指定しているので scriptencodingと、 " "このファイルのエンコードが一致するよう注意! " "全角スペースが強調表示されない場合、ここでscriptencodingを指定すると良い。 " "scriptencoding cp932 " " function! s:zenkakuSpace() " "ZenkakuSpaceをカラーファイルで設定するなら次の行は削除 " highlight ZenkakuSpace cterm=underline ctermfg=darkgrey gui=underline guifg=darkgrey " "全角スペースを明示的に表示する。 " silent! match ZenkakuSpace / / " endfunction " if has('syntax') " augroup ZenkakuSpace " autocmd! " autocmd VimEnter,BufEnter * call zenkakuSpace() " augroup END " endif " " }}} " " バッファの削除 {{{ function! s:delete_hide_buffer() let list = filter(range(1, bufnr("$")), "bufexists(v:val) && !buflisted(v:val)") for v in list execute "bw ".v endfor endfunction command! -bar DeleteHideBuffer :call s:delete_hide_buffer() function! s:delete_no_file_buffer() let list = filter(range(1, bufnr("$")), \ 'bufexists(v:val) && !filereadable(expand("#".v:val.":p"))' \ ) for v in list execute "bw ".v endfor endfunction command! -bar DeleteNoFileBuffer :call s:delete_no_file_buffer() " }}} " 各 filetype ごとの設定ファイル {{{ " after/ftplugin/{&filetype}.vim ファイルを開く " ディレクトリは各環境にあわせて let $AFTER_FTPLUGIN = $BUNDLE_ROOT."/after/ftplugin" " nnoremap :execute ":e ".$AFTER_FTPLUGIN."/".&filetype.".vim" nnoremap :execute ":tab drop ".$AFTER_FTPLUGIN."/".&filetype.".vim" " }}} " 雑多 {{{ function! s:flatten(seq) let result = [] for n in a:seq if(type(n) == type([])) let result = result + s:flatten(n) else let result = result + [n] endif unlet n endfor return result endfunction function! s:delete_window() let tabpagelist = s:flatten(map(range(tabpagenr("$")), "tabpagebuflist(v:val+1)")) if count(tabpagelist, winbufnr("%")) == 1 :bdelete else :quit endif endfunction " }}} " neocomplcache が作成した tag ファイルのパスを tags に追加する {{{ function! s:TagsUpdate() " setlocal tags に neocomplcache が出力した tag ファイルのパスを追加する " include している tag ファイルが毎回同じとは限らないので1度初期化 setlocal tags= for filename in neocomplcache#sources#include_complete#get_include_files(bufnr('%')) execute "setlocal tags+=".neocomplcache#cache#encode_name('tags_output', filename) endfor endfunction command! \ -nargs=? PopupTags \ Unite -default-action=tabdrop -immediately -direction=belowright -winheight=12 tag/include: function! s:get_func_name(word) let end = match(a:word, '<\|[\|(') return end == -1 ? a:word : a:word[ : end-1 ] endfunction noremap g :execute "PopupTags ".expand('') noremap G :execute "PopupTags " \.substitute(get_func_name(expand('')), '\:', '\\\:', "g") nnoremap ns :execute "tabnew\|:NeoComplCacheEditSnippets ".&filetype " }}} " タブ表示 {{{ function! g:tablabel() let label = &ft == "howm_memo" ? getline(1) \ : fnamemodify(expand('%:p'),':h:t').'/'.expand('%:t') let bufnrlist = tabpagebuflist(v:lnum) " このタブページに変更のあるバッファがるときには '+' を追加する for bufnr in bufnrlist if getbufvar(bufnr, "&modified") let label = '+ '.label break endif endfor return label endfunction set guitablabel=%{g:tablabel()} " nmap gf gf " }}} " スワップファイルの削除 {{{ function! s:remove_swapfile() let target = &directory let list = split(glob(target."**/*.*.sw{p,o}"), '\n') echo "remove" for file in list echo file call delete(file) endfor endfunction command! RemoveSwapfile :call remove_swapfile() " }}} "スクリプトローカルな関数を呼び出す {{{ " http://d.hatena.ne.jp/thinca/20111228/1325077104 " Call a script local function. " Usage: " - S('local_func') " -> call s:local_func() in current file. " - S('plugin/hoge.vim:local_func', 'string', 10) " -> call s:local_func('string', 10) in *plugin/hoge.vim. " - S('plugin/hoge:local_func("string", 10)') " -> call s:local_func("string", 10) in *plugin/hoge(.vim)?. function! S(f, ...) let [file, func] =a:f =~# ':' ? split(a:f, ':') : [expand('%:p'), a:f] let fname = matchstr(func, '^\w*') " Get sourced scripts. redir =>slist silent scriptnames redir END let filepat = '\V' . substitute(file, '\\', '/', 'g') . '\v%(\.vim)?$' for s in split(slist, "\n") let p = matchlist(s, '^\s*\(\d\+\):\s*\(.*\)$') if empty(p) continue endif let [nr, sfile] = p[1 : 2] let sfile = fnamemodify(sfile, ':p:gs?\\?/?') if sfile =~# filepat && \ exists(printf("*\%d_%s", nr, fname)) let cfunc = printf("\%d_%s", nr, func) break endif endfor if !exists('nr') echoerr Not sourced: ' . file return elseif !exists('cfunc') let file = fnamemodify(file, ':p') echoerr printf( \ 'File found, but function is not defined: %s: %s()', file, fname) return endif return 0 <= match(func, '^\w*\s*(.*)\s*$') \ ? eval(cfunc) : call(cfunc, a:000) endfunction "}}} " }}} "========================================================== " 各言語の設定 "========================================================== " {{{ " cpp{{{ " source $VIMUSER/vimrcs/default/cpp.vim let c_comment_strings=1 let c_no_curly_error=1 " filetype = cpp の時 autocmd FileType cpp call s:cpp_loaded() function! s:cpp_loaded() set nocindent setlocal matchpairs+=<:> if !exists("g:neocomplcache_include_paths") let g:neocomplcache_include_paths ={} endif let g:neocomplcache_source_disable['include_complete']=1 endfunction " }}} " {{{ " }}} " dart {{{ " let g:quickrun_config.dart = { " \ "command" : g:dart_cmd, " \} augroup vimrc_group_dart autocmd! autocmd BufReadPost *.dart set shiftwidth=4 noexpandtab augroup END " }}} " Haskell {{{ command! -nargs=1 QuickHaskell :execute ":QuickRun haskell -outputter command_line -hook/u_nya_/enable 0 -src 'main = putStrLn $ show $ ".."'" " }}} " }}} source $VIMUSER/vimrcs/default/windowbuffer.vim " vim:set foldmethod=marker: