" legacy pathogen {{{ " http://www.adamlowe.me/2009/12/vim-destroys-all-other-rails-editors.html runtime! autoload/pathogen.vim if exists('g:loaded_pathogen') call pathogen#runtime_prepend_subdirectories(expand('~/.vimbundles')) try call pathogen#helptags() catch /Duplicate tag/ " do nothing endtry end " }}} " active neobundle {{{ set nocompatible filetype off if has('vim_starting') set runtimepath+=expand('~/.vimbundles/neobundle.vim') call neobundle#rc(expand('~/.vimbundles')) endif "NeoBundle 'git://github.com/Shougo/clang_complete.git' NeoBundle 'git://github.com/Shougo/echodoc.git' NeoBundle 'git://github.com/Shougo/neocomplcache.git' NeoBundle 'git://github.com/Shougo/neobundle.vim.git' "NeoBundle 'git://github.com/Shougo/unite.vim.git' NeoBundle 'git://github.com/Shougo/vim-vcs.git' NeoBundle 'git://github.com/Shougo/vimfiler.git' NeoBundle 'git://github.com/Shougo/vimshell.git' "NeoBundle 'git://github.com/Shougo/vimproc.git' NeoBundle 'git://github.com/Shougo/neocomplcache-snippets-complete.git' NeoBundle 'eagletmt/ghcmod-vim' NeoBundle 'git://gist.github.com/187578.git', {'directory': 'h2u_white'} NeoBundle 'tsukkee/lingr-vim' filetype plugin on filetype indent on nnoremap sn :Unite neobundle:install:! " }}} " vimproc {{{ let g:V = vital#of('vital') if !g:V.is_mac() let g:vimproc_dll_path = expand('~/.vimbundles/vimproc/autoload/vimproc_unix.so') " '/home/ujihisa/vimproc2/autoload/vimproc_unix.so' endif " }}} " settings {{{ set encoding=utf-8 set termencoding=utf-8 set fileencodings=ucs-bom,euc-jp,cp932,iso-2022-jp set fileformats=unix,dos,mac set ignorecase set smartcase set number set ruler set autoindent set nosmartindent set nocindent set shiftwidth=2 set tabstop=2 set expandtab set hlsearch set splitbelow set splitright set switchbuf=useopen set background=dark syntax enable set wildmode=list:longest set list set listchars=tab:>-,trail:-,extends:>,precedes:< set hidden set autoread set title set backspace=indent,eol,start set modeline set noequalalways " http://vim-users.jp/2009/06/hack31/ set t_Co=256 set cmdheight=3 " http://vim-users.jp/2009/06/hack32/ set directory-=. " http://vim-users.jp/2010/07/hack162/ if has('persistent_undo') set undodir=~/.vimundo augroup vimrc-undofile autocmd! autocmd BufReadPre ~/* setlocal undofile augroup END endif set equalalways set updatetime=500 " for Gentoo. " is this bug fixed already? set notagbsearch " }}} " mappings {{{ "let mapleader=" " "let maplocalleader=' ' let g:transparency = 10 if g:V.is_mac() " for MacVim's bug nnoremap :set nohlsearch:let &transparency = g:transparency else nnoremap :set nohlsearch end nnoremap / :set hlsearch/ nnoremap ? :set hlsearch? nnoremap * :set hlsearch* nnoremap # :set hlsearch# command! -nargs=0 Amp execute 'normal!' printf('/\<%s\>', expand('')) nnoremap & :set hlsearch:Amp nnoremap -- :e %:h omap p % nmap p % vmap p % nnoremap vv nnoremap ]p p`[=`] nnoremap sh h:call good_width() nnoremap sj j nnoremap sk k nnoremap sl l:call good_width() nnoremap H H:call good_width() nnoremap sJ J nnoremap sK K nnoremap L L:call good_width() function! s:good_width() let size = 84 if winwidth(0) < size execute "vertical resize" size endif endfunction " for plugins rewrite j/k nnoremap j nnoremap k nnoremap w :write nnoremap q :quit nnoremap Q :quit! nnoremap . :OpenVimrcTab "nnoremap cz :new ~/git/config/_zshrc "nnoremap ct :new ~/git/config/_termtter.erb "nnoremap h :help "nnoremap ] ] noremap j noremap k " inoremap 「」 " inoremap 【】 " undoable inoremap u inoremap u inoremap cnoremap "nnoremap a nnoremap aa :tabnew:pwd:VimShell nnoremap an :tabnew:CD ~/ "nnoremap ac :tabclose nnoremap aj :execute 'tabnext' 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$'):redraw nnoremap :execute 'tabnext' 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$'):redraw nnoremap :execute 'tabnext' 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$'):redraw inoremap :execute 'tabnext' 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$'):redraw inoremap :execute 'tabnext' 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$'):redraw nnoremap ak gT nnoremap gT nnoremap gT inoremap gT inoremap gT nnoremap Y y$ nnoremap co zo nnoremap cc zc " inoremap TabOrCompl() " function! TabOrCompl() " return (col('.') == 1 || matchstr(getline('.'), '.', col('.')-2) == "\t") ? "\\" : "\" " endfunction nnoremap s q:set filetype= nnoremap sr :set filetype=ruby "nnoremap sm :set filetype=markdown "nnoremap sh :set filetype=haskell "nnoremap sj :set filetype=javascript nnoremap spp :set filetype=phpierror_reporting(E_ERROR \| E_WARNING \| E_PARSE \| E_NOTICE \| E_STRICT); "nnoremap shs :set filetype=haskelli{-# LANGUAGE OverloadedStrings #-}import qualified Data.Text as Timport qualified Data.Text.IO as Tmain = doprint $ nnoremap shs :set filetype=haskellimain = doprint $ nnoremap ssl :set filetype=scala nnoremap scl :set filetype=clojure nnoremap b :w blogger:create "let g:blogger_ruby_path = '/Users/ujihisa/git/ruby193/local/bin/ruby' if filereadable("/Users/ujihisa/git/ruby200/local/bin/ruby") let g:blogger_ruby_path = "/Users/ujihisa/git/ruby200/local/bin/ruby" else let g:blogger_ruby_path = "/home/ujihisa/git/ruby/local/bin/ruby" endif let g:blogger_gist = 0 nnoremap I $i "nnoremap C $C nnoremap X ^x nnoremap cp Pjdd nnoremap Q nnoremap // /^ nnoremap s* ':%substitute/\<' . expand('') . '\>/' nnoremap n :new nnoremap N :call new_with_the_filetype() function! s:new_with_the_filetype() let f = &filetype new let &filetype = f endfunction " visual shifting (does not exit Visual mode) vnoremap < >gv " paste in insert mode is p while paste in command-line mode is ". " it's confusing. cnoremap p " " for speedup nnoremap /p /" "}}} " = for completion and \ for cancel {{{ inoremap = pumvisible() ? "\" : '=' inoremap \ pumvisible() ? "\" : '\' inoremap (vimrc_bs) neocomplcache#close_popup() . (pumvisible() ? '' : "\") imap (vimrc_bs) "function! s:wrapmap(key) " return pumvisible() ? "\(vimrc_bs)" : a:key "endfunction "inoremap pumvisible() ? neocomplcache#close_popup() . ' ' : ' ' " }}} " Cr in Insert Mode always means newline {{{ function! CrInInsertModeAlwaysMeansNewline() "let a = (exists('b:did_indent') ? "\" : "") . "\X\" let a = "\X\" return pumvisible() ? neocomplcache#close_popup() . a : a endfunction "inoremap pumvisible() ? neocomplcache#close_popup()."\\X\" : "\\X\" inoremap CrInInsertModeAlwaysMeansNewline() " }}} " Flip Arguments {{{ " f(a, b) to f(b, a) when your cursol is on '('. function! FlipArguments() normal! y% let @" = split(system('flipper "' . @" . '"'), "\n")[0] execute "normal! %p\d%" endfunction nnoremap flip :call FlipArguments() " }}} " vimshell {{{ function! EmptyBufferP() return expand('%') == '' && !&modified endfunction "nnoremap v EmptyBufferP() ? ":VimShell" : ":new:VimShell" "nnoremap V EmptyBufferP() ? ":VimShell" : ":vnew:VimShell" "nmap V (vimshell_split_switch) "nmap v (vimshell_switch) nmap v (vimshell_split_switch) nnoremap V :new:VimShellCreate let g:vimshell_user_prompt = 'fnamemodify(getcwd(), ":~")' let g:vimshell_prompt = '$ ' let g:vimshell_split_command = 'vnew' autocmd FileType vimshell call s:vimshell_local() function! s:vimshell_local() imap pumvisible() ? "\(vimrc_bs)" : "\(vimshell_another_delete_backward_char)" nmap j (vimshell_next_prompt) nmap k (vimshell_previous_prompt) " deleting (vimshell_delete_previous_output) nunmap nmap (vimshell_delete_previous_output) endfunction autocmd FileType int-* call s:vimshell_iexe() function! s:vimshell_iexe() "imap (vimshell_int_another_delete_backward_char) nmap j (vimshell_int_next_prompt) nmap k (vimshell_int_previous_prompt) endfunction " }}} " tag opens in a new window {{{ "if 0 " if you want to use gtags " function! s:tagjump_in_new_window() " if filereadable("GTAGS") " sp " GtagsCursor " else " execute "normal! \\" " endif " endfunction " " function! s:tagjump_or_cr() " if bufname('%') == '[Command Line]' || &buftype == 'quickfix' " execute "normal! \" " else " if filereadable("GTAGS") " GtagsCursor " else " execute "normal! \" " endif " endif " endfunction " let Gtags_OpenQuickfixWindow = 0 "else function! s:tagjump_in_new_window() execute "normal! \\" "http://d.hatena.ne.jp/thinca/20110202 "UniteWithCursorWord -immediately -no-start-insert -auto-preview -default-action=split tag endfunction function! s:tagjump_or_cr() if bufname('%') == '[Command Line]' || &buftype == 'quickfix' execute "normal! \" else execute "normal! \" "http://d.hatena.ne.jp/thinca/20110202 "UniteWithCursorWord -immediately -no-start-insert -auto-preview tag endif endfunction nnoremap :call tagjump_in_new_window() nnoremap :call tagjump_or_cr() " }}} " unite-grep {{{ nnoremap sg :Unite grep:. -default-action=split nnoremap sG :execute 'Unite grep:.:-iR:' . expand('') . ' -default-action=split' " }}} " {{{ thinca/poslist.vim nmap (poslist_prev) nmap (poslist_next) " }}} " MacBook Battery http://d.hatena.ne.jp/lurker/20060801/1154443551 {{{ command! Battery echo split(system("pmset -g ps | egrep -o '[0-9]+%'"), "\n")[0] " }}} " Backslashes in the commands :e and :cd are ~/ {{{ "function! HomedirOrBackslash() " if getcmdtype() == ':' " for i in split('e cd CD new vnew so', ' ') " if getcmdline() =~# printf('^%s ', i) " return '~/' " endif " endfor " if getcmdline() =~# '^?\?!' " return '~/' " endif " endif " return '\' "endfunction "cnoremap HomedirOrBackslash() "cnoremap \ smartchr#one_of('~/', '\') " }}} " http://vim-users.jp/2009/11/hack96/ {{{ "autocmd FileType * "\ if &l:omnifunc == '' "\ | setlocal omnifunc=syntaxcomplete#Complete "\ | endif "}}} " remote {{{ command! -nargs=1 RunOnVm !run_on_vm % " }}} " Neocomplecache {{{ let g:neocomplcache_enable_at_startup = 1 "let g:NeoComplCache_EnableQuickMatch = 0 "cnoreabbrev ne NeoComplCacheEnable "inoremap neocomplcache#undo_completion() "if !exists('g:NeoComplCache_OmniPatterns') " let g:NeoComplCache_OmniPatterns = {} "endif " below is the copy from ruby's. "let g:NeoComplCache_OmniPatterns.haskell = '[^. *\t]\.\h\w*' "let g:NeoComplCache_CachingDisablePattern = '\[Command line\]' "let g:neocomplcache_manual_completion_length = 2 let g:neocomplcache_plugin_completion_length = { \ 'include_complete': 1} let g:neocomplcache_plugin_rank = { \ 'include_complete': 11} let g:neocomplcache_max_list = 200 let g:neocomplcache_max_keyword_width = 70 "let g:neocomplcache_enable_smart_case = 1 "let g:neocomplcache_enable_ignore_case = 0 "let g:neocomplcache_text_mode_filetypes = { " \ 'text': 0, 'help': 0, 'tex': 0, 'gitcommit': 0, 'nothing': 0} let g:neocomplcache_text_mode_filetypes = {} let g:neocomplcache_text_mode_filetypes.markdown = 1 imap (neocomplcache_start_unite_complete) imap (neocomplcache_snippets_expand) imap (neocomplcache_snippets_jump) nmap a autocmd FileType haskell nnoremap :NeoComplCacheCachingGhc let g:neocomplcache_auto_completion_start_length = 1 " }}} " thinca's local vimrc http://vim-users.jp/2009/12/hack112/ {{{ " Load settings for eacy location. augroup vimrc-local autocmd! autocmd BufNewFile,BufReadPost * call s:vimrc_local(expand(':p:h')) augroup END function! s:vimrc_local(loc) let files = findfile('.vimrc.local', escape(a:loc, ' ') . ';', -1) for i in reverse(filter(files, 'filereadable(v:val)')) source `=i` endfor endfunction " }}} function! OpenVimrcTab() " {{{ tabnew TabpageCD ~/git/config edit ~/git/config/_vimrc endfunction " }}} " My commands {{{ command! -nargs=0 OpenVimrcTab call OpenVimrcTab() command! -nargs=1 OpenRubydoc new ~/rubydoc/doctree/refm/api/src/.rd command! -nargs=0 Ctags call Ctags() function! Ctags() let cmdname = globpath(&rtp, 'plugin/vimproc.vim') != '' ? 'VimProcBang' : '!' execute cmdname 'ctags -R' if globpath(&rtp, 'plugin/unite.vim') != '' NeoComplCacheCachingTags endif endfunction " }}} command! SplitNicely call s:split_nicely() " {{{ function! s:split_nicely() if 80*2 * 15/16 <= winwidth(0) " FIXME: threshold customization vsplit else split endif endfunction " }}} " rak {{{ "command! -nargs=* Rak call Rak("") "function Rak(args) " new " execute "r!rak --nocolour" a:args " nnoremap o :spgf "endfunction " "call altercmd#load() "command! "\ -bar -nargs=+ "\ AlterCommandWrapper "\ CAlterCommand | AlterCommand " "AlterCommandWrapper rak Rak " }}} " unite {{{ if globpath(&rtp, 'plugin/unite.vim') != '' nnoremap ss :Unite file_rec -default-action=split nnoremap se :Unite file_rec nnoremap so :Unite outline -auto-preview nnoremap sc :Unite colorscheme font -auto-preview nnoremap sf :Unite file -default-action=split nnoremap sm :Unite file_mru -default-action=split nnoremap sb :Unite buffer -default-action=split nnoremap sra :Unite rake nnoremap sre :Unite ref/man ref/hoogle ref/pydoc -default-action=split nnoremap su q:Unite nnoremap R :Unite quicklearn -immediately "AlterCommandWrapper unite Unite endif let g:unite_enable_start_insert = 1 let g:unite_enable_split_vertically = 1 let g:unite_kind_openable_cd_command = 'CD' let g:unite_source_file_rec_ignore_pattern = 'phpdoc\|\%(^\|/\)\.$\|\~$\|\.\%(o\|exe\|dll\|bak\|sw[po]\|class\)$\|\%(^\|/\)\.\%(hg\|git\|bzr\|svn\)\%($\|/\)' let g:unite_quick_match_table = { \'a' : 1, 's' : 2, 'd' : 3, 'f' : 4, 'g' : 5, 'h' : 6, 'j' : 7, 'k' : 8, 'l' : 9, ':' : 10, \'q' : 11, 'w' : 12, 'e' : 13, 'r' : 14, 't' : 15, 'y' : 16, 'u' : 17, 'i' : 18, 'o' : 19, 'p' : 20, \'1' : 21, '2' : 22, '3' : 23, '4' : 24, '5' : 25, '6' : 26, '7' : 27, '8' : 28, '9' : 29, '0' : 30, \} " in other words, it just swaps : and ; autocmd FileType unite call s:unite_my_settings() function! s:unite_my_settings()"{{{ silent! nunmap silent! nunmap silent! iunmap silent! iunmap endfunction"}}} " }}} augroup MyVim " {{{ autocmd! if has('gui_running') autocmd FileType vim nnoremap gs :source %:source $MYGVIMRC else autocmd FileType vim nnoremap gs :source % endif augroup END " }}} " Big and Man {{{ command! Big wincmd _ | wincmd | "AlterCommandWrapper big Big "AlterCommandWrapper man Man " }}} " fuzzyfinder {{{ if 0 nnoremap ff :FuzzyFinderFile nnoremap fm :FuzzyFinderMruFile nnoremap fr :FuzzyFinderBuffer if !exists('g:FuzzyFinderOptions') let g:FuzzyFinderOptions = { 'Base':{}, 'Buffer':{}, 'File':{}, 'Dir':{}, 'MruFile':{}, 'MruCmd':{}, 'Bookmark':{}, 'Tag':{}, 'TaggedFile':{}} let g:FuzzyFinderOptions.Base.key_open = '' let g:FuzzyFinderOptions.Base.key_open_split = '' let g:FuzzyFinderOptions.Base.key_open_vsplit = '' endif endif " }}} if has('mac') " {{{ " Option+Arrow keys set =OC set =OD set =OA set =OB nnoremap > nnoremap nnoremap + nnoremap - " Arrow keys nnoremap  l nnoremap  h nnoremap  nnoremap  " Shift+Arrow keys (actually I cannot use it on a terminal) nnoremap O2C :bn nnoremap O2D :bp nnoremap O2A i上 nnoremap O2B i下 " arrow and arrow keys nnoremap  j nnoremap  k endif " }}} "legacy {{{ "set formatoptions=tcq " http://subtech.g.hatena.ne.jp/secondlife/20080603/1212489817 "let git_diff_spawn_mode=1 "}}} " for git {{{ augroup MyGit autocmd! autocmd BufWinEnter,BufNewFile COMMIT_EDITMSG set filetype=git augroup END let g:git_diff_spawn_mode = 2 " }}} " command! GitGol call s:git_gol() " {{{ " function! s:git_gol() " vnew " read!for i in $(git log --pretty=oneline | head -n 10 | cut -d ' ' -f 1); do git show $i --color-words; done " endfunction " }}} " motemen's escape sequence {{{ function! HighlightConsoleCodes() 0 let register_save = @" while search('^[\[[0-9;]*m', 'c') normal! dfm let [lnum, col] = getpos('.')[1:2] if len(getline('.')) == col let col += 1 endif let syntax_name = 'ConsoleCodeAt_' . bufnr('%') . '_' . lnum . '_' . col execute 'syntax region' syntax_name 'start=+\%' . lnum . 'l\%' . col . 'c+ end=+\%$+' 'contains=ALL' let highlight = '' for color_code in split(matchstr(@", '[0-9;]\+'), ';') if color_code == 0 let highlight .= ' ctermfg=NONE ctermbg=NONE' elseif color_code == 1 let highlight .= ' cterm=bold' elseif 30 <= color_code && color_code <= 37 let highlight .= ' ctermfg=' . (color_code - 30) elseif color_code == 38 " TODO elseif color_code == 39 " TODO elseif 40 <= color_code && color_code <= 47 let highlight .= ' ctermbg=' . (color_code - 40) elseif color_code == 49 " TODO endif endfor if len(highlight) execute 'highlight' syntax_name highlight endif endwhile let @" = register_save 0 endfunction autocmd BufRead,StdinReadPost * if search('^[[\d*m', 'n') | call HighlightConsoleCodes() | set buftype=nofile nomodifiable | endif " `:set modifiable | undo | syntax clear' to revert " }}} augroup MySomething " {{{ autocmd! autocmd BufWinEnter,BufNewFile *.io setfiletype io autocmd BufWinEnter,BufNewFile *_spec.rb set filetype=ruby.rspec autocmd BufWinEnter,BufNewFile *.tex.erb set filetype=tex.eruby " set filetype=twitter and then... autocmd FileType twitter inoremap :execute '!twitter post "' . escape(getline('.'), '"!#%') . '" >&/dev/null &'o "autocmd FileType mixiim inoremap 2GdG:MixiEchoGetddO "autocmd FileType mixispam inoremap :MixiEchoo "autocmd FileType spamspam inoremap :execute '!twitter post "' . escape(getline('.'), '"!#') . '" >&/dev/null &':MixiEchoo augroup END " }}} augroup RubyTrunk " {{{ autocmd! autocmd BufWinEnter,BufNewFile ~/git/ruby/*.c setl ts=8 noexpandtab autocmd BufWinEnter,BufNewFile ~/git/ruby/*.y setl ts=8 noexpandtab "autocmd BufWinEnter,BufNewFile ~/rubies/src/**/*.c setl ts=8 noexpandtab augroup END " }}} "augroup RubySpec " {{{ " autocmd! " autocmd BufWinEnter,BufNewFile ~/git/ruby-trunk/spec/rubyspec/*.rb " \ let b:quickrun_command = " \ '/usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t ~/rubies/bin/ruby192' " "\ '/usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t ~/git/ruby-trunk/ruby19/bin/ruby' "augroup END " }}} " irb {{{ " augroup MyIRB " autocmd! " autocmd FileType irb inoremap :ruby v=VIM::Buffer.current;v.append(v.line_number, '#=> ' + eval(v[v.line_number]).inspect)jo " augroup END " nnoremap irb :vnew:setfiletype irb " }}} " quickrun {{{ for mine let g:quickrun_direction = 'rightbelow vertical' let g:quickrun_no_default_key_mappings = 0 " suspend to map r " nnoremap r :call quickrun_of_buffer() " function! s:quickrun_of_buffer() " if !exists('b:quickrun_of_buffer') " let b:quickrun_of_buffer = '' " endif " echo 'QuickRun' b:quickrun_of_buffer " execute 'QuickRun' b:quickrun_of_buffer " endfunction " function! Quickrun_open_test_window() " new " setfiletype ruby " execute "normal (quickrun)" " execute "normal H7_" " execute "normal p" " q! " endfunction " }}} " quickrun for thinca {{{ "nmap r :QuickRun nmap r (quickrun) let g:quickrun_config = {} let g:quickrun_config._ = {'runner': 'vimproc', 'split': 'below'} let g:quickrun_config.coffee = {'command': 'coffee', 'exec': '%c -cpb %s'} let g:quickrun_config.asm = {'command': 'gcc', 'exec': ['gcc %s -o ./aaaaa', './aaaaa', 'rm ./aaaaa']} let g:quickrun_config['ruby.rspec'] = {'command': "spec -l {line('.')}"} let g:quickrun_config.textile = { \ 'command': 'redcloth', \ 'tempfile': '{tempname()}.textile', \ 'exec': ['%c %s > %s:p:r.html', 'open %s:p:r.html', 'sleep 1', 'rm %s:p:r.html'] } "let g:quickrun_config.go = { "\ 'command': '8g', "\ 'exec': ['8g %s', '8l -o %s:p:r %s:p:r.8', '%s:p:r %a', 'rm -f %s:p:r'] "\ } let g:quickrun_config['ruby'] = {'command': 'ruby'} let g:quickrun_config['R'] = {'command': 'R', 'exec': ['%c -s --no-save -f %s', ':%s/.\b//g']} "let g:quickrun_config['clojure'] = {'command': 'java -cp /Users/ujihisa/git/clojure/clojure.jar clojure.main'} let g:quickrun_config['markdown'] = { \ 'type': 'markdown/pandoc', \ 'cmdopt': '-s', \ 'outputter': 'browser' \ } let g:quickrun_config['scala'] = { \ 'cmdopt': g:quickrun#default_config.scala.cmdopt . ' -unchecked -cp ' . join(reverse(split(vimproc#system('find ~/.ivy2/cache/ -name "*.jar"'), "\n")), ":")} "let g:quickrun_config.haskell = {'exec': ['runghc ~/.vim/sortimport.hs %s > %s.tmp', 'mv %s.tmp %s', '%c %s -o %s:p:r'], 'command': 'runghc', 'runner': 'system'} " \ 'erlang': { " \ 'command': 'escript', " +\ 'exec': ['echo "#!escript\n%%%%! -smp enable -sname quickrun -mnesia debug verbose" > %s.tmp', 'cat %s >> %s.tmp', 'mv %s.tmp %s', '%c %s %a', ':call delete("%s.tmp")', ':call delete("%s")'], " +\ 'tempfile': '{fnamemodify(tempname(), ":h")}/quickrun', " \ }, " }}} " filetype aliases http://vim-users.jp/2010/04/hack138/ {{{ augroup FiletypeAliases autocmd! autocmd FileType js set filetype=javascript autocmd FileType cf set filetype=coffee augroup END " }}} " for git-vim (motemen) {{{ "let g:git_command_edit = 'rightbelow vnew' nnoremap gd :GitDiff --no-prefix --cached nnoremap gD :GitDiff --no-prefix nnoremap gs :GitStatus nnoremap gS :Git submodule foreach git status "nnoremap gl :GitLog "nnoremap gL :GitLog -u \| head -10000 if globpath(&rtp, 'plugin/shadow.vim') != '' nnoremap ga :call GitAddBoth() else nnoremap ga :GitAdd endif nnoremap gA :GitAdd nnoremap gc :GitCommit nnoremap gC :GitCommit --amend nnoremap gp :Git push " }}} " TeX Supports {{{ " F5 to -- "augroup LatexSuite " au LatexSuite User LatexSuiteFileType " \ imap -- Tex_FastEnvironmentInsert "augroup END " lates-suite is so evil. don't use it. " LaTeX-Suite let g:Tex_SmartKeyQuote = 0 " beamer.tex support let g:Tex_FoldedSections = 'part,chapter,section,%%fakesection,frame,' \. 'subsection,subsubsection,paragraph' " flymake/tex "augroup FlymakeTex " autocmd! " autocmd BufWritePost *.tex silent !rake tex &>/dev/null & "augroup END let g:Tex_DefaultTargetFormat = 'pdf' let g:Tex_FormatDependency_pdf = 'bib,dvi' let g:Tex_CompileRule_bib = 'bibtex $*.aux' let g:Tex_CompileRule_pdf = 'dvipdfmx $*.dvi' if has('mac') let g:Tex_CompileRule_dvi = 'platex -kanji=utf8 -interaction=nonstopmode $*' let g:Tex_ViewRule_pdf = 'open' else let g:Tex_CompileRule_dvi = '/opt/ptexlive/bin/platex -kanji=utf8 -interaction=nonstopmode $*' let g:Tex_ViewRule_pdf = 'acroread' endif " }}} " misc {{{ augroup MyKeywordprg autocmd! autocmd FileType twitter setl keywordprg=dictionary augroup END " save with growl "nnoremap w :write:silent !growlnotify -n vim -m '[write] %' >&/dev/null:echo expand('%') "nnoremap q :silent !growlnotify -n vim -m '[quit] %' >&/dev/null:quit "set cursorline "set cursorcolumn " }}} " html {{{ function! s:HtmlEscape() silent s/&/\&/eg silent s//\>/eg endfunction function! s:HtmlUnEscape() silent s/<//eg silent s/&/\&/eg endfunction vnoremap e :call HtmlEscape() vnoremap ue :call HtmlUnEscape() " }}} " for quicklaunch {{{ "let g:quicklaunch_commands = [ " \ 'ruby launch.rb', " \ 'ls', " \ 'ls -a', " \ 'ls -l', " \ 'ruby check_gmail.rb', " \ 'twitter timeline', " \ 'port outdated', " \ '', " \ '', " \ 'tail -n 30 ~/.zsh_history' " \ ] "for i in range(10) " execute "silent! nmap " . i . " (quicklaunch-" . i . ")" "endfor "silent! nmap l (quicklaunch-list) " }}} " kana's useful tab function {{{ function! s:move_window_into_tab_page(target_tabpagenr) " Move the current window into a:target_tabpagenr. " If a:target_tabpagenr is 0, move into new tab page. if a:target_tabpagenr < 0 " ignore invalid number. return endif let original_tabnr = tabpagenr() let target_bufnr = bufnr('') let window_view = winsaveview() if a:target_tabpagenr == 0 tabnew tabmove " Move new tabpage at the last. execute target_bufnr 'buffer' let target_tabpagenr = tabpagenr() else execute a:target_tabpagenr 'tabnext' let target_tabpagenr = a:target_tabpagenr topleft new " FIXME: be customizable? execute target_bufnr 'buffer' endif call winrestview(window_view) execute original_tabnr 'tabnext' if 1 < winnr('$') close else enew endif execute target_tabpagenr 'tabnext' endfunction " }}} " ao move current buffer into a new tab. {{{ "nnoremap ao :call move_window_into_tab_page(0) nnoremap ao T " }}} " shell-like guyon cd {{{ "command! CD call CD() "function! CD() " let b:old_dir = getcwd() " execute "lcd " . expand("%:p:h") "endfunction "command! CDB call CDB() "function! CDB() " let tmp = getcwd() " execute "lcd " . b:old_dir " let b:old_dir = tmp "endfunction " }}} " kana's tabpagecd with my fix {{{ "let s:TRUE = 1 "augroup MyAutoCmd " autocmd! "augroup END " "command! -complete=customlist,s:complete_cdpath -nargs=+ CD TabpageCD "function! s:complete_cdpath(arglead, cmdline, cursorpos) " return split(globpath(&cdpath, " \ join(split(a:cmdline, '\s', s:TRUE)[1:], ' ') . '*/'), " \ "\n") "endfunction " "AlterCommandWrapper cd CD "" TabpageCD - wrapper of :cd to keep cwd for each tabpage " "command! -nargs=? TabpageCD "\ execute 'cd' fnameescape() "\ | let t:cwd = getcwd() " "autocmd MyAutoCmd TabEnter * "\ if !exists('t:cwd') "\ | let t:cwd = getcwd() "\ | endif "\ | execute 'cd' fnameescape(t:cwd) " }}} " shougo's tabpagecd {{{ " Each tab has current directory command! -bar -complete=dir -nargs=? \ CD \ TabpageCD command! -bar -complete=dir -nargs=? \ TabpageCD \ execute 'cd' fnameescape(expand()) \ | let t:cwd = getcwd() autocmd TabEnter * \ if exists('t:cwd') && !isdirectory(t:cwd) \ | unlet t:cwd \ | endif \ | if !exists('t:cwd') \ | let t:cwd = getcwd() \ | endif \ | execute 'cd' fnameescape(expand(t:cwd)) " Exchange ':cd' to ':TabpageCD'. "cnoreabbrev cd (getcmdtype() == ':' && getcmdline() ==# 'cd') ? 'TabpageCD' : 'cd' "AlterCommandWrapper cd CD "}}} " open lib and corresponding test at a new tab {{{ command! -nargs=1 Lib call s:open_lib_and_corresponding_test() "AlterCommandWrapper lib Lib function! s:open_lib_and_corresponding_test(fname) execute 'tabnew lib/' . a:fname . '.rb' execute 'vnew spec/' . a:fname . '_test.rb' execute "normal \(quickrun)\J\7_" endfunction " }}} " gist.vim {{{ let g:gist_clip_command = 'pbcopy' " }}} " color {{{ " colorscheme desert " highlight Cursor ctermbg=black " highlight Pmenu cterm=standout ctermfg=2 ctermbg=black " highlight PmenuSel cterm=bold ctermfg=2 ctermbg=black " highlight PmenuSbar ctermbg=0 " highlight StatusLine term=standout cterm=underline ctermfg=2 " highlight StatusLineNC cterm=underline " highlight VertSplit cterm=NONE " highlight LineNr ctermfg=2 " highlight TabLineFill ctermfg=0 " }}} command! LeftSpace call s:left_space() " {{{ function! s:left_space() let bufname = printf('[leftspace:%s]', tabpagenr()) let bufnr = bufnr(bufname) " FIXME: escape. let winnr = bufwinnr(bufnr) if winnr == -1 " create execute "topleft 20vnew " . bufname setlocal nomodifiable wincmd p else " destroy execute winnr "wincmd w" wincmd c wincmd p endif endfunction "AlterCommandWrapper leftspace LeftSpace " }}} " Say supports {{{ command! Say silent execute '!say "' . escape(getline('.'), '"') . '" &>/dev/null &' augroup SayCurrentLine autocmd! autocmd FileType say nnoremap j j:Say autocmd FileType say nnoremap k k:Say augroup END " }}} " Substitute all spaces for indentation to underlines {{{ " " before: " def aaa " hi " end " after: " def aaa " __hi " end command! -nargs=0 LeadUnderscores %s/^\s*/\=repeat('_', strlen(submatch(0)))/g " }}} " replace v_p {{{ vnoremap p :call yank_paste_without_yanking() function! s:yank_paste_without_yanking() let a = @" normal! gvp let @" = a endfunction " }}} " smartword {{{ "if globpath(&rtp, 'autoload/smartword.vim') != '' " map w (smartword-w) " map b (smartword-b) " map e (smartword-e) " map ge (smartword-ge) " noremap W w " "noremap B b " noremap E e " noremap gE ge "endif " }}} " Require secret password file {{{ if filereadable(expand('~/.vimrc_secret')) source ~/.vimrc_secret endif " This file should let following variables: " Blogger.vim " * g:blogger_blogid " * g:blogger_email " * g:blogger_pass " * g:lingr_vim_user " * g:lingr_vim_password " }}} " XML, HTML completion {{{ "augroup MyXML " autocmd! " autocmd Filetype xml inoremap " autocmd Filetype html inoremap "augroup END " }}} " Rename (See Vim Hacks #17 {{{ command! -nargs=1 -complete=file Rename f |call delete(expand('#')) " }}} " C/C++ semicolon support {{{ "function! s:smartsemicolon() " let s = getline('.') " if s != "" && match(s, '#.*\|.*//.*\|/\*\|\*/\|\s*$\|.*[;({},]$') " normal! a; " endif "endfunction "augroup MyCSemicolon " autocmd! " "autocmd Filetype c inoremap :call smartsemicolon() " "autocmd Filetype cpp inoremap :call smartsemicolon() " " autocmd FileType c inoremap : ; " autocmd FileType c inoremap ; : " " autocmd FileType cpp inoremap : ; " autocmd FileType cpp inoremap ; : "augroup END " }}} " C/C++ compiler {{{ augroup MyCompiler autocmd! " run save&compile autocmd Filetype c compiler gcc autocmd Filetype cpp compiler gcc autocmd Filetype c setl makeprg=gcc\ -Wall\ %\ -o\ %:r.o autocmd Filetype cpp setl makeprg=g++\ -Wall\ %\ -o\ %:r.o autocmd Filetype c nmap m :w:make autocmd Filetype cpp nmap m :w:make " run splint autocmd Filetype c nmap M :!splint % autocmd Filetype cpp nmap M :!splint % augroup END " }}} " vimshell supports {{{ let g:vimshell_escape_colors = [ \'#3c3c3c', '#ff6666', '#66ff66', '#ffd30a', '#1e95fd', '#ff13ff', '#1bc8c8', '#C0C0C0', \'#686868', '#ff6666', '#66ff66', '#ffd30a', '#6699ff', '#f820ff', '#4ae2e2', '#ffffff' \] let g:vimshell_split_command = 'split' let g:vimshell_cd_command = 'TabpageCD' let g:VimShell_UsePopen2 = 0 " }}} " mspec/rubyspec supports {{{ function! DoMspec() new read! /usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t ~/git/ruby-trunk/ruby19/bin/ruby # call append(line('$'), '--------------------------------------------------------------') normal G read! /usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t ~/rubies/bin/ruby191 # call append(line('$'), '--------------------------------------------------------------') normal G read! /usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t ~/rubies/bin/ruby187 # call append(line('$'), '--------------------------------------------------------------') normal G read! /usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t /opt/local/bin/ruby # call append(line('$'), '--------------------------------------------------------------') normal G read! /usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t /usr/bin/ruby # endfunction " }}} " capslock.vim {{{ imap CapsLockToggle "set statusline=...%{exists('*CapsLockStatusline')?CapsLockStatusline():''} " }}} " Haskell Tag {{{ " see also: ~/bin/update-cabal-tags set tag+=~/.cabal/tags " }}} " thinca vim development environment {{{ " http://d.hatena.ne.jp/thinca/20100216/1266294717 " Load settings for each location. augroup vimrc-local autocmd! autocmd BufNewFile,BufReadPost * call s:vimrc_local(expand(':p:h')) augroup END function! s:vimrc_local(loc) let files = findfile('vimrc_local.vim', escape(a:loc, ' ') . ';', -1) for i in reverse(filter(files, 'filereadable(v:val)')) source `=i` endfor endfunction if exists('g:loaded_vimrc') && g:loaded_vimrc == 0 call s:vimrc_local(getcwd()) endif let g:loaded_vimrc = 1 " }}} " ] for completion (dirty hack) {{{ " see also: hack #135 "augroup CloseOrCompl " autocmd! " autocmd BufWinEnter,BufNewFile ~/blog/dre/*.txt inoremap ] CloseOrCompl() "augroup END "inoremap ] searchpair('\[', '', '\]', 'nbW', 'synIDattr(synID(line("."), col("."), 1), "name") =~? "String"') ? ']' : "\" " inoremap ] searchpair('\[', '', '\]', 'nbW', 'synIDattr(synID(line("."), col("."), 1), "name") =~? "String"') ? ']' : pumvisible() ? "\" : "\\\" " }}} " Open junk file. by Shougo "{{{ command! -nargs=0 JunkFile call s:open_junk_file() function! s:open_junk_file() let l:junk_dir = $HOME . '/.Trash/vim_junk'. strftime('/%Y/%m') if !isdirectory(l:junk_dir) call mkdir(l:junk_dir, 'p') endif let l:filename = input('Junk Code: ', l:junk_dir.strftime('/%Y-%m-%d-%H%M%S.')) if l:filename != '' execute 'edit ' . l:filename endif endfunction " }}} " vim filetype specific conf in general {{{ " also for No Command-line window by Shougo http://vim-users.jp/2010/07/hack161/ nnoremap (command-line-enter) q: xnoremap (command-line-enter) q: nnoremap (command-line-norange) q: nmap : (command-line-enter) xmap : (command-line-enter) " I added "nnoremap q: q: autocmd CmdwinEnter * call s:init_cmdwin() " MacVim is shit autocmd CmdwinEnter * nnoremap CmdwinRun() autocmd CmdwinEnter * inoremap CmdwinRun() function! CmdwinRun() let a = getline(line('.')) return "\\\:" . a . "\" endfunction function! s:cmdwin_backslash() return matchstr(getline('.'), '\w\+') =~# '^s\(ubstitute\)\?$' ? '\' : smartchr#one_of('~/', '\') endfunction inoremap (vimrc_cmdwin_close) :quit function! s:init_cmdwin() inoremap pumvisible() ? "\\" : "\" inoremap pumvisible() ? "\\" : "\" "inoremap pumvisible() ? "\\" : "\" "I added imap col('.') == 1 ? "\(vimrc_cmdwin_close)" : "\(vimrc_bs)" inoremap : col('.') == 1 ? "VimProcBang " : col('.') == 2 && getline('.')[0] == 'r' ? "VimProcRead " : ":" "inoremap \ smartchr#one_of('~/', '\') inoremap \ pumvisible() ? neocomplcache#close_popup() : cmdwin_backslash() " Completion. "inoremap pumvisible() ? "\" : "\" startinsert! endfunction function! s:vimrc_vim() " to disable sw= -> swapfile= auto completion inoremap w= w= endfunction augroup vimrc-vim autocmd! autocmd FileType vim call vimrc_vim() augroup END " }}} " load PATH from ~/.zshrc {{{ "function! LoadPathFromZshrc() " for cmd in split(system("~/bin/loadpathfromzshrc"), "\n") " execute cmd " endfor "endfunction "call LoadPathFromZshrc() " }}} " guifont changer {{{ " function! GuifontChanger() " if !exists('s:guifont_changer_index') " let s:guifont_changer_index = 0 " else " let s:guifont_changer_index += 1 " endif " if !exists('s:guifont_changer_list') " let s:guifont_changer_list = [ " \ 'Andale Mono:h14', " \ 'Menlo:h13', " \ 'Inconsolata:h14', " \ 'Handwriting - Dakota:h32', " \ 'Handwriting - Dakota:h64', " \ ] " endif " let font = s:guifont_changer_list[ " \ s:guifont_changer_index % len(s:guifont_changer_list)] " let cmd = "set guifont=" . substitute(font, " ", "\\\\ ", 'g') " execute cmd " call WindowsizeMaximize13() " echo cmd " for some reason it doesn't show up... " endfunction " "command! -nargs=0 GuifontChanger call GuifontChanger() " nnoremap ff :call GuifontChanger() " }}} " few {{{ function s:vimrc_few() let path = expand('~/git/few/bin/few') if filereadable(path) execute 'QuickRun ruby' path else echoerr printf("'%s' not found", path) endif endfunction command! -nargs=0 Few call vimrc_few() "AlterCommandWrapper few Few " }}} " Swap window without moving cursor {{{ " https://gist.github.com/654701 "nmap j (swap-window-down-no-cursor-move) "nmap k (swap-window-up-no-cursor-move) nmap h (swap-window-left-no-cursor-move) nmap l (swap-window-right-no-cursor-move) nnoremap (swap-window-down-no-cursor-move) :call swap_with_wincmd(v:count1, 'j') nnoremap (swap-window-up-no-cursor-move) :call swap_with_wincmd(v:count1, 'k') nnoremap (swap-window-left-no-cursor-move) :call swap_with_wincmd(v:count1, 'h') nnoremap (swap-window-right-no-cursor-move) :call swap_with_wincmd(v:count1, 'l') function! s:swap_with_wincmd(n, dir) let curwin = winnr() execute a:n 'wincmd' a:dir let targetwin = winnr() wincmd p call s:swap_window(curwin, targetwin) endfunction function! s:swap_window(curwin, targetwin) let curbuf = winbufnr(a:curwin) let targetbuf = winbufnr(a:targetwin) if curbuf == targetbuf " TODO: Swap also same buffer! else execute 'hide' targetbuf . 'buffer' execute a:targetwin 'wincmd w' execute curbuf 'buffer' wincmd p " Behave like x ? endif endfunction " }}} " copy the current file name {{{ command! -nargs=0 CopyTheCurrentFileName let @+ = expand('%') "AlterCommandWrapper copythecurrentfilename CopyTheCurrentFileName " }}} " unite-neco {{{ let s:unite_source = {'name': 'neco'} function! s:unite_source.gather_candidates(args, context) let necos = [ \ "~(-'_'-) goes right", \ "~(-'_'-) goes right and left", \ "~(-'_'-) goes right quickly", \ "~(-'_'-) skips right", \ "~(-'_'-) -8(*'_'*) go right and left", \ "(=' .' ) ~w", \ ] return map(necos, '{ \ "word": v:val, \ "source": "neco", \ "kind": "command", \ "action__command": "Neco " . v:key, \ }') endfunction "function! unite#sources#locate#define() " return executable('locate') ? s:unite_source : [] "endfunction call unite#define_source(s:unite_source) " }}} " unite-evalruby {{{ "let s:unite_source = { " \ 'name': 'evalruby', " \ 'is_volatile': 1, " \ 'required_pattern_length': 1, " \ 'max_candidates': 30, " \ } " "function! s:unite_source.gather_candidates(args, context) " if a:context.input[-1:] == '.' " let methods = split( " \ unite#util#system(printf('ruby -e "puts %s.methods"', a:context.input[:-2])), " \ "\n") " call map(methods, printf("'%s' . v:val", a:context.input)) " else " let methods = [a:context.input] " endif " return map(methods, '{ " \ "word": v:val, " \ "source": "evalruby", " \ "kind": "command", " \ "action__command": printf("!ruby -e \"p %s\"", v:val), " \ }') "endfunction " "call unite#define_source(s:unite_source) " }}} " for fast cycle {{{ function! ForFastCycle() Unite evalruby endfunction command -nargs=0 ForFastCycle call ForFastCycle() if 0 nnoremap :ForFastCycle nnoremap :qa! endif " }}} " Restart.vim {{{ let g:restart_sessionoptions = 'blank,curdir,folds,help,localoptions,tabpages' " }}} let g:shadow_debug = 1 " PATH {{{ "command! -nargs=1 AddPath let $PATH=":".$PATH command! -nargs=1 AddPath let $PATH = expand() . ':' .$PATH "command! -nargs=1 AddPath0e let $PATH = $PATH . ':' . expand() " if filereadable(expand('~/.zshrc')) " "execute 'let $PATH="' . system('zsh -c "source ~/.zshrc; echo -n \$PATH"') . '"' " let $PATH='/Users/ujihisa/git/ruby193/local/bin:/Users/ujihisa/git/ruby192/local/bin:/Users/ujihisa/git/ruby187/local/bin:/Users/ujihisa/git/jruby/bin:/usr/local/bin:/Users/ujihisa/git/epitaph/bin:/Users/ujihisa/git/cbc/usr/bin:/Users/ujihisa/src/llvm/usr/bin:/Users/ujihisa/src/javacc-5.0/bin:/Users/ujihisa/.cabal/bin:/Users/ujihisa/.gem/jruby/1.8/bin:/Users/ujihisa/.gem/ruby/1.9/bin:/Users/ujihisa/.gem/ruby/1.8/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/ujihisa/git/jark:/Users/ujihisa/src/llvm-git-build/local/bin:/Users/ujihisa/Library/Haskell/bin:/Users/ujihisa/git/mdv:/Users/ujihisa/git/ruby193/local/bin:/Users/ujihisa/git/ruby192/local/bin:/Users/ujihisa/git/ruby187/local/bin:/Users/ujihisa/git/jruby/bin:/Users/ujihisa/git/epitaph/bin:/Users/ujihisa/git/cbc/usr/bin:/Users/ujihisa/src/llvm/usr/bin:/Users/ujihisa/src/javacc-5.0/bin:/Users/ujihisa/.cabal/bin:/Users/ujihisa/.gem/jruby/1.8/bin:/Users/ujihisa/.gem/ruby/1.9/bin:/Users/ujihisa/.gem/ruby/1.8/bin:/opt/local/bin:/opt/local/sbin:/Applications/MacVim.app/Contents/MacOS:/Users/ujihisa/bin/:/Users/ujihisa/appengine-java-sdk-1.2.1/bin:/Users/ujihisa/android-sdk-mac_x86-1.5_r2/tools/:/Users/ujihisa/git/termtter/bin:/Users/ujihisa/.gem/ruby/1.9.1/bin:/Users/ujihisa/bin/scala-2.6.0-final/:/Users/ujihisa/git/rubinius/local/bin:/Users/ujihisa/node_modules/coffee-script/bin/:/Users/ujihisa/git/git-hg/bin:/usr/local/Cellar/python/2.7.1/bin/:/Users/ujihisa/bin/:/Users/ujihisa/appengine-java-sdk-1.2.1/bin:/Users/ujihisa/android-sdk-mac_x86-1.5_r2/tools/:/Users/ujihisa/git/termtter/bin:/Users/ujihisa/.gem/ruby/1.9.1/bin:/Users/ujihisa/bin/scala-2.6.0-final/::/Users/ujihisa/git/rubinius/local/bin:/Users/ujihisa/node_modules/coffee-script/bin/:/Users/ujihisa/git/git-hg/bin:/usr/local/Cellar/python/2.7.1/bin/' " else AddPath /usr/bin AddPath /usr/local/bin AddPath /sbin AddPath /usr/sbin " endif AddPath /Users/ujihisa/git/mdv AddPath /Users/ujihisa/Library/Haskell/bin if isdirectory('/Users/ujihisa/pear/bin/pear') AddPath /Users/ujihisa/pear/bin endif if isdirectory('/Users/ujihisa/src/llvm-git-build/local/bin') AddPath /Users/ujihisa/src/llvm-git-build/local/bin endif "if isdirectory('/Users/ujihisa/git/jark') " AddPath /Users/ujihisa/git/jark "endif if isdirectory(expand('~/git/ruby200/local/bin')) AddPath ~/git/ruby200/local/bin endif if isdirectory(expand('~/bin')) AddPath ~/bin endif if !g:V.is_mac() AddPath /home/ujihisa/git/termtter/bin AddPath /home/ujihisa/git/ruby/local/bin AddPath /home/ujihisa/src/llvm-git-build/local/bin "AddPath /home/ujihisa/src/haskell-platform-2011.2.0.1/local/bin "AddPath /home/ujihisa/src/ghc-7.0.3/local/bin AddPath /home/ujihisa/.cabal/bin "AddPath /home/ujihisa/git/ghc/local/bin AddPath /home/ujihisa/git/Gyazo-for-Linux/ endif AddPath ~/git/leiningen/bin " }}} " macvim proportional {{{ function! Proportional() set guifontwide= set macproportionalfont endfunction command! -nargs=0 Proportional call Proportional() " }}} " last two digit move {{{ " inspired by tavis' emacs voice line number movement feature "command! -count=1 -nargs=0 LastTwoDigitMove call LastTwoDigitMove() "function! LastTwoDigitMove(bound) " " for example when you are at line num 123 and typed 3gl " " getpos('.')[1] is 123 " " a:bound is 125 " " the goal is 103 " let current = getpos('.')[1] " let to = current / 100 * 100 + a:bound - current + 1 " execute to "endfunction "nnoremap gl :LastTwoDigitMove " version 2.0 " thanks MarcWeber " not it's not only two-digit command! -count=1 -nargs=0 GoToTheLine silent execute getpos('.')[1][:-len(v:count)-1] . v:count nnoremap gl :GoToTheLine " }}} " Haskell Type {{{ function! s:haskell_type(fname, expression) if filereadable(a:fname) let fname = a:fname else let fname = tempname() call writefile(getline(0, '$'), fname, 'b') "return {'left': printf("File not found: %s", a:fname)} endif let r = ref#system(['ghc-mod', 'type', fname, 'main', a:expression]) if r.result != 0 return {'left': r.stderr} endif return {'right': r.stdout} endfunction command! -nargs=1 HaskellType echo s:haskell_type(expand('%'), ) " }}} " echodoc {{{ let g:echodoc_enable_at_startup = 0 let g:echodoc_hoogle_cache = {} let s:doc_dict = { \ 'name': 'haskell', \ 'rank': 10, \ 'filetypes' : {'haskell': 1}, \ } function! s:doc_dict.search(cur_text) let tmp = matchlist(a:cur_text, "\\([a-z][a-z0-9.'_]*\\)\\s*$") let tmp = filter(tmp, 'v:val != ""') if len(tmp) == 2 let query = tmp[1] else return [] endif let result = s:haskell_type(expand('%'), query) if has_key(result, 'left') return [] endif return [{'text': query, 'highlight': 'Identifier'}, {'text': ' :: ' . substitute(result.right, "\n", "", "")}] if mode() !=# 'i' echo a:cur_text let query .= neocomplcache#get_next_keyword() endif if len(query) < 3 return [] endif let the_type = s:hoogle(query) if split(the_type, ' ')[1] == query return [{'text': the_type}] else return [] endif endfunction function! s:hoogle(cur_text) if !has_key(g:echodoc_hoogle_cache, a:cur_text) let g:echodoc_hoogle_cache[a:cur_text] = split(neocomplcache#system('hoogle ' . a:cur_text), "\n")[0] endif return g:echodoc_hoogle_cache[a:cur_text] endfunction call echodoc#register('haskell', s:doc_dict) " }}} " rsense {{{ "if !exists('g:neocomplcache_omni_patterns') " let g:neocomplcache_omni_patterns = {} "endif "let g:rsenseUseOmniFunc = 1 "if filereadable(expand('~/git/rsense/bin/rsense')) " let g:rsenseHome = expand('~/git/rsense') " " let g:neocomplcache_omni_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::' "endif " }}} " testing neco-ghc {{{ "nnoremap :e ~/.vimbundles/neco-ghc/fixtures/a.hs " }}} " vim-ref {{{ let g:ref_phpmanual_path = expand("~/src/php-chunked-xhtml/") let g:ref_phpmanual_cmd = 'elinks -dump -dump-charset utf-8 -no-numbering -no-references %s' " charset is important "let g:ref_man_cmd = "man -P cat" let g:ref_erlang_manpath = '/usr/local/share/man' let $MANPAGER='cat' call ref#rmcache() " }}} " special git log viewer {{{ function! s:git_log_viewer() vnew "VimProcRead git log -u 'HEAD@{1}..HEAD' --reverse VimProcRead git log -u 'ORIG_HEAD..HEAD' set filetype=git-log.git-diff setl foldmethod=expr setl foldexpr=getline(v:lnum)!~'^commit' endfunction command! GitLogViewer call s:git_log_viewer() " }}} " disable macvim vimrc_examples {{{ let g:no_vimrc_example = 1 " }}} " Git Diff -> The file {{{ function! SGoDiff() let [maybe, fname] = s:latest_fname() if maybe ==# 'nothing' echoerr 'failed to find the filename' return endif let [maybe, linenum] = s:latest_linenum() if maybe ==# 'nothing' echoerr 'failed to find the linenum' return endif execute "vnew" fname execute linenum execute "normal! z\" endfunction augroup vimrc-sgodiff autocmd! autocmd FileType git-diff nnoremap :call SGoDiff() augroup END function! s:latest_fname() for i in reverse(range(1, line('.'))) if getline(i) =~ '^+++ ' return ['just', substitute(getline(i)[4:], '\t.*$', '', 'b')] endif endfor return ['nothing', ''] endfunction function! s:latest_linenum() for i in reverse(range(1, line('.'))) if getline(i) =~ '^@@ ' let a = matchlist(getline(i), '^@@ -.\{-},.\{-} +\(.\{-}\),') if exists('a[1]') return ['just', a[1]] endif endif endfor return ['nothing', ''] endfunction " }}} " yet another star {{{ "function! s:star_with_smartcase() " set hlsearch " echo expand('') " execute printf('/\<%s\>', expand('')) "endfunction "nnoremap * :call star_with_smartcase() " }}} " vital toplevel func for hand-testing {{{ command! Letv let V = vital#__latest__#new() | echo 'V: ' . string(keys(V)) " }}} " setl list is very often {{{ nnoremap ` :!setl list! " }}} " too much t). I dont' use ). ) should be t). {{{ onoremap ) t) onoremap ( t( vnoremap ) t) vnoremap ( t( " }}} " hack 104 http://vim-users.jp/2009/11/hack104/ {{{ vnoremap * "vy/\V=substitute(escape(@v,'\/'),"\n",'\\n','g') " }}} " hootsuite {{{ "command! -nargs=0 HootSuiteVim new /Users/ujihisa/.vimbundles/hootsuite/plugin/hootsuite.vim "command! -nargs=0 HootSuiteSpec new /Users/ujihisa/git/hstools/spec/committer.rb " }}} " MacVim is unko {{{ let rtp = split(&rtp, ',') unlet rtp[index(rtp, '/Applications/MacVim.app/Contents/Resources/vim/plugins/kaoriya')] let &rtp = join(rtp, ',') " }}} " golden ratio {{{ command! -nargs=0 GoldenRatio execute 'vertical resize' &columns * 5 / 8 nnoremap ] :GoldenRatio " }}} " hootsuite_lang {{{ augroup hootsuite-lang autocmd! autocmd BufWinEnter,BufNewFile ~/git/hootsuite_lang/* nnoremap m :VimProcBang rake augroup END " }}} " unite-launch {{{ let g:unite_launch_apps = [ \ 'rake', \ 'make', \ 'git pull', \ 'git push'] " }}} " unite-transparency {{{ let s:unite_source = {'name': 'transparency', 'action_table': {'*': {}} } " avoid triple closes function! s:unite_source.gather_candidates(args, context) return map(range(0, 100, 4), '{ \ "word": v:val, \ "source": "transparency", \ "kind": "command", \ "action__command": "set transparency=" . v:val, \ }') endfunction let s:unite_source.action_table['*'].preview = { \ 'description': 'preview this transparency', 'is_quit': 0 } function! s:unite_source.action_table['*'].preview.func(candidate) execute a:candidate.action__command endfunction call unite#define_source(s:unite_source) " }}} " quickrun + haskell = infinite loop {{{ command! -nargs=0 KillHaskell execute '!killall runghc' | execute '!killall ghc' " }}} " syntastic {{{ let g:synastic_enable_signs = 1 " }}} " vimerl {{{ let g:erlangManPath = '/usr/local/share/man' "let g:neocomplcache_omni_patterns.erlang = '[a-zA-Z]\|:' " }}} " remote {{{ function! s:_vim(x) if filereadable('/Applications/MacVim.app/Contents/MacOS/Vim') return g:V.system('/Applications/MacVim.app/Contents/MacOS/Vim ' . a:x) endif endfunction function! s:new(...) let name = a:0 == 1 ? a:1 : s:_remote_name() return {'name': name, 'send': function('s:_send'), 'focus': function('s:_focus')} endfunction function! s:_send(key) dict return s:_vim('--servername ' . self.name . ' --remote-send ' . string(a:key)) endfunction function! s:_focus() dict VimProcBang open ~/.vim/macvimfocus.app endfunction function! s:_remote_name() for server in split(s:_vim('--serverlist'), "\n") if server !=# v:servername return server endif endfor call g:V.print_error('No remote server') endfunction function! VimrcRemoteInit() let remote = s:new() " echo remote.send(':h client-server') command! -nargs=* R call remote.send(':' . . '') | call remote.focus() nnoremap [ :VimProcBang osascript ~/.vim/macvimfocus.scpt endfunction " }}} " vimclojure {{{ if globpath(&rtp, 'autoload/vimclojure.vim') != '' let vimclojure#HighlightBuiltins = 1 let vimclojure#ParenRainbow = 1 let g:vimclojure#FuzzyIndent = 1 endif " }}} " golden-ratio {{{ let g:golden_ratio_autocommand = 0 "nmap gr (golden_ratio_resize) "imap gr (golden_ratio_resize) " }}} " conceallevel changer {{{ nnoremap ` :setl conceallevel=0 " }}} " vimfiler {{{ let g:vimfiler_as_default_explorer = 1 autocmd FileType vimfiler call s:vimfiler_local() function! s:vimfiler_local() nunmap L nunmap H endfunction " }}} " :TOhtmlAndBrowse {{{ " http://d.hatena.ne.jp/tyru/20110710/tenuki " changing command name from TOhtmlAndBrowse to TOhtmAndBrowse to avoid Vim bug " also.. it doesn't delete the file because this computer is slow.. command! \ TOhtmAndBrowse \ call s:TOhtmlAndBrowse() function! s:TOhtmlAndBrowse() TOhtml " begin callback...? %s/font-family: monospace/font-family: Myriad Pro/ %s/.lnr { /\0font-family: monospace; / %s/^[ 0-9]\+<\/span> */\0<\/font>/ %s/\s*[0-9]\+\s*<\/span>\zs \+\ze/\='' . repeat("_", len(submatch(0))) . "<\/font>"/g " end saveas `=tempname()` let save = get(g:, 'openbrowser_open_filepath_in_vim') let g:openbrowser_open_filepath_in_vim = 0 try OpenBrowser file://% finally let g:openbrowser_open_filepath_in_vim = save endtry "sleep 1 "call delete(expand('%')) endfunction " }}} " keynote integration {{{ command! -nargs=0 TOkeynote call s:keynote() function! s:keynote() let before = g:colors_name Tcolorscheme martin_krischik ToggleRaibowParenthesis setl conceallevel=0 TOhtmAndBrowse execute "Tcolorscheme" before endfunction " }}} " unite-build {{{ command! -nargs=* UniteBuild Unite build -no-start-insert -default-action=split " }}} " ENV {{{ if !$LANG let $LANG='en_US.UTF-8' endif " http://lingr.com/room/vim/archives/2011/09/19#message-4881743 " }}} " for vital spec {{{ " /Users/ujihisa/git/MacVim/src/MacVim/build/Release/MacVim.app/Contents/MacOS/Vim -g -u NONE -i NONE -N --cmd 'filetype indent on' -S spec/data/string.vim -c 'Fin /tmp/prelude.result' " }}} " vimshell platform-dependent aliases {{{ let s:is_gentoo = system('uname -a') =~ 'gentoo' " for some reason vimproc#system doesn't work function! s:vimshell_settings() if s:is_gentoo call vimshell#set_alias('time', 'exe time -p') else call vimshell#set_alias('eix', 'exe brew search') endif endfunction augroup vimshell-settings autocmd! autocmd FileType vimshell call s:vimshell_settings() augroup END " }}} " platform-dependencies {{{ if s:is_gentoo inoremap ö "+p vnoremap ã "+y set lsp=2 endif " }}} " jruby {{{ function! VimrcJruby() if &filetype != 'ruby' echoerr 'not ruby' return endif call vimproc#system_bg('jruby --ng-server') let b:quickrun_config = {'command': 'jruby', 'cmdopt': '--ng --1.9'} endfunction " }}} " syntastic {{{ let g:syntastic_cpp_compiler_options = ' -std=c++0x' let g:syntastic_mode_map = { \ 'mode': 'active', \ } "\ 'passive_filetypes': ['scala'] } " }}} " pseudo rm command {{{ command! -nargs=* Rm echo " }}} " no python preview {{{ set completeopt-=preview " }}} " minecraft {{{ function! VimrcSwank() VimShellInteractive java -jar /home/ujihisa/git/swank-client/swank-client-1.1.0-standalone.jar -p 4005 set filetype=clojure normal! A(ns cloft.core) endfunction function! VimrcSendSwank() "let @" = substitute(vimclojure#ExtractSexpr(1)[1], '\(;.*\)\?\n *', ' ', 'g') execute 'VimShellSendString' vimclojure#ExtractSexpr(1)[1] endfunction " }}} " vim-scala {{{ let g:scala_use_default_keymappings = 0 " }}} " haskell snippets {{{ " import qualified Control.Monad.State as S " import Control.Applicative ((<$>), (<*>)) " import Data.Maybe (fromMaybe) " import qualified Data.Map as M " import Control.Monad (unless) " " {-# LANGUAGE QuasiQuotes #-} " import Data.String.Interpolation (str) " }}} " unite-file_rec with file-extension {{{ function! s:file_extension() let table = { \ 'ruby': 'rb', \ 'haskell': 'hs', \ 'clojure': 'clj' } return '.' . get(table, &filetype, &filetype) endfunction command! -nargs=0 UniteFilerecWithFiletype execute "Unite file_rec -input=" . file_extension() " }}} " lingr-vim {{{ augroup vimrc-lingr autocmd! autocmd FileType lingr-messages nmap i (lingr-messages-show-say-buffer) autocmd FileType lingr-say inoremap :wq augroup END " }}} " javascript {{{ function! s:vimrc_javascript() setl ts=4 setl sw=4 setl noexpandtab setl nolist inoremap \ smartchr#one_of('function(', '\') inoremap ` console.log(); "runtime! ftplugin/coffee.vim endfunction augroup vimrc-javascript autocmd! autocmd FileType javascript call vimrc_javascript() augroup END " }}} " coffeescript {{{ function! s:vimrc_coffeescript() setl sw=2 setl sts=2 setl expandtab setl list return function! JavaScriptUnderScoreBecomesCamelCase() if matchstr(getline('.'), '.', col('.')-2) =~ '\w' return "\(stickykey-shift)" else return '_' endif endfunction! imap _ JavaScriptUnderScoreBecomesCamelCase() endfunction augroup vimrc-coffeescript autocmd! autocmd FileType coffee call vimrc_coffeescript() augroup END " }}} " yacc {{{ " mostly for ruby/parse.y augroup vimrc-yacc autocmd! autocmd FileType yacc setl nolist autocmd FileType yacc setl noexpandtab autocmd FileType yacc setl ts=8 autocmd FileType yacc setl sw=4 augroup END " }}} " java {{{ function! s:vimrc_java() compiler javac nnoremap m :make % inoremap ` System.out.println(); endfunction augroup vimrc-java autocmd! autocmd FileType java call vimrc_java() augroup END " }}} " あ、そういやたぶん今年も11月くらいに来日します。ujihisa.vimとかそういう感じの何かをやりたいなと思ってます。発表したい方はlingrやtwitterなどでぜひお伝えください! " __END__ "{{{1 " vim: expandtab softtabstop=2 shiftwidth=2 " vim: foldmethod=marker