" ------------------------------------------------------------------------------------------------------------ " - * File: .vimrc " - * Author: itchyny " - * Last Change: 2013/01/12 18:06:04. " ------------------------------------------------------------------------------------------------------------ " INITIALIZE {{{ " ------------------------------------------------------------------------------------------------------------ set nocompatible filetype off let s:isunix = has('unix') let s:iswin = has('win16') || has('win32') || has('win64') let s:iscygwin = has('win32unix') let s:ismac = !s:iswin && !s:iscygwin && \ (has('mac') || has('macunix') || has('guimacvim') || system('uname') =~? '^darwin') let s:nosudo = $SUDO_USER == '' augroup ESC autocmd! augroup END augroup SetLocal autocmd! augroup END function! s:safeexecute(s, ...) if a:0 let check = a:1 else let check = a:s endif if exists(check) try silent execute a:s catch try silent execute 'call '.a:s catch endtry endtry endif endfunction " }}} " Bundles {{{ let $VIM = $HOME.'/.vim' let $BUNDLE = $VIM.'/bundle' let s:neobundle_dir = $BUNDLE.'/neobundle.vim' if !isdirectory(s:neobundle_dir) " neobundle {{{ " ------------------------------------------------------------------------------------------------------------ if executable('git') echo 'Initializing neobundle' execute '!mkdir -p '.$BUNDLE \.' && git clone git@github.com:Shougo/neobundle.vim.git '.$BUNDLE.'/neobundle.vim' \.' && git clone git@github.com:Shougo/unite.vim.git '.$BUNDLE.'/unite.vim' \.' && git clone git@github.com:Shougo/neocomplcache.git '.$BUNDLE.'/neocomplcache' \.' && git clone git@github.com:Shougo/vimproc.git '.$BUNDLE.'/vimproc' \.' && git clone git@github.com:Shougo/vimfiler.git '.$BUNDLE.'/vimfiler' \.' && git clone git@github.com:thinca/vim-quickrun.git '.$BUNDLE.'/vim-quickrun' \.' && git clone git@github.com:Shougo/vimshell.git '.$BUNDLE.'/vimshell' if s:ismac if executable('llvm-gcc') execute '!cd '.$BUNDLE.'/vimproc && make -f make_mac.mak' elseif executable('gcc') execute '!cd '.$BUNDLE.'/vimproc && gcc -O2 -W -Wall -Wno-unused -bundle -fPIC -arch x86_64 -arch ' \.'i386 -o autoload/vimproc_mac.so autoload/proc.c -lutil' else echo 'gcc not found!' endif elseif s:iswin echo 'access https://github.com/Shougo/vimproc/downloads to get dll' else if executable('gcc') execute '!cd '.$BUNDLE.'/vimproc && make -f make_unix.mak' else echo 'gcc not found!' endif endif else echo 'git not found! Sorry, this .vimrc cannot be completely used without git.' endif else execute 'set runtimepath+='.expand(s:neobundle_dir) call neobundle#rc(expand($BUNDLE)) NeoBundle 'Shougo/neobundle.vim' " nnoremap :NeoBundleUpdate nnoremap :Unite neobundle/update " }}} " Colorscheme {{{ " ------------------------------------------------------------------------------------------------------------ try NeoBundle 'itchyny/landscape.vim' colorscheme landscape catch endtry NeoBundle 'xterm-color-table.vim' " http://www.vim.org/scripts/script.php?script_id=3412 " }}} " Complement {{{ " ------------------------------------------------------------------------------------------------------------ if s:nosudo NeoBundle 'Shougo/neocomplcache' let g:neocomplcache_enable_at_startup = 1 let g:neocomplcache_enable_smart_case = 1 let g:neocomplcache_enable_underbar_completion = 1 let g:neocomplcache_enable_camel_case_completion = 1 let g:neocomplcache_enable_cursor_hold_i = 0 let g:neocomplcache_max_list = 10 let g:neocomplcache_skip_auto_completion_time = "0.50" NeoBundle 'Shougo/neosnippet' let g:neosnippet#snippets_directory = expand($VIM.'/snippets') imap neosnippet#expandable() neosnippet#jumpable() ? \ "\(neosnippet_expand_or_jump)" \: pumvisible() ? "\" : "\" smap neosnippet#expandable() neosnippet#jumpable() ? \ "\(neosnippet_expand_or_jump)" \: "\" NeoBundle 'ujihisa/neco-look' " --| Requirement: look commnad endif " }}} " Unite ( "," ) {{{ " ------------------------------------------------------------------------------------------------------------ let mapleader = "," if s:nosudo NeoBundle 'Shougo/unite.vim' let g:unite_enable_start_insert = 1 nnoremap :Unite nnoremap :Unite buffer -buffer-name=buffer nnoremap :Unite file/new directory/new -buffer-name=file/new,directory/new nnoremap :Unite output:message -buffer-name=output:message nnoremap :execute 'Unite file:'.change_directory().' file/new -buffer-name=file' nnoremap :Unite file_mru -buffer-name=file_mru nnoremap :Unite line -buffer-name=line augroup Unite autocmd! autocmd FileType unite nnoremap unite#do_action('split') autocmd FileType unite inoremap unite#do_action('split') autocmd FileType unite nnoremap unite#do_action('vsplit') autocmd FileType unite inoremap unite#do_action('vsplit') autocmd FileType unite inoremap autocmd FileType unite inoremap autocmd FileType unite nmap (unite_insert_enter) augroup END autocmd ESC FileType unite nnoremap :q autocmd ESC FileType unite inoremap :q highlight default link uniteSourcePrompt Identifier let s:startfiletypes = '.*\.\(exe\|png\|gif\|jpg\|jpeg\|bmp\|eps\|pdf\|mp3\|mp4\|avi\|mkv\)$' call unite#custom_source('file', 'ignore_pattern' \, '.*\.\(o\|exe\|dll\|bak\|sw[po]\|hi\|fff\|aux\|toc\|bbl\|blg\|DS_Store\)$') let auto_open = { \ 'description' : 'edit or open files', \ 'is_selectable' : 1, \ } function! auto_open.func(candidates) try for candidate in a:candidates if candidate.word =~? s:startfiletypes call unite#take_action('start', candidate) else call unite#take_action('open', candidate) endif endfor catch endtry endfunction call unite#custom_action('file', 'auto open', auto_open) call unite#custom_default_action('file', 'auto open') unlet auto_open NeoBundle 'Shougo/unite-build' nnoremap :Unite build -buffer-name=build NeoBundle 'unite-colorscheme' NeoBundle 'ujihisa/vim-ref' if executable('hoogle') NeoBundle 'ujihisa/ref-hoogle' " --| Requirement: hoogle " --| $ cabal install hoogle " --| $ hoogle data nnoremap h :Unite ref/hoogle -buffer-name=ref/hoogle endif NeoBundle 'h1mesuke/unite-outline' NeoBundle 'ujihisa/unite-haskellimport' endif " }}} " QuickRun / Filer / Outer world of Vim ( "\\" ) {{{ " ------------------------------------------------------------------------------------------------------------ let mapleader = "\\" NeoBundle 'Shougo/vimproc', { \ 'build' : { \ 'windows' : 'echo "Sorry, cannot update vimproc binary file in Windows."', \ 'cygwin' : 'make -f make_cygwin.mak', \ 'mac' : 'make -f make_mac.mak', \ 'unix' : 'make -f make_unix.mak', \ }, \ } NeoBundle 'thinca/vim-quickrun' let g:quickrun_config = {'*': {'runmode': 'async:vimproc', 'split': 'vertical', 'into': 1}} if executable('node') let g:quickrun_config.javascript = {'command' : 'node'} endif if executable('roy') let g:quickrun_config.roy = {'command' : 'roy'} endif if executable('pandoc') let g:quickrun_config.markdown = {'type' : 'markdown/pandoc', 'outputter': 'browser', 'cmdopt': '-s'} endif if executable('qcl') let g:quickrun_config.qcl = {'command': 'qcl'} endif if executable('runhaskell') let g:quickrun_config.haskell = {'command' : 'runhaskell'} let g:quickrun_config.lhaskell = {'command' : 'runhaskell'} endif if executable('autolatex') let g:quickrun_config.tex = {'command' : 'autolatex'} elseif executable('platex') let g:quickrun_config.tex = {'command' : 'platex'} endif if executable('man') let g:quickrun_config.nroff = {'command': 'man', \ 'args': " -P cat | tr '\b' '\1' | sed -e 's/.\1//g'", 'filetype': 'man'} endif if executable('autognuplot') let g:quickrun_config.gnuplot = {'command' : 'autognuplot'} elseif executable('gnuplot') let g:quickrun_config.gnuplot = {'command' : 'gnuplot'} endif if executable('bf') let g:quickrun_config.bf = {'command': 'bf'} endif nnoremap r :QuickRun nnoremap r :QuickRun >file:temp.dat nnoremap e :QuickRun nnoremap o :QuickRun file:output autocmd ESC FileType quickrun inoremap :q autocmd ESC FileType quickrun nnoremap :q autocmd ESC FileType quickrun vnoremap :q if s:nosudo NeoBundle 'Shougo/vimfiler' let g:vimfiler_as_default_explorer = 1 let g:vimfiler_sort_type = 'TIME' let g:vimfiler_safe_mode_by_default = 0 if s:iswin let g:vimfiler_tree_leaf_icon = '|' let g:vimfiler_tree_opened_icon = '-' let g:vimfiler_tree_closed_icon = '+' else let g:vimfiler_tree_leaf_icon = ' ' let g:vimfiler_tree_opened_icon = '▾' let g:vimfiler_tree_closed_icon = '▸' endif let g:vimfiler_file_icon = '-' if s:ismac let g:vimfiler_readonly_file_icon = '✗' let g:vimfiler_marked_file_icon = '✓' else let g:vimfiler_readonly_file_icon = 'x' let g:vimfiler_marked_file_icon = 'v' endif nnoremap f :VimFilerCurrentDir -buffer-name=vimfiler nnoremap :VimFilerCurrentDir -buffer-name=vimfiler nnoremap @ :VimFilerCurrentDir -buffer-name=vimfiler nnoremap @@ :VimFilerCurrentDir -buffer-name=vimfiler let g:vimfiler_execute_file_list = { 'pdf': 'open', 'PDF': 'open', \ 'png': 'open', 'PNG': 'open', \ 'jpg': 'open', 'JPG': 'open', \ 'jpeg': 'open', 'JPEG': 'open', \ 'gif': 'open', 'GIF': 'open', \ 'bmp': 'open', 'BMP': 'open', \ 'ico': 'open', 'ICO': 'open', \ 'ppt': 'open', 'PPT': 'open', \ 'html': 'open', 'HTML': 'open', \ } let s:usestatl = system('stat -l . > /dev/null 2>&1; echo $?') =~ '^0' function! s:changetime() let marked_files = vimfiler#get_marked_filenames() if !empty(marked_files) return endif let file = vimfiler#get_file() if empty(file) return endif let filepath = file.action__path let vimfiler_current_dir = get(unite#get_context(), 'vimfiler__current_directory', '') if vimfiler_current_dir == '' let vimfiler_current_dir = getcwd() endif let current_dir = getcwd() if s:usestatl let atime = system('stat -lt "%Y/%m/%d %H:%M" "'.filepath."\" | awk {'print $6\" \"$7'} | tr -d '\\n'") else let atime = system('stat --printf "%y" "'.filepath."\" | sed -e 's/\\..*//'") endif let atime = substitute(atime, '-', '/', 'g') try lcd `=vimfiler_current_dir` let newtime = input(printf('New time: %s -> ', atime)) redraw if newtime == '' let newtime = atime endif let newtime = substitute(newtime, '\d\@ autocmd FileType vimfiler nunmap \ autocmd FileType vimfiler nmap l autocmd FileType vimfiler nmap (vimfiler_redraw_screen) autocmd FileType vimfiler nmap O (vimfiler_sync_with_another_vimfiler) autocmd FileType vimfiler nmap e \ vimfiler#smart_cursor_map("\(vimfiler_cd_file)", "\(vimfiler_edit_file)") autocmd FileType vimfiler nmap t changetime() augroup END NeoBundle 'Shougo/vinarise' endif NeoBundle 'eagletmt/ghci-vim' augroup Ghci autocmd! autocmd FileType haskell nnoremap l call s:safeexecute(':GhciLoad') autocmd FileType haskell nnoremap i call s:safeexecute(':GhciInfo') autocmd FileType haskell nnoremap t call s:safeexecute(':GhciType') augroup END NeoBundle 'tyru/open-browser.vim' nmap b (openbrowser-smart-search) vmap b (openbrowser-smart-search) nmap s (openbrowser-search) NeoBundle 'mattn/webapi-vim' " }}} " vimshell ( ";" ) {{{ " ------------------------------------------------------------------------------------------------------------ let mapleader = ";" if s:nosudo NeoBundle 'Shougo/vimshell' " --| Requirement: vimproc " --| If you can't use sudo, do: " --| $ sudo chmod 4755 /usr/bin/sudo let g:vimshell_interactive_update_time = 150 let g:vimshell_popup_command = 'split' let g:vimshell_split_command = 'vsplit' let g:vimshell_user_prompt = 'fnamemodify(getcwd(), ":~")' let g:vimshell_prompt = ' $ ' let g:vimshell_disable_escape_highlight = 1 augroup Vimshell autocmd! " for easy window moving, unmap C-[hjkl] autocmd FileType vimshell iunmap autocmd FileType vimshell iunmap autocmd FileType vimshell iunmap autocmd FileType vimshell iunmap autocmd FileType vimshell nunmap autocmd FileType vimshell nunmap autocmd FileType vimshell nmap autocmd FileType vimshell nmap j autocmd FileType vimshell inoremap h autocmd FileType vimshell inoremap j autocmd FileType vimshell inoremap k autocmd FileType vimshell inoremap l autocmd FileType vimshell inoremap __ \ :call vimshell#execute('clear'):call vimshell#print_prompt():call vimshell#start_insert() autocmd FileType vimshell inoremap ^ \ :call vimshell#execute('cd ../'):call vimshell#print_prompt():call vimshell#start_insert() " disable unexpected deleting autocmd FileType vimshell nnoremap dj autocmd FileType vimshell nnoremap dk autocmd FileType vimshell nnoremap dg autocmd FileType vimshell vnoremap dj autocmd FileType vimshell vnoremap dk autocmd FileType vimshell vnoremap dg autocmd FileType vimshell vnoremap c autocmd FileType vimshell vnoremap autocmd FileType vimshell vnoremap a GA autocmd FileType vimshell vnoremap y yGA autocmd FileType vimshell imap " の設定では効かないので, エスケープ文字で設定してます. autocmd FileType vimshell inoremap OA unite#sources#vimshell_history#start_complete(!0) autocmd FileType vimshell inoremap OB unite#sources#vimshell_history#start_complete(!0) autocmd FileType vimshell nnoremap OA unite#sources#vimshell_history#start_complete(!0) autocmd FileType vimshell nnoremap OB unite#sources#vimshell_history#start_complete(!0) autocmd FileType vimshell inoremap unite#sources#vimshell_history#start_complete(!0) autocmd FileType vimshell inoremap unite#sources#vimshell_history#start_complete(!0) autocmd FileType vimshell nnoremap unite#sources#vimshell_history#start_complete(!0) autocmd FileType vimshell nnoremap unite#sources#vimshell_history#start_complete(!0) autocmd FileType vimshell autocmd BufEnter * call vimshell#start_insert(1) augroup END nnoremap s :VimShell -split nnoremap s :execute 'VimShellCreate '.current_directory_auto() nnoremap :execute 'VimShellPop '.current_directory_auto() nnoremap z :VimShellInteractive zsh nnoremap g :VimShellInteractive ghci nnoremap p :VimShellInteractive python if executable('ghc-mod') " neocomplcache (neco-ghc) throws fatal error when ghc-mod is not found NeoBundle 'ujihisa/neco-ghc' NeoBundle 'eagletmt/ghcmod-vim' " --| Requirement: ghc-mod " --| $ cabal install ghc-mod endif endif " }}} " Commenter / Utility / Matching ( "," ) {{{ " ------------------------------------------------------------------------------------------------------------ let mapleader = "," NeoBundle 'tpope/vim-surround' let g:surround_{char2nr('$')} = "$\r$" " for LaTeX NeoBundle 't9md/vim-surround_custom_mapping' NeoBundle 'tComment' augroup tComment autocmd! autocmd FileType gnuplot call tcomment#DefineType('gnuplot', '# %s') autocmd FileType haxe call tcomment#DefineType('haxe', '// %s') augroup END NeoBundle 'Align' NeoBundle 'errormarker.vim' NeoBundle 'mattn/calendar-vim' autocmd ESC FileType calendar nnoremap :q nnoremap c :Calendar NeoBundle 'autodate.vim' let g:autodate_format = '%Y/%m/%d %H:%M:%S' if has('python') NeoBundle 'sjl/gundo.vim' " --| Requirement: +python nnoremap g :GundoToggle autocmd ESC FileType gundo nnoremap :GundoToggle NeoBundle 'VimCalc' " --| Requirement: +python autocmd ESC FileType vimcalc nnoremap :q nnoremap a :Calc endif NeoBundle 'kana/vim-fakeclip' NeoBundle 'tsaleh/vim-matchit' NeoBundle 'gregsexton/MatchTag' NeoBundle 'matchit.zip' NeoBundle 'vimtaku/hl_matchit.vim.git' let g:hl_matchit_enable_on_vim_startup = 1 let g:hl_matchit_hl_groupname = 'MatchParen' let g:hl_matchit_allow_ft_regexp = 'vim\|sh\|tex' " }}} " Syntax {{{ " ------------------------------------------------------------------------------------------------------------ NeoBundle 'scrooloose/syntastic' if s:ismac let g:syntastic_error_symbol='✕' let g:syntastic_warning_symbol='⚠' endif let g:syntastic_enable_highlighting = 0 NeoBundle 'mattn/zencoding-vim' let g:user_zen_expandabbr_key = '' let g:user_zen_settings = { 'html' : { 'indentation' : ' ' }, } NeoBundle 'JavaScript-syntax' NeoBundle 'itspriddle/vim-javascript-indent' NeoBundle 'JSON.vim' NeoBundle 'html5.vim' NeoBundle 'wavded/vim-stylus' NeoBundle 'colorizer' augroup colorizer autocmd! autocmd BufNewFile,BufReadPost *.css ColorHighlight augroup END NeoBundle 'groenewege/vim-less' NeoBundle 'less.vim' NeoBundle 'syntaxm4.vim' NeoBundle 'vim-scripts/jade.vim' NeoBundle 'vim-coffee-script' NeoBundle 'rest.vim' NeoBundle 'VST' NeoBundle 'syntaxhaskell.vim' NeoBundle 'haskell.vim' NeoBundle 'vim-scripts/indenthaskell.vim' NeoBundle 'tpope/vim-markdown' NeoBundle 'haxe.vim' NeoBundle 'motemen/hatena-vim' " }}} " Powerline {{{ " ------------------------------------------------------------------------------------------------------------ NeoBundle 'Lokaltog/vim-powerline' try " --| $ sudo apt-get install fontforge " --| $ sudo apt-get install python-fontforge " --| $ cd ~/.vim/bundle/vim-powerline/fontpatcher " --| $ wget http://levien.com/type/myfonts/Inconsolata.otf " --| $ python ./fontpatcher ./Inconsolata.otf " --| $ sudo cp ./Inconsolata-Powerline.otf /usr/share/fonts set guifont=Inconsolata_for_Powerline:h11:cANSI set guifontwide=MS_Gothic:h11:cSHIFTJIS let g:Powerline_symbols = 'fancy' let g:Powerline_mode_n = 'NORMAL' call Pl#Hi#Allocate({ \ 'black' : 16, \ 'white' : 231, \ \ 'darkestgreen' : 22, \ 'darkgreen' : 28, \ \ 'darkestcyan' : 21, \ 'mediumcyan' : 117, \ \ 'darkestblue' : 24, \ 'darkblue' : 31, \ \ 'darkestred' : 52, \ 'darkred' : 88, \ 'mediumred' : 124, \ 'brightred' : 160, \ 'brightestred' : 196, \ \ 'darkestyellow' : 59, \ 'darkyellow' : 100, \ 'darkestpurple' : 57, \ 'mediumpurple' : 98, \ 'brightpurple' : 189, \ \ 'brightorange' : 208, \ 'brightestorange': 214, \ \ 'gray0' : 233, \ 'gray1' : 235, \ 'gray2' : 236, \ 'gray3' : 239, \ 'gray4' : 240, \ 'gray5' : 241, \ 'gray6' : 244, \ 'gray7' : 245, \ 'gray8' : 247, \ 'gray9' : 250, \ 'gray10' : 252, \ }) " 'n': normal mode " 'i': insert mode " 'v': visual mode " 'r': replace mode " 'N': not active let g:Powerline#Colorschemes#my#colorscheme = Pl#Colorscheme#Init([ \ Pl#Hi#Segments(['SPLIT'], { \ 'n': ['white', 'gray2'], \ 'N': ['gray0', 'gray0'], \ }), \ \ Pl#Hi#Segments(['mode_indicator'], { \ 'i': ['darkestgreen', 'white', ['bold']], \ 'n': ['darkestcyan', 'white', ['bold']], \ 'v': ['darkestpurple', 'white', ['bold']], \ 'r': ['mediumred', 'white', ['bold']], \ 's': ['white', 'gray5', ['bold']], \ }), \ \ Pl#Hi#Segments(['fileinfo', 'filename'], { \ 'i': ['white', 'darkestgreen', ['bold']], \ 'n': ['white', 'darkestcyan', ['bold']], \ 'v': ['white', 'darkestpurple', ['bold']], \ 'r': ['white', 'mediumred', ['bold']], \ 'N': ['gray0', 'gray2', ['bold']], \ }), \ \ Pl#Hi#Segments(['branch', 'scrollpercent', 'raw', 'filesize'], { \ 'n': ['gray2', 'gray7'], \ 'N': ['gray0', 'gray2'], \ }), \ \ Pl#Hi#Segments(['fileinfo.filepath', 'status'], { \ 'n': ['gray10'], \ 'N': ['gray5'], \ }), \ \ Pl#Hi#Segments(['static_str'], { \ 'n': ['white', 'gray4'], \ 'N': ['gray1', 'gray1'], \ }), \ \ Pl#Hi#Segments(['fileinfo.flags'], { \ 'n': ['white'], \ 'N': ['gray4'], \ }), \ \ Pl#Hi#Segments(['currenttag', 'fileformat', 'fileencoding', 'pwd', 'filetype', 'charcode', 'currhigroup'], { \ 'n': ['gray9', 'gray4'], \ }), \ \ Pl#Hi#Segments(['lineinfo'], { \ 'n': ['gray2', 'gray10'], \ 'N': ['gray2', 'gray4'], \ }), \ \ Pl#Hi#Segments(['errors'], { \ 'n': ['white', 'gray2'], \ }), \ \ Pl#Hi#Segments(['lineinfo.line.tot'], { \ 'n': ['gray2'], \ 'N': ['gray2'], \ }), \ \ Pl#Hi#Segments(['paste_indicator', 'ws_marker'], { \ 'n': ['white', 'brightred', ['bold']], \ }), \ \ Pl#Hi#Segments(['gundo:static_str.name'], { \ 'n': ['white', 'mediumred', ['bold']], \ 'N': ['brightred', 'darkestred', ['bold']], \ }), \ \ Pl#Hi#Segments(['gundo:static_str.buffer'], { \ 'n': ['white', 'darkred'], \ 'N': ['brightred', 'darkestred'], \ }), \ \ Pl#Hi#Segments(['gundo:SPLIT'], { \ 'n': ['white', 'gray2'], \ 'N': ['white', 'gray0'], \ }), \ ]) let g:Powerline_colorscheme = 'my' catch endtry " }}} endif " }}} Bundles " ENCODING {{{ " ------------------------------------------------------------------------------------------------------------ " SET {{{ set encoding=utf-8 set fenc=utf-8 set fileencodings=utf-8,euc-jp,sjis,jis,iso-2022-jp,cp932,latin set formatoptions+=mM " 日本語の行の連結時には空白を入力しない " ☆や□や○の文字があってもカーソル位置がずれないようにする " ambiwidthの設定のみでは, 解決しない場合がある " Ubuntuでは, gnome-terminal, terminatorを以下のコマンドに貼り替えると解決する " /bin/sh -c "VTE_CJK_WIDTH=1 terminator -m" " /bin/sh -c "VTE_CJK_WIDTH=1 gnome-terminal --disable-factory" " MacのiTermでは, Profiles>Text>Double-Width Characters " >Treat ambiguous-width characters as double widthにチェック set ambiwidth=double " }}} " 書類を開くことができませんでした。テキストエンコーディング日本語(Mac OS)には対応していません。 {{{ " http://d.hatena.ne.jp/uasi/20110523/1306079612 augroup SetUTF8Xattr autocmd! autocmd BufWritePost * call SetUTF8Xattr(escape(expand(""), "*[]?{}' ")) augroup END function! SetUTF8Xattr(file) let isutf8 = &fileencoding == "utf-8" || (&fileencoding == "" && &encoding == "utf-8") if s:ismac && isutf8 call system("xattr -w com.apple.TextEncoding 'utf-8;134217984' \"".a:file."\"") endif endfunction " }}} " 文字コードの自動認識 {{{ " http://www.kawaz.jp/pukiwiki/?vim#cb691f26 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 augroup AU_ReCheck_FENC autocmd! autocmd BufReadPost * call AU_ReCheck_FENC() augroup END endif " 改行コードの自動認識 set fileformats=unix,dos,mac " }}} " }}} ENCODING " APPERANCE {{{ " ------------------------------------------------------------------------------------------------------------ " Frame appearance {{{ " set showcmd set noshowmode " https://github.com/vim-jp/issues/issues/100 " }}} " Main appearance {{{ set list if s:iswin set listchars=tab:^I,nbsp:% else set listchars=tab:▸\ ,extends:»,precedes:«,nbsp:% endif set shortmess+=I " disable start up message set number autocmd SetLocal FileType vimshell,vimcalc,quickrun,int-ghci setlocal nonumber set cursorline autocmd SetLocal FileType calendar,vimcalc,vimshell,quickrun,int-ghci setlocal nocursorline set nocursorcolumn set showmatch set showtabline=1 set previewheight=20 set helplang=en set nospell function! s:autospell() if search("[^\x01-\x7e]", 'n') == 0 setlocal spell else setlocal nospell endif endfunction augroup autospell autocmd! autocmd FileType tex,md call autospell() augroup END set modeline set modelines=1 " }}} " Status line {{{ set ruler " show the cursor position (needless if you set 'statusline' later) set laststatus=2 " ステータスラインを常に表示 set statusline=%{expand('%:p:t')}\ %<[%{expand('%:p:h')}]%=\ %m%r%y%w[%{&fenc!=''?&fenc:&enc}] \[%{&ff}][%3l,%3c,%3p][%{strftime(\"%m/%d\ %H:%M\")}] " }}} " Color {{{ syntax enable set background=dark if !has('gui_running') set t_Co=256 endif " }}} " Statusline color {{{ if !exists('g:Powerline_loaded') let s:hi_sl = 'highlight StatusLine ' let s:hi_normal = s:hi_sl.'guifg=black guibg=blue gui=none ctermfg=black ctermbg=blue cterm=none' let s:hi_insert = s:hi_sl.'guifg=black guibg=darkmagenta gui=none ctermfg=black ctermbg=darkmagenta cterm=none' silent execute s:hi_normal augroup InsertStatus autocmd! autocmd InsertEnter * execute s:hi_insert autocmd InsertLeave * execute s:hi_normal augroup END endif if has('unix') && !has('gui_running') " ESC後にすぐ反映されない対策(実際これいる) inoremap endif " }}} " }}} APPERANCE " FILE READING {{{ " ------------------------------------------------------------------------------------------------------------ " SET {{{ set autoread " }}} " Filetype {{{ augroup Filetype autocmd! autocmd BufNewFile,BufReadPost,BufEnter *.bf setlocal filetype=bf autocmd BufNewFile,BufReadPost,BufEnter *.cls setlocal filetype=tex autocmd BufNewFile,BufReadPost,BufEnter *.gnuplot setlocal filetype=gnuplot autocmd BufNewFile,BufReadPost,BufEnter *.hs,*.y setlocal filetype=haskell autocmd BufNewFile,BufReadPost,BufEnter *.hx setlocal filetype=haxe autocmd BufNewFile,BufReadPost,BufEnter *.jade setlocal filetype=jade autocmd BufNewFile,BufReadPost,BufEnter *.json setlocal filetype=json autocmd BufNewFile,BufReadPost,BufEnter *.less setlocal filetype=less autocmd BufNewFile,BufReadPost,BufEnter *.md,*.mkd setlocal filetype=markdown autocmd BufNewFile,BufReadPost,BufEnter *.qcl setlocal filetype=qcl autocmd BufNewFile,BufReadPost,BufEnter *.r setlocal filetype=r autocmd BufNewFile,BufReadPost,BufEnter *.roy setlocal filetype=roy autocmd BufNewFile,BufReadPost,BufEnter *.rst setlocal filetype=rest autocmd BufNewFile,BufReadPost,BufEnter *.tex setlocal filetype=tex augroup END " }}} " Binary editor {{{ " http://d.hatena.ne.jp/goth_wrist_cut/20090809/1249800323 let $BINS = '*.bin,*.exe,*.png,*.gif,*.jpg,*.jpeg,*.bmp,*.PNG,*.JPG,*.JPEG,*.BMP,*.ico,*.pdf,*.dvi,*.pyc,*.mp3' augroup Binary autocmd! autocmd FileType xxd nnoremap ,b :%!xxd autocmd FileType xxd nnoremap ,r :%!xxd -r autocmd BufReadPre $BINS let &binary = 1 autocmd BufReadPost $BINS call BinReadPost() " autocmd BufWritePre $BINS call BinWritePre() " autocmd BufWritePost $BINS call BinWritePost() " autocmd CursorHold $BINS call BinReHex() function! BinReadPost() set filetype=xxd " execute '%!xxd' " let &binary = 1 endfunction function! BinWritePre() let s:saved_pos = getpos('.') silent %!xxd -r endfunction function! BinWritePost() silent %!xxd -g1 call setpos('.', s:saved_pos) set nomod endfunction function! BinReHex() let s:saved_pos = getpos('.') let s:modified = &modified silent %!xxd -r silent %!xxd -g1 call setpos('.', s:saved_pos) let &modified = s:modified endfunction augroup END " }}} " }}} FILE READING " EDIT {{{ " ------------------------------------------------------------------------------------------------------------ " Search {{{ set wrapscan " 最後まで検索したら先頭へ戻る set ignorecase " 大文字小文字無視 set smartcase " 検索文字列に大文字が含まれている場合は区別して検索する set incsearch " インクリメンタルサーチ set hlsearch " 検索文字をハイライト set magic " パターン中で.[*の特殊文字を使用する " }}} " Indent {{{ filetype plugin indent on set autoindent autocmd SetLocal FileType tex,hatena setlocal noautoindent set smartindent autocmd SetLocal FileType tex,hatena setlocal nosmartindent set shiftwidth=2 autocmd SetLocal FileType markdown setlocal shiftwidth=4 " }}} " Special keys (tab, backspace) {{{ set textwidth=0 " No auto breking line autocmd SetLocal FileType rest setlocal textwidth=50 set expandtab " insert spaces with set tabstop=2 retab set backspace=indent,eol,start " }}} " Clipboard {{{ set clipboard=unnamed set clipboard+=autoselect " }}} " IME {{{ set iminsert=0 set imsearch=-1 " }}} " Windows specific {{{ if s:iswin set noswapfile endif " }}} " Gui specific {{{ map map map " }}} " }}} EDIT " UTILITY {{{ " ------------------------------------------------------------------------------------------------------------ " On starting vim {{{ function! s:enter() silent call s:safeexecute('Pl#UpdateStatusline(1)', 'g:Powerline_colorscheme') if argc() == 0 silent call s:safeexecute(':VimFiler -buffer-name=vimfiler', ':VimFiler') endif endfunction augroup Enter autocmd! autocmd VimEnter * call s:enter() autocmd GUIEnter * simalt ~x augroup END " }}} " Move to the directory for each buffer, current directory functions {{{ function! s:directory_escape(directory) return escape(a:directory, '*[]?{} ') endfunction function! s:current_directory_raw() return substitute(expand('%:p:h'), '\*\(vinarise\|bitmapview\)\* - ', '', '') endfunction function! s:current_directory_escape() return s:directory_escape(s:current_directory_raw()) endfunction function! s:current_directory_auto() if &filetype ==# 'vimfiler' return s:directory_escape(b:vimfiler.current_dir) else return s:current_directory_escape() endif endfunction function! s:substitute_path_slash(path) return substitute(a:path, '\\', '/', 'g') endfunction function! s:current_directory_abbr() let path = s:current_directory_auto() let rawpath = s:current_directory_escape() if s:iswin if &filetype !=# 'vimfiler' let path = s:substitute_path_slash(path) endif let rawpath = s:substitute_path_slash(rawpath) endif return substitute(substitute(substitute(path, rawpath, '.', ''), '^./', '', ''), '^.$', '', '') endfunction function! s:change_directory() try execute ':lcd '.s:current_directory_auto() catch endtry return s:current_directory_abbr() endfunction augroup ChangeDirectory autocmd! autocmd BufEnter * call s:change_directory() augroup END " }}} " Enable omni completation {{{ augroup Omnifunc autocmd! autocmd FileType c setlocal omnifunc=ccomplete#Complete autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS autocmd FileType html setlocal omnifunc=htmlcomplete#CompleteTags autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS autocmd FileType php setlocal omnifunc=phpcomplete#CompletePHP autocmd FileType python setlocal omnifunc=pythoncomplete#Complete autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc augroup END setlocal omnifunc=syntaxcomplete#Complete " }}} " Make with S-F5 key (user omake) {{{ function! Automake() if filereadable('OMakefile') && executable('omake') execute '!omake' elseif filereadable('Makefile') || filereadable('makefile') execute '!make all' endif endfunction nnoremap :call Automake() " }}} " AOJ template {{{ function! AOJtemplate() call append( 0, '#include ') call append( 1, '#include ') call append( 2, '#include ') call append( 3, '#include ') call append( 4, '#include ') call append( 5, '#include ') call append( 6, '#include ') call append( 8, 'typedef long long ll;') call append( 9, 'using namespace std;') call append(10, '') call append(11, 'int main () {') call append(12, ' int i = 0, j = 0, k = 0, l = 0, m = 0, n = 0;') call append(13, '}') endfunction nnoremap ,,, :call AOJtemplate()zRjjjjjo "}}} " GCJTemplate {{{ function! GCJ() call append( 0, 'main = interact $ format . map solve . parseInput') call append( 1, '') call append( 2, 'parseInput = tail . map (map read . words :: String -> [Int]) . lines') call append( 3, '') call append( 4, 'format :: (Show a) => [a] -> String') call append( 5, 'format = unlines . map f . zip [1..]') call append( 6, ' where s x | ((==''"'') . head . show) x = init $ tail $ show x') call append( 8, ' | otherwise = show x') call append( 9, ' f x = "Case #" ++ show (fst x) ++ ": " ++ s (snd x)') call append(10, '') call append(11, 'solve (x:_) =') endfunction nnoremap ,p :call GCJ() " }}} " Open file explorer at current directory {{{ function! Explorer() if s:ismac execute '! open -a Finder .' elseif s:iswin silent execute '! start .' else execute '! nautilus .' endif endfunction nnoremap \n :call Explorer() nnoremap ge :call Explorer() " }}} " Quickly open with outer text editor {{{ function! TextEdit() if s:ismac execute '! open -a TextEdit %' elseif s:iswin silent execute '! notepad %' else execute '! gedit %' endif endfunction nnoremap \g :call TextEdit() " }}} " 新型戦闘力計測器 {{{ " http://d.hatena.ne.jp/thinca/20091031/1257001194 function! Scouter(file, ...) let pat = '^\s*$\|^\s*"' let lines = readfile(a:file) if !a:0 || !a:1 let lines = split(substitute(join(lines, "\n"), '\n\s*\\', '', 'g'), "\n") endif return len(filter(lines, 'v:val !~ pat')) endfunction command! -bar -bang -nargs=? -complete=file Scouter \ echo Scouter(empty() ? $MYVIMRC : expand(), 0) " }}} " view syntax name under cursor {{{ function! Syntax() :echo synIDattr(synID(line('.'), col('.'), 0), 'name') endfunction command! Syntax call Syntax() command! S call Syntax() nnoremap ss :Syntax " }}} " Quick open dot files {{{ if filereadable(expand('~/Dropbox/dotfiles/.vimrc')) nnoremap \. :e ~/Dropbox/dotfiles/.vimrc elseif filereadable(expand('~/.vimrc')) nnoremap \. :e ~/.vimrc endif if filereadable(expand('~/Dropbox/dotfiles/.zshrc')) nnoremap ;. :e ~/Dropbox/dotfiles/.zshrc elseif filereadable(expand('~/.zshrc')) nnoremap ;. :e ~/.zshrc endif " }}} " template for blog {{{ nnoremap ,cpp i>\|cpp\|\|\|< nnoremap ,sh i>\|sh\|\|\|< nnoremap ,hs i>\|haskell\|\|\|< " }}} " remove Icon\r file {{{ if s:ismac silent call system('echo -e "Icon\\r" | xargs cat && echo -e "Icon\\r" | xargs rm') endif " }}} " }}} UTILITY " OTHERS {{{ " ------------------------------------------------------------------------------------------------------------ " Performance {{{ set ttyfast " }}} " Command line {{{ set wildmode=list:longest " コマンドライン補間をシェルっぽく " }}} " }}} OTHERS " KEY MAPPING {{{ " ------------------------------------------------------------------------------------------------------------ " edit {{{ " Increment and decrement of alphabets, numbers " set nrformats+=alpha nnoremap + nnoremap - " fold by indentation nnoremap [ zak nnoremap ] j " indentation in visual mode vnoremap < >gv| " swap line/normal visual mode noremap v noremap v " easy copy, paste with clipboard if s:ismac vmap y "*y nmap y "*y nmap p "*p nmap P "*P vmap d "*d nmap d "*d vmap D "*D nmap D "*D endif " remove spaces at the end of lines nnoremap , ma:%s/ *$//`a " selecting all nnoremap gg inoremap gg vnoremap gg " smart Enter inoremap (pumvisible()?"\o":"\u\") " split by 80 characters nnoremap ,80 :s/\(.\{80,80}\)/\1/g:set nohlsearch vnoremap ,80 :s/\(.\{80,80}\)/\1/g:set nohlsearch " }}} " file {{{ " save nnoremap :w inoremap :w vnoremap :w " }}} " search {{{ nnoremap :set nohlsearch nnoremap / :set hlsearch/ nnoremap ? :set hlsearch? nnoremap * :set hlsearch* nnoremap # :set hlsearch# " }}} " Navigation {{{ " window " doesn't work, without the setting of inoremap h inoremap j inoremap k inoremap l nnoremap h nnoremap j nnoremap j nnoremap k nnoremap l nnoremap x vnoremap h vnoremap j vnoremap j vnoremap k vnoremap l vnoremap x inoremap nnoremap vnoremap let s:winwid = winwidth(0) function! AutoClose() try if &filetype == 'quickrun' silent execute 'q!' elseif &filetype == 'gundo' silent call feedkeys('q') elseif winwidth(0) < 2 * s:winwid / 3 silent execute 'q' elseif &filetype == '' && !&modified silent execute 'q!' elseif &modified elseif &filetype == 'vimshell' silent execute 'q' else silent execute 'bd!' endif catch endtry endfunction inoremap :call AutoClose() nnoremap :call AutoClose() vnoremap :call AutoClose() " tab nnoremap :tabnew inoremap gT inoremap gt nnoremap gT nnoremap gt vnoremap gT vnoremap gt " select last paste nnoremap gp '`['.strpart(getregtype(), 0, 1).'`]' " quit help with escapae key autocmd ESC FileType help nnoremap :q " disable EX-mode map " }}} " }}} KEY MAPPING " REFERENCE TO KEY MAPPING {{{ " ------------------------------------------------------------------------------------------------------------ " normal mode " +=========+=====================+=============+==================+===================+=================+ " | Leader | \ | ; | , | | " | b | OpenBrowser | | | NeoBundleInstall! | default | " | c | | | Calendar | default | | " | d | | | | default | | " | e | QuickRun h | " | i | | | | default | | " | j | | | | default | j | " +---------+---------------------+-------------+------------------+-------------------+-----------------+ " | k | | | | | k | " | l | | | | | l | " | m | | | | | | " | n | nautilus / Finder | | | | Unite file/new | " | o | QuickRun output | | | default | Unite file | " +---------+---------------------+-------------+------------------+-------------------+-----------------+ " | p | | Python | | | Unite buffer | " | q | | | | | (default) | " | r | QuickRun | | | default | default | " | s | OpenBrowser | VimShell | | | :w | " | t | | | | | tabnew | " +---------+---------------------+-------------+------------------+-------------------+-----------------+ " | u | | | | | Unite | " | v | | | | default | default | " | w | | | | | :q :bd | " | x | | | | | | " | y | | | | | | " +---------+---------------------+-------------+------------------+-------------------+-----------------+ " | z | | zsh | | | Unite file_mru | " | . | .vimrc | .zshrc | | | | " +=========+=====================+=============+==================+===================+=================+ " }}} REFERENCE TO KEY MAPPING " vim:foldmethod=marker