" vim:set fen fdm=marker: " " See also: ~/.vimrc " " let $VIMRC_DEBUG = 1 " let $VIMRC_DISABLE_MYAUTOCMD = 1 " let $VIMRC_DISABLE_VIMENTER = 1 " Basic {{{ scriptencoding utf-8 syntax enable filetype plugin indent on language messages C language time C if filereadable(expand('~/.vimrc.local')) execute 'source' expand('~/.vimrc.local') endif let s:is_win = has('win16') || has('win32') || has('win64') " }}} " Utilities {{{ " Function {{{ function! s:SID() "{{{ return matchstr(expand(''), '\zs\d\+\ze_SID$') endfunction "}}} function! s:SNR(map) "{{{ return printf("%d_%s", s:SID(), a:map) endfunction "}}} " e.g.) s:has_plugin('eskk') ? 'yes' : 'no' function! s:has_plugin(name) let nosuffix = a:name =~? '\.vim$' ? a:name[:-5] : a:name let suffix = a:name =~? '\.vim$' ? a:name : a:name . '.vim' return &rtp =~# '\c\<' . nosuffix . '\>' \ || globpath(&rtp, suffix, 1) != '' \ || globpath(&rtp, nosuffix, 1) != '' \ || globpath(&rtp, 'autoload/' . suffix, 1) != '' \ || globpath(&rtp, 'autoload/' . tolower(suffix), 1) != '' endfunction function! s:echomsg(hl, msg) "{{{ execute 'echohl' a:hl try echomsg a:msg finally echohl None endtry endfunction "}}} function! s:warn(msg) "{{{ call s:echomsg('WarningMsg', a:msg) endfunction "}}} " }}} " Commands {{{ augroup vimrc autocmd! augroup END command! \ -bar -nargs=1 \ Nop \ command! -bar -bang -nargs=* : " :autocmd is listed in |:bar| command! \ -bang -nargs=* \ MyAutocmd \ autocmd vimrc if exists('$VIMRC_DISABLE_MYAUTOCMD') Nop MyAutoCmd endif command! \ -nargs=+ \ Lazy \ call s:cmd_lazy() if exists('$VIMRC_DISABLE_VIMENTER') Nop MyAutoCmd endif function! s:cmd_lazy(q_args) "{{{ if a:q_args == '' return endif if has('vim_starting') execute 'MyAutocmd VimEnter *' \ join([ \ 'try', \ 'execute '.string(a:q_args), \ 'catch', \ 'call StartDebugMode()', \ 'endtry', \ ], " | ") else execute a:q_args endif endfunction "}}} " }}} " }}} " Initializing {{{ if !exists('$VIMRC_DEBUG') call rtputil#bundle() else " TODO: Reduce dependency plugins. " Basic plugins call rtputil#append('~/.vim/bundle/tyru') call rtputil#append('~/.vim/bundle/emap.vim') call rtputil#append('~/.vim/bundle/vim-altercmd') call rtputil#append('~/.vim/bundle/vital.vim') " Useful plugins for debug call rtputil#append('~/.vim/bundle/dutil.vim') call rtputil#append('~/.vim/bundle/vim-prettyprint') call rtputil#append('~/.vim/bundle/restart.vim') " Load plugins to debug call rtputil#append('~/.vim/bundle/eskk.vim') call rtputil#append('~/.vim/bundle/neocomplcache') endif let s:Vital = vital#of('vital') call s:Vital.load('Data.List') call s:Vital.load('System.Filepath') command! -bar -bang HelpTagsAll call rtputil#helptags(0) HelpTagsAll call emap#load('noprefix') " Define :EmMap as :Map " call emap#set_sid_from_vimrc() call emap#set_sid(s:SID()) " call emap#set_sid_from_sfile(expand('')) call altercmd#load() command! \ -bar -nargs=+ \ MapAlterCommand \ CAlterCommand | AlterCommand call dutil#load() " }}} " Options {{{ " Reset all options except 'runtimepath'. let s:tmp = &runtimepath set all& let &runtimepath = s:tmp unlet s:tmp if exists('&msghistlen') set msghistlen=9999 endif " indent set autoindent set smartindent set expandtab set smarttab set tabstop=4 " search set hlsearch set incsearch set smartcase " listchars set list set listchars=tab:>_,extends:>,precedes:<,eol:/ " scroll set scroll=5 " set scrolloff=15 " set scrolloff=9999 set scrolloff=0 " let g:scrolloff = 15 " see below " Disable it temporarily... let g:scrolloff = 0 " Hack for not to adjust ('scrolloff') when single-clicking. " Implement 'scrolloff' by auto-command to control the fire. " cf. http://vim-users.jp/2011/04/hack213/ MyAutocmd CursorMoved * call s:reinventing_scrolloff() let s:last_lnum = -1 function! s:reinventing_scrolloff() if g:scrolloff ==# 0 || s:last_lnum > 0 && line('.') ==# s:last_lnum return endif let s:last_lnum = line('.') let winline = winline() let winheight = winheight(0) let middle = winheight / 2 let upside = (winheight / winline) >= 2 " If upside is true, add winlines to above the cursor. " If upside is false, add winlines to under the cursor. if upside let up_num = g:scrolloff - winline + 1 let up_num = winline + up_num > middle ? middle - winline : up_num if up_num > 0 execute 'normal!' up_num."\" endif else let down_num = g:scrolloff - (winheight - winline) let down_num = winline - down_num < middle ? winline - middle : down_num if down_num > 0 execute 'normal!' down_num."\" endif endif endfunction " shift set shiftround set shiftwidth=4 if v:version > 703 || v:version is 703 && has('patch629') " Follow 'tabstop' value. set shiftwidth=0 endif " completion set complete=.,w,b,u,t,i,d,k,kspell set wildmenu set pumheight=20 " tags if has('path_extra') set tags+=.; set tags+=tags; endif set showfulltag set notagbsearch " cscope if 0 set cscopetag set cscopeverbose endif " virtualedit if has('virtualedit') set virtualedit=all endif " swap set noswapfile set updatecount=0 " backup set backup let &backupdir = $MYVIMDIR . '/backup' if !isdirectory(&backupdir) call mkdir(&backupdir, 'p') endif function! SandboxCallOptionFn(option_name) "{{{ try return s:{a:option_name}() catch call setbufvar('%', '&' . a:option_name, '') return '' endtry endfunction "}}} " title set title function! s:titlestring() "{{{ if exists('t:cwd') return t:cwd . ' (tab)' elseif haslocaldir() return getcwd() . ' (local)' else return getcwd() endif endfunction "}}} let &titlestring = '%{SandboxCallOptionFn("titlestring")}' " tab set showtabline=2 function! MyTabLabel(tabnr) "{{{ if exists('*gettabvar') let title = gettabvar(a:tabnr, 'title') if title != '' return title endif endif let buflist = tabpagebuflist(a:tabnr) let bufname = bufname(buflist[tabpagewinnr(a:tabnr) - 1]) let modified = 0 for bufnr in buflist if getbufvar(bufnr, '&modified') let modified = 1 break endif endfor if bufname == '' let label = '[No Name]' elseif tabpagenr() != a:tabnr let label = fnamemodify(bufname, ':t') else let label = pathshorten(bufname) endif return label . (modified ? '[+]' : '') endfunction "}}} function! s:tabline() "{{{ let s = '' for i in range(tabpagenr('$')) " select the highlighting if i + 1 == tabpagenr() let s .= '%#TabLineSel#' else let s .= '%#TabLine#' endif " set the tab page number (for mouse clicks) let s .= '%' . (i + 1) . 'T' " the label is made by MyTabLabel() let s .= ' %{MyTabLabel(' . (i + 1) . ')} ' endfor " after the last tab fill with TabLineFill and reset tab page nr let s .= '%#TabLineFill#%T' " right-align the label to close the current tab page if tabpagenr('$') > 1 let s .= '%=%#TabLine#%999XX' endif return s endfunction "}}} set tabline=%!SandboxCallOptionFn('tabline') function! s:guitablabel() "{{{ let s = '%{tabpagenr()}. [%t]' if exists('t:cwd') let s .= ' @ [tab: %{t:cwd}]' elseif haslocaldir() let s .= ' @ [local cwd: %{getcwd()}]' else let s .= ' @ [cwd: %{getcwd()}]' endif return s endfunction "}}} set guitablabel=%!SandboxCallOptionFn('guitablabel') " statusline set laststatus=2 function! s:statusline() "{{{ let s = '%f%([%M%R%H%W]%)%(, %{&ft}%), %{&fenc}/%{&ff}' let s .= '%(' if exists('g:loaded_eskk') " eskk.vim " postpone the load of autoload/eskk.vim if exists('g:loaded_autoload_eskk') let s .= ' %{eskk#statusline("IM:%s", "IM:off")}' endif elseif exists('g:skk_loaded') " skk.vim let s .= ' %{SkkGetModeStr()}' endif if !get(g:, 'cfi_disable') \ && s:has_plugin('current-func-info') let s .= '%( | %{cfi#format("%s()", "")}%)' endif " XXX: calling GetCCharAndHex() destroys also unnamed register. it may be the problem of Vim. " let s .= '%( | [%{GetCCharAndHex()}]%)' let s .= '%( | %{GetDocumentPosition()}%)' let s .= '%)' return s endfunction "}}} set statusline=%!SandboxCallOptionFn('statusline') function! GetDocumentPosition() return float2nr(str2float(line('.')) / str2float(line('$')) * 100) . "%" endfunction function! GetCCharAndHex() if mode() !=# 'n' return '' endif if foldclosed(line('.')) isnot -1 return '' endif let cchar = s:get_cchar() return cchar ==# '' ? '' : cchar . ":" . "0x".char2nr(cchar) endfunction function! s:get_cchar() let reg = getreg('z', 1) let regtype = getregtype('z') try if col('.') ==# col('$') || virtcol('.') > virtcol('$') return '' endif normal! "zyl return @z catch return '' finally call setreg('z', reg, regtype) endtry endfunction " gui set guioptions=agitrhpF " &migemo if has("migemo") set migemo endif " convert "\\" to "/" on win32 like environment if exists('+shellslash') set shellslash endif " visual bell set novisualbell Lazy set t_vb= " set debug=beep " restore screen set norestorescreen set t_ti= set t_te= " timeout set notimeout " fillchars " TODO Change the color of inactive statusline. set fillchars=stl:\ ,stlnc::,vert:\ ,fold:-,diff:- " cursor behavior in insertmode set whichwrap=b,s set backspace=indent,eol,start set formatoptions=mMcroqnl2 " undo-persistence if has('persistent_undo') set undofile let &undodir = $MYVIMDIR . '/info/undo' silent! call mkdir(&undodir, 'p') endif " http://vim-users.jp/2009/12/hack107/ " Enable mouse support. set mouse=a " For screen. if &term =~ "^screen" augroup MyAutoCmd autocmd VimLeave * :set mouse= augroup END " workaround for freeze when using mouse on GNU screen. set ttymouse=xterm2 endif if has('gui_running') " Show popup menu if right click. set mousemodel=popup " Don't focus the window when the mouse pointer is moved. set nomousefocus " Hide mouse pointer on insert mode. set mousehide endif " misc. set diffopt=filler,vertical set helplang=ja,en set history=50 set keywordprg= " set lazyredraw set nojoinspaces set showcmd set nrformats=hex set shortmess=aI set switchbuf=useopen,usetab set textwidth=0 set colorcolumn=80 set viminfo='50,h,f1,n$HOME/.viminfo set matchpairs+=<:> set showbreak=↪ " }}} " Autocmd {{{ " colorscheme " NOTE: On MS Windows, setting colorscheme in .vimrc does not work. " Because :Lazy is necessary. " XXX: `:Lazy colorscheme tyru` does not throw ColorScheme event, " what the fuck? Lazy colorscheme tyru | doautocmd ColorScheme " Open a file as read-only if swap exists MyAutocmd SwapExists * let v:swapchoice = 'o' MyAutocmd QuickfixCmdPost * QuickFix " Set syntaxes MyAutocmd BufNewFile,BufRead *.as setlocal syntax=actionscript MyAutocmd BufNewFile,BufRead _vimperatorrc,.vimperatorrc setlocal syntax=vimperator MyAutocmd BufNewFile,BufRead *.avs setlocal syntax=avs " Aliases MyAutocmd FileType mkd setlocal filetype=markdown MyAutocmd FileType js setlocal filetype=javascript MyAutocmd FileType c++ setlocal filetype=cpp MyAutocmd FileType py setlocal filetype=python MyAutocmd FileType pl setlocal filetype=perl MyAutocmd FileType rb setlocal filetype=ruby MyAutocmd FileType scm setlocal filetype=scheme " Checking typo. {{{ MyAutocmd BufWriteCmd *[,*] call s:write_check_typo(expand('')) function! s:write_check_typo(file) let prompt = "possible typo: really want to write to '" . a:file . "'?(y/n):" if input(prompt) =~? '^\s*y' execute 'write' a:file endif endfunction " }}} " Automatic `:!chmod +x %`. {{{ command! -bar AutoChmodDisable let b:disable_auto_chmod = 1 command! -bar AutoChmodEnable unlet! b:disable_auto_chmod MyAutocmd BufWritePost * call s:auto_chmod() function! s:check_auto_chmod() "{{{ return !exists('b:disable_auto_chmod') \ && has('unix') \ && getfperm(expand('%'))[2] !=# 'x' \ && getline(1) =~# '^#!' \ && executable('chmod') endfunction "}}} function! s:auto_chmod() if s:check_auto_chmod() " XXX: 'setlocal autoread' and " 'setglobal autoread' and " 'autocmd FileChangedShell' also do not work. " This is expected behavior? let save_global_autoread = &g:autoread let save_local_autoread = &l:autoread set autoread try " Change permission. !chmod +x % redraw call s:echomsg('Special', 'chmod +x '.expand('%').' ... done.') sleep 1 catch return finally if save_global_autoread ==# save_local_autoread let &g:autoread = save_global_autoread set autoread< else let &l:autoread = save_local_autoread let &g:autoread = save_global_autoread endif endtry endif endfunction " }}} " Automatic mkdir when :edit nonexistent-file {{{ " 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("'" . a:dir . "' does not exist. Create? [y/N]") =~? '^y\%[es]$') call mkdir(iconv(a:dir, &encoding, &termencoding), 'p') endif endfunction augroup END " }}} " }}} " Mappings and/or Abbreviations {{{ " TODO " " MapOriginal: " MapOriginal j " MapOriginal k " " MapPrefix: " MapPrefix [n] prefix_name rhs " " MapLeader: " MapLeader ; " " MapLocalLeader: " MapLocalLeader , " " MapOp: " " Map [nvo] lhs rhs " MapOp lhs rhs " " MapMotion: " " Map [nvo] lhs rhs " MapMotion lhs rhs " " MapObject: " " Map [vo] lhs rhs " MapObject lhs rhs " " DisableMap: " " Map [n] $ " " Map [n] % " " . " " . " " . " DisableMap [n] $ % & ' ( ) ^ " " MapCount: " " Map -expr [n] v:count1 . 'gt' " MapCount [n] gt " TODO Do not clear mappings set by plugins. " mapclear " mapclear! " " mapclear!!!! " lmapclear " Set up general prefix keys. {{{ DefMacroMap [nvo] orig q DefMacroMap [ic] orig Map [n] q q DefMacroMap [nvo] excmd DefMacroMap [nvo] operator ; DefMacroMap [n] window DefMacroMap [nvo] prompt ,t let g:mapleader = ';' Map [n] Map [n] ;; ; Map [n] ,, , let g:maplocalleader = '\' Map [n] DefMacroMap [i] compl " }}} " map {{{ " operator {{{ " Copy to clipboard, primary. Map [nvo] y "+y Map [nvo] gy "*y Map [nvo] d "+d Map [nvo] gd "*d " Do not destroy noname register. Map [nvo] x "_x Map [nvo] e = if s:has_plugin('operator-user') " operator-adjust {{{ call operator#user#define('adjust', 'Op_adjust_window_height') function! Op_adjust_window_height(motion_wiseness) execute (line("']") - line("'[") + 1) 'wincmd' '_' normal! `[zt endfunction Map -remap [nvo] adj (operator-adjust) " }}} " operator-sort {{{ call operator#user#define_ex_command('sort', 'sort') Map -remap [nvo] s (operator-sort) " }}} " operator-retab {{{ call operator#user#define_ex_command('retab', 'retab') Map -remap [nvo] t (operator-retab) " }}} " operator-join {{{ call operator#user#define_ex_command('join', 'join') Map -remap [nvo] j (operator-join) " }}} " operator-uniq {{{ call operator#user#define_ex_command('uniq', 'sort u') Map -remap [nvo] u (operator-uniq) " }}} " operator-reverse-lines {{{ Map -remap [nvo] rl (operator-reverse-lines) " }}} " operator-reverse-text {{{ Map -remap [nvo] rw (operator-reverse-text) " }}} " operator-narrow {{{ call operator#user#define_ex_command('narrow', 'Narrow') Map -remap [nvo] na (operator-narrow) Map [nvo] nw :Widen let g:narrow_allow_overridingp = 1 " }}} " operator-replace {{{ Map -remap [nvo] p (operator-replace) " Map -remap [vo] p (operator-replace) " }}} " operator-camelize {{{ Map -remap [nvo] c (operator-camelize-toggle) let g:operator_camelize_all_uppercase_action = 'camelize' let g:operator_decamelize_all_uppercase_action = 'lowercase' " Test: g:operator_camelize_detect_function " function! Camelized(word) " return 0 " endfunction " let g:operator_camelize_detect_function = 'Camelized' " E704: Funcref variable name must start with a capital: g:operator_camelize_detect_function " let g:operator_camelize_detect_function = function('Camelized') " Test: mappings " Map -remap [nvo] c (operator-camelize) " Map -remap [nvo] C (operator-decamelize) " See "keymappings" branch. " Map -remap [nvo] c (operator-camelize/camelize) " Map -remap [nvo] C (operator-decamelize/lowercase) " }}} " operator-blank-killer {{{ call operator#user#define_ex_command('blank-killer', 's/\s\+$//') Map -remap [nvo] bk (operator-blank-killer) " }}} " operator-html-escape {{{ Map -remap [nvo] he (operator-html-escape) Map -remap [nvo] hu (operator-html-unescape) " }}} " operator-zen2han, operator-han2zen {{{ call operator#user#define('zen2han', 'Op_zen2han') function! Op_zen2han(motion_wiseness) " TODO endfunction call operator#user#define('han2zen', 'Op_han2zen') function! Op_han2zen(motion_wiseness) " TODO endfunction Map -remap [nvo] zh (operator-zen2han) Map -remap [nvo] hz (operator-han2zen) " }}} endif " }}} " motion {{{ Map [nvo] j gj Map [nvo] k gk Map [nvo] j j Map [nvo] k k " FIXME: Does not work in visual mode. Map [nvo] ]k :call search('^\S', 'Ws') Map [nvo] [k :call search('^\S', 'Wsb') Map [nvo] gp % " }}} " textobj {{{ Map -remap [vo] iF (textobj-fold-i) Map -remap [vo] aF (textobj-fold-a) Map -remap [vo] iF (textobj-between-i) Map -remap [vo] aF (textobj-between-a) Map -remap [vo] if (textobj-function-i) Map -remap [vo] af (textobj-function-a) Map [vo] aa a> Map [vo] ia i> Map [vo] ar a] Map [vo] ir i] Map -remap [vo] il (textobj-lastpat-n) " }}} " }}} " nmap {{{ DefMacroMap [nvo] fold z " Open only current line's fold. Map [n] zMzvzz " Folding mappings easy to remember. Map [n] l zo Map [n] h zc Map -silent [n] n nzz Map -silent [n] N Nzz " Operate on line without newline. Map [n] d 0d$ Map [n] y 0y$ Map [n] c 0c$ " http://vim-users.jp/2009/08/hack57/ Map [n] d :call append(line('.'), '')j Map [n] c :call append(line('.'), '')jI Map [n] me :messages Map [n] di :display Map [n] g; ~ Map [n] r gR Map [n] gl :cnext Map [n] gh :cNext Map [n] ct :tabclose Map [n] gm :make Map [n] tl :tabedit Map [n] th :tabedit:execute 'tabmove' (tabpagenr() isnot 1 ? tabpagenr() - 2 : '') Map [n] ,cd :cd %:p:h " :LookupCD - chdir to root directory of project working tree {{{ Map [n] cd :LookupCD %:p:h command! \ -bar -complete=dir -nargs=? \ LookupCD \ call s:cmd_lookup_cd() function! s:cmd_lookup_cd(args) "{{{ " Expand :cd like notation. let dir = expand(a:args != '' ? a:args : '.') " Get fullpath. let dir = fnamemodify(dir, ':p') if !isdirectory(dir) call s:warn("No such directory: " . dir) return endif return s:lookup_repo(dir) endfunction "}}} function! s:is_root_project_dir(dir) "{{{ let FP = s:Vital.System.Filepath " .git may be a file when its repository is a submodule. return isdirectory(FP.join(a:dir, '.git')) \ || filereadable(FP.join(a:dir, '.git')) \ || isdirectory(FP.join(a:dir, '.hg')) endfunction "}}} function! s:lookup_repo(dir) "{{{ " Assert isdirectory(a:dir) let parent = s:Vital.System.Filepath.dirname(a:dir) if a:dir ==# parent " root call s:warn('Not found project directory.') return elseif s:is_root_project_dir(a:dir) cd `=a:dir` else return s:lookup_repo(parent) endif endfunction "}}} " }}} " TODO: Smart 'zd': Delete empty line {{{ " }}} " TODO: Smart '{', '}': Treat folds as one non-empty line. {{{ " }}} " Execute most used command quickly {{{ Map [n] ee :edit Map [n] w :update Map [n] q :quit " }}} " Edit/Apply .vimrc quickly {{{ Map [n] ev :edit $MYVIMRC Map [n] sv :source $MYVIMRC " }}} " Cmdwin {{{ set cedit= function! s:cmdwin_enter() Map -buffer -force [ni] Map -buffer [n] :quit Map -buffer -force [n] k :quit Map -buffer -force [n] :quit Map -buffer -force -expr [i] col('.') == 1 ? "\:quit\" : "\" startinsert! endfunction MyAutocmd CmdwinEnter * call s:cmdwin_enter() Map [n] : q: Map [n] / q/ Map [n] ? q? " }}} " Moving tabs {{{ Map [n] :execute 'tabmove' (tabpagenr() == 1 ? tabpagenr('$') : tabpagenr() - 2) Map [n] :execute 'tabmove' (tabpagenr() == tabpagenr('$') ? 0 : tabpagenr()) " NOTE: Mappings , work only in gVim Map [n] :execute 'tabmove' 0 Map [n] :execute 'tabmove' tabpagenr('$') " }}} " Toggle options {{{ function! s:toggle_option(option_name) "{{{ if exists('&' . a:option_name) execute 'setlocal' a:option_name . '!' execute 'setlocal' a:option_name . '?' endif endfunction "}}} function! s:advance_state(state, elem) "{{{ let curidx = index(a:state, a:elem) let curidx = curidx is -1 ? 0 : curidx return a:state[index(a:state, curidx + 1) isnot -1 ? curidx + 1 : 0] endfunction "}}} function! s:advance_option_state(state, optname) "{{{ let varname = '&' . a:optname call setbufvar( \ '%', \ varname, \ s:advance_state( \ a:state, \ getbufvar('%', varname))) execute 'setlocal' a:optname . '?' endfunction "}}} Map [n] oh :call toggle_option('hlsearch') Map [n] oi :call toggle_option('ignorecase') Map [n] op :call toggle_option('paste') Map [n] ow :call toggle_option('wrap') Map [n] oe :call toggle_option('expandtab') Map [n] ol :call toggle_option('list') Map [n] on :call toggle_option('number') Map [n] om :call toggle_option('modeline') Map [n] ofc :call advance_option_state(['', 'all'], 'foldclose') Map [n] ofm :call advance_option_state(['manual', 'marker', 'indent'], 'foldmethod') command! \ -bar \ OptInit \ \ set hlsearch ignorecase nopaste wrap expandtab list modeline foldclose= foldmethod=manual \ | echo 'Initialized frequently toggled options.' Map [n] OI :OptInit silent OptInit " }}} " Close help/quickfix window {{{ " s:winutil {{{ unlet! s:winutil let s:winutil = {} function! s:winutil.close(winnr) "{{{ if s:winutil.exists(a:winnr) execute a:winnr . 'wincmd w' execute 'wincmd c' return 1 else return 0 endif endfunction "}}} function! s:winutil.exists(winnr) "{{{ return winbufnr(a:winnr) !=# -1 endfunction "}}} function! s:winutil.get_winnr_like(expr) "{{{ let ret = [] let winnr = 1 while winnr <= winnr('$') let bufnr = winbufnr(winnr) if eval(a:expr) call add(ret, winnr) endif let winnr = winnr + 1 endwhile return ret endfunction "}}} function! s:winutil.close_first_like(expr) "{{{ let winnr_list = s:winutil.get_winnr_like(a:expr) " Close current window if current matches a:expr. let winnr_list = s:move_current_winnr_to_head(winnr_list) if empty(winnr_list) return endif let prev_winnr = winnr() try for winnr in winnr_list call s:winutil.close(winnr) return 1 " closed. endfor return 0 finally " Back to previous window. let cur_winnr = winnr() if cur_winnr !=# prev_winnr && winbufnr(prev_winnr) !=# -1 execute prev_winnr . 'wincmd w' endif endtry endfunction "}}} " TODO Simplify function! s:move_current_winnr_to_head(winnr_list) "{{{ let winnr_list = a:winnr_list let curwinnr = winnr() let counter = 0 while index(winnr_list, counter) isnot -1 let nr = winnr_list[counter] if curwinnr ==# nr call remove(winnr_list, counter) return [nr] + winnr_list endif let counter += 1 endwhile return winnr_list endfunction "}}} lockvar 1 s:winutil " }}} " s:window {{{ unlet! s:window let s:window = {'_group_order': [], '_groups': {}} function! s:window.register(group_name, functions) "{{{ call add(s:window._group_order, a:group_name) let s:window._groups[a:group_name] = a:functions endfunction "}}} function! s:window.get_all_groups() "{{{ return map(copy(s:window._group_order), 'deepcopy(s:window._groups[v:val])') endfunction "}}} lockvar 1 s:window " }}} " cmdwin {{{ let s:in_cmdwin = 0 MyAutocmd CmdwinEnter * let s:in_cmdwin = 1 MyAutocmd CmdwinLeave * let s:in_cmdwin = 0 function! s:close_cmdwin_window() "{{{ if s:in_cmdwin quit return 1 else return 0 endif endfunction "}}} function! s:is_cmdwin_window(winnr) "{{{ return s:in_cmdwin endfunction "}}} call s:window.register('cmdwin', {'close': function('s:close_cmdwin_window'), 'detect': function('s:is_cmdwin_window')}) " }}} " help {{{ function! s:close_help_window() "{{{ return s:winutil.close_first_like('s:is_help_window(winnr)') endfunction "}}} function! s:is_help_window(winnr) "{{{ return getbufvar(winbufnr(a:winnr), '&buftype') ==# 'help' endfunction "}}} call s:window.register('help', {'close': function('s:close_help_window'), 'detect': function('s:is_help_window')}) " }}} " quickfix {{{ function! s:close_quickfix_window() "{{{ " cclose return s:winutil.close_first_like('s:is_quickfix_window(winnr)') endfunction "}}} function! s:is_quickfix_window(winnr) "{{{ return getbufvar(winbufnr(a:winnr), '&buftype') ==# 'quickfix' endfunction "}}} call s:window.register('quickfix', {'close': function('s:close_quickfix_window'), 'detect': function('s:is_quickfix_window')}) " }}} " ref {{{ function! s:close_ref_window() "{{{ return s:winutil.close_first_like('s:is_ref_window(winnr)') endfunction "}}} function! s:is_ref_window(winnr) "{{{ return getbufvar(winbufnr(a:winnr), '&filetype') ==# 'ref' endfunction "}}} call s:window.register('ref', {'close': function('s:close_ref_window'), 'detect': function('s:is_ref_window')}) " }}} " quickrun {{{ function! s:close_quickrun_window() "{{{ return s:winutil.close_first_like('s:is_quickrun_window(winnr)') endfunction "}}} function! s:is_quickrun_window(winnr) "{{{ return getbufvar(winbufnr(a:winnr), '&filetype') ==# 'quickrun' endfunction "}}} call s:window.register('quickrun', {'close': function('s:close_quickrun_window'), 'detect': function('s:is_quickrun_window')}) " }}} " unlisted {{{ function! s:close_unlisted_window() "{{{ return s:winutil.close_first_like('s:is_unlisted_window(winnr)') endfunction "}}} function! s:is_unlisted_window(winnr) "{{{ return !getbufvar(winbufnr(a:winnr), '&buflisted') endfunction "}}} call s:window.register('unlisted', {'close': function('s:close_unlisted_window'), 'detect': function('s:is_unlisted_window')}) " }}} function! s:close_certain_window() "{{{ let curwinnr = winnr() let groups = s:window.get_all_groups() " Close current. for group in groups if group.detect(curwinnr) call group.close() return endif endfor " Or close outside buffer. for group in groups if group.close() return 1 endif endfor endfunction "}}} Map [n] c: :call close_cmdwin_window() Map [n] ch :call close_help_window() Map [n] cQ :call close_quickfix_window() Map [n] cr :call close_ref_window() Map [n] cq :call close_quickrun_window() Map [n] cb :call close_unlisted_window() Map [n] cc :call close_certain_window() " }}} " 'Y' to yank till the end of line. {{{ Map [n] Y y$ Map [n] ;Y "+y$ Map [n] ,Y "*y$ " }}} " Back to col '$' when current col is right of col '$'. {{{ " " 1. move to the last col " when over the last col ('virtualedit') and getregtype(v:register) ==# 'v'. " 2. do not insert " " before inserted text " when characterwise and getregtype(v:register) ==# 'v'. function! s:virtualedit_enabled() return has('virtualedit') \ && &virtualedit =~# '\\|\' endfunction if s:virtualedit_enabled() function! s:paste_characterwise_nicely() let reg = '"' . v:register let move_to_last_col = \ (s:virtualedit_enabled() \ && col('.') >= col('$')) \ ? '$' : '' let paste = \ reg . (getline('.') ==# '' ? 'P' : 'p') return getregtype(v:register) ==# 'v' ? \ move_to_last_col . paste : \ reg . 'p' endfunction Map -expr [n] p paste_characterwise_nicely() endif " }}} " [hjkl] for [hjkl] {{{ Map -silent [n] j j Map -silent [n] k k Map -silent [n] h h Map -silent [n] l l Map -silent [n] n w Map -silent [n] p W " }}} " Moving between tabs {{{ Map -silent [n] gt Map -silent [n] gT " }}} " Move all windows of current group beyond next group. {{{ " TODO " }}} " quickfix buffer-local mappings {{{ MyAutocmd FileType qf call s:quickfix_settings() function! s:quickfix_settings() Map -buffer [n] j jzo Map -buffer [n] k kzo endfunction " }}} " "Use one tabpage per project" project {{{ " :SetTabName - Set tab's title {{{ Map -silent [n] :SetTabName command! -bar -nargs=* SetTabName call s:cmd_set_tab_name() function! s:cmd_set_tab_name(name) "{{{ let old_title = exists('t:title') ? t:title : '' if a:name == '' let t:title = input('tab name?:', old_title) else let t:title = a:name endif if t:title !=# old_title " :redraw does not update tabline. redraw! endif endfunction "}}} " }}} " }}} " }}} " vmap {{{ " Map [v] g1gs Map -silent [v] y y:call remove_trailing_spaces_blockwise() function! s:remove_trailing_spaces_blockwise() let regname = v:register if getregtype(regname)[0] !=# "\" return '' endif let value = getreg(regname, 1) let expr = 'substitute(v:val, '.string('\v\s+$').', "", "")' let value = s:splitmapjoin(value, '\n', expr, "\n") call setreg(regname, value, "\") endfunction function! s:splitmapjoin(str, pattern, expr, sep) return join(map(split(a:str, a:pattern, 1), a:expr), a:sep) endfunction " http://labs.timedia.co.jp/2012/10/vim-more-useful-blockwise-insertion.html Map -expr [v] I force_blockwise_visual('I') Map -expr [v] A force_blockwise_visual('A') function! s:force_blockwise_visual(next_key) if mode() ==# 'v' return "\" . a:next_key elseif mode() ==# 'V' return "\0o$" . a:next_key else " mode() ==# "\" return a:next_key endif endfunction " }}} " map! {{{ Map [ic] Map [ic] Map [ic] Map [ic] Map [ic] if 0 function! s:eclipse_like_autoclose(quote) if mode() !~# '^\(i\|R\|Rv\|c\|cv\|ce\)$' return a:quote endif return \ col('.') <=# 1 || col('.') >=# col('$') ? \ a:quote.a:quote."\" : \ getline('.')[col('.') - 1] ==# a:quote ? \ "\" : \ getline('.')[col('.') - 2] ==# a:quote ? \ a:quote.a:quote."\" : \ a:quote endfunction noremap! " eclipse_like_autoclose('"') noremap! ' eclipse_like_autoclose("'") endif " }}} " imap {{{ Map [i] " shift left (indent) Map [i] " make and undoable. Map [i] u Map [i] u Map [i] Map [i] O Map [i] o " completion {{{ Map [i] " Map [i] n " Map [i] p Map [i] n Map [i] p Map [i] ] Map [i] d Map [i] f Map [i] i Map [i] k Map [i] l " Map [i] s " Map [i] t Map -expr [i] o omni_or_user_func() function! s:omni_or_user_func() "{{{ if &omnifunc != '' return "\\" elseif &completefunc != '' return "\\" else return "\" endif endfunction "}}} " Map [i] j " Map [i] k " TODO " call submode#enter_with('c', 'i', '', emap#compile_map('i', 'j'), '') " call submode#enter_with('c', 'i', '', emap#compile_map('i', 'k'), '') " call submode#leave_with('c', 'i', '', '') " call submode#map ('c', 'i', '', 'j', '') " call submode#map ('c', 'i', '', 'k', '') Map -expr [i] neocomplcache#close_popup() Map -expr [i] pumvisible() ? neocomplcache#close_popup() . "\" : "\" Map -remap [is] (neocomplcache_snippets_expand) " }}} " }}} " cmap {{{ if &wildmenu Map -force [c] Map -force [c] endif " paste register Map [c] + Map [c] * Map [c] " Map [c] Map [c] Map [c] " Escape /,? {{{ Map -expr [c] / getcmdtype() == '/' ? '\/' : '/' Map -expr [c] ? getcmdtype() == '?' ? '\?' : '?' " }}} " }}} " abbr {{{ Map -abbr -expr [i] date@ strftime('%Y-%m-%d') Map -abbr -expr [i] time@ strftime("%H:%M") Map -abbr -expr [i] dt@ strftime("%Y-%m-%d %H:%M") Map -abbr -expr [ic] mb@ [^\x01-\x7e] MapAlterCommand th tab help MapAlterCommand t tabedit MapAlterCommand sf setf MapAlterCommand hg helpgrep MapAlterCommand ds diffsplit MapAlterCommand do diffoff! " For typo. MapAlterCommand qw wq MapAlterCommand amp map " }}} " Mappings with option value. {{{ function! s:expr_with_options(cmd, opt) "{{{ for [name, value] in items(a:opt) call setbufvar('%', name, value) endfor return a:cmd endfunction "}}} Map -expr [n] / expr_with_options('/', {'&ignorecase': 1, '&hlsearch': 1}) Map -expr [n] ? expr_with_options('?', {'&ignorecase': 1, '&hlsearch': 1}) Map -expr [n] * expr_with_options('*', {'&ignorecase': 0, '&hlsearch': 1}) Map -expr [n] # expr_with_options('#', {'&ignorecase': 0, '&hlsearch': 1}) Map -expr [nv] : expr_with_options(':', {'&ignorecase': 1}) Map -expr [n] gd expr_with_options('gd', {'&hlsearch': 1}) Map -expr [n] gD expr_with_options('gD', {'&hlsearch': 1}) " }}} " Emacs like kill-line. {{{ Map -expr [i] "\u".(col('.') == col('$') ? 'gJ' : 'D') Map [c] e getcmdpos() == 1 ? '' : getcmdline()[:getcmdpos()-2] " }}} " Make searching directions consistent {{{ " 'zv' is harmful for Operator-pending mode and it should not be included. " For example, 'cn' is expanded into 'cnzv' so 'zv' will be inserted. Map -expr [nv] n search_forward_p() ? 'nzv' : 'Nzv' Map -expr [nv] N search_forward_p() ? 'Nzv' : 'nzv' Map -expr [o] n search_forward_p() ? 'n' : 'N' Map -expr [o] N search_forward_p() ? 'N' : 'n' function! s:search_forward_p() return exists('v:searchforward') ? v:searchforward : 1 endfunction " }}} " Walk between columns at 0, ^, $, window's right edge(virtualedit). {{{ function! s:back_between(zero, tilde, dollar) "{{{ let curcol = col('.') let tilde_col = match(getline('.'), '\S') + 1 if curcol > col('$') " $ ~ return a:dollar elseif curcol > tilde_col " ^ ~ $ return a:tilde else " 0 ~ ^ return a:zero endif endfunction "}}} function! s:advance_between(tilde, dollar) "{{{ let curcol = col('.') let tilde_col = match(getline('.'), '\S') + 1 if curcol < tilde_col " 0 ~ ^ return a:tilde elseif curcol < col('$') " ^ ~ $ return a:dollar else " $ ~ return a:dollar " back endif endfunction "}}} " imap Map -force -expr [i] back_between("\", "\^", "\") Map -force -expr [i] advance_between("\^", "\") " motion Map -expr [nvo] H back_between('0', '^', '$') Map -expr [nvo] L advance_between('^', '$') " TODO " Map -expr [nvo] L advance_between('^', '$', '') " " }}} " Disable unused keys. {{{ Map [n] Map [n] ZZ Map [n] ZQ Map [n] U " }}} " Expand abbreviation {{{ " http://gist.github.com/347852 " http://gist.github.com/350207 DefMap [i] -expr bs-ctrl-] getline('.')[col('.') - 2] ==# "\" ? "\" : '' DefMap [c] -expr bs-ctrl-] getcmdline()[getcmdpos() - 2] ==# "\" ? "\" : '' Map -remap [ic] " }}} " Add current line to quickfix. {{{ command! -bar -range QFAddLine ,call s:quickfix_add_range() function! s:quickfix_add_range() range for lnum in range(a:firstline, a:lastline) call s:quickfix_add_line(lnum) endfor endfunction function! s:quickfix_add_line(lnum) let lnum = a:lnum =~# '^\d\+$' ? a:lnum : line(a:lnum) let qf = { \ 'bufnr': bufnr('%'), \ 'lnum': lnum, \ 'text': getline(lnum), \} if s:quickfix_supported_quickfix_title() " Set 'qf.col' and 'qf.vcol'. call s:quickfix_add_line_set_col(lnum, qf) endif call setqflist([qf], 'a') endfunction function! s:quickfix_add_line_set_col(lnum, qf) let lnum = a:lnum let qf = a:qf let search_word = s:quickfix_get_search_word() if search_word !=# '' let idx = match(getline(lnum), search_word[1:]) if idx isnot -1 let qf.col = idx + 1 let qf.vcol = 0 endif endif endfunction " }}} " :QFSearchAgain {{{ command! -bar QFSearchAgain call s:qf_search_again() function! s:qf_search_again() let qf_winnr = s:quickfix_get_winnr() if !qf_winnr copen endif let search_word = s:quickfix_get_search_word() if search_word !=# '' let @/ = search_word[1:] setlocal hlsearch try execute 'normal!' "/\" catch call s:echomsg('ErrorMsg', v:exception) endtry endif endfunction " }}} " Quickfix utility functions {{{ function! s:quickfix_get_winnr() " quickfix window is usually at bottom, " thus reverse-lookup. for winnr in reverse(range(1, winnr('$'))) if getwinvar(winnr, '&buftype') ==# 'quickfix' return winnr endif endfor return 0 endfunction function! s:quickfix_exists_window() return !!s:quickfix_get_winnr() endfunction function! s:quickfix_supported_quickfix_title() return v:version >=# 703 endfunction function! s:quickfix_get_search_word() " NOTE: This function returns a string starting with "/" " if previous search word is found. " This function can't use an empty string " as a failure return value, because ":vimgrep /" also returns an empty string. " w:quickfix_title only works 7.3 or later. if !s:quickfix_supported_quickfix_title() return '' endif let qf_winnr = s:quickfix_get_winnr() if !qf_winnr copen endif try let qf_title = getwinvar(qf_winnr, 'quickfix_title') if qf_title ==# '' return '' endif " NOTE: Supported only :vim[grep] command. let rx = '^:\s*\\s*\(/.*\)' let m = matchlist(qf_title, rx) if empty(m) return '' endif return m[1] finally if !qf_winnr cclose endif endtry endfunction " }}} " Mouse {{{ " TODO: Add frequently-used-commands to the top level of the menu. " like MS Windows Office 2007 Ribborn interface. " Do not adjust current scroll position (do not fire 'scrolloff') on single-click. Map -silent [n] :set eventignore=all:set eventignore= " Double-click for searching the word under the cursor. Map [n] <2-LeftMouse> g* " Single-click for searching the word selected in visual-mode. Map -remap [v] (visualstar-g*) " Select lines with Map [n] V " }}} " }}} " Encoding {{{ let s:enc = 'utf-8' let &enc = s:enc let &fenc = s:enc let &termencoding = s:enc let &fileencodings = join(s:Vital.Data.List.uniq( \ [s:enc] \ + split(&fileencodings, ',') \ + ['iso-2022-jp', 'iso-2022-jp-3', 'cp932'] \), ',') unlet s:enc set fileformats=unix,dos,mac if exists('&ambiwidth') set ambiwidth=double endif " }}} " FileType {{{ function! s:current_filetypes() "{{{ return split(&l:filetype, '\.') endfunction "}}} function! s:set_dict() "{{{ let filetype_vs_dictionary = { \ 'c': ['c', 'cpp'], \ 'cpp': ['c', 'cpp'], \ 'html': ['html', 'css', 'javascript'], \ 'scala': ['scala', 'java'], \} let dicts = [] for ft in s:current_filetypes() for ft in get(filetype_vs_dictionary, ft, [ft]) let dict_path = $MYVIMDIR . '/dict/' . ft . '.dict' if filereadable(dict_path) call add(dicts, dict_path) endif endfor endfor let &l:dictionary = join(s:Vital.Data.List.uniq(dicts), ',') endfunction "}}} function! s:is_current_filetype(filetypes) if type(a:filetypes) isnot type([]) return s:is_current_filetype([a:filetypes]) endif let filetypes = copy(a:filetypes) for ft in s:current_filetypes() if !empty(filter(filetypes, 'v:val ==# ft')) return 1 endif endfor return 0 endfunction function! s:set_tab_width() "{{{ if s:is_current_filetype( \ ['css', 'xml', 'html', 'lisp', 'scheme', 'yaml'] \) CodingStyle Short indent else CodingStyle My style endif endfunction "}}} function! s:set_compiler() "{{{ let filetype_vs_compiler = { \ 'c': 'gcc', \ 'cpp': 'gcc', \ 'html': 'tidy', \ 'java': 'javac', \} try for ft in s:current_filetypes() execute 'compiler' get(filetype_vs_compiler, ft, ft) endfor catch /E666:/ " compiler not supported: ... endtry endfunction "}}} function! s:load_filetype() "{{{ if &omnifunc == "" setlocal omnifunc=syntaxcomplete#Complete endif call s:set_dict() call s:set_tab_width() call s:set_compiler() endfunction "}}} MyAutocmd FileType * call s:load_filetype() " }}} " Commands {{{ " :DiffOrig {{{ " from vimrc_example.vim " " Convenient command to see the difference between the current buffer and the " file it was loaded from, thus the changes you made. " Only define it when not defined already. command! -bar DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis \ | wincmd p | diffthis " }}} " :MTest {{{ " convert Perl's regex to Vim's regex " No -bar command! \ -nargs=+ \ MTest \ call s:MTest() function! s:MTest(args) "{{{ let org_search = @/ let org_hlsearch = &hlsearch try silent execute "M" . a:args let @" = @/ catch return finally let @/ = org_search let &hlsearch = org_hlsearch endtry echo @" endfunction "}}} " }}} " :EchoPath - Show path-like option in a readable way {{{ MapAlterCommand epa EchoPath MapAlterCommand rtp EchoPath&rtp " TODO Add -complete=option command! \ -bar -nargs=+ -complete=expression \ EchoPath \ call s:cmd_echo_path() function! s:cmd_echo_path(optname, ...) "{{{ let delim = a:0 != 0 ? a:1 : ',' let val = eval(a:optname) for i in split(val, delim) echo i endfor endfunction "}}} " }}} " :AllMaps - Do show/map in all modes. {{{ command! \ -nargs=* -complete=mapping \ AllMaps \ map | map! | lmap " }}} " :Expand {{{ command! \ -bar -nargs=? \ Expand \ call s:cmd_expand() function! s:cmd_expand(args) "{{{ if a:args != '' echo expand(a:args) else if getbufvar('%', '&buftype') == '' echo expand('%:p') else echo expand('%') endif endif endfunction "}}} MapAlterCommand ep Expand " }}} " :Has {{{ MapAlterCommand has Has command! \ -bar -nargs=1 -complete=customlist,feature_list_excomplete#complete \ Has \ echo has() " }}} " :GlobPath {{{ command! \ -bar -nargs=1 -complete=file \ GlobPath \ echo globpath(&rtp, , 1) MapAlterCommand gp GlobPath " }}} " :QuickFix - Wrapper for favorite quickfix opening command {{{ " Select prefered command from cwindow, copen, and so on. command! \ -bar -nargs=? \ QuickFix \ if !empty(getqflist()) | cwindow | endif MapAlterCommand qf QuickFix " }}} " :Capture {{{ MapAlterCommand cap[ture] Capture 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 "}}} " }}} " :SynNames {{{ " :help synstack() command! \ -bar \ SynNames \ \ for id in synstack(line("."), col(".")) \ | echo synIDattr(id, "name") \ | endfor \ | unlet! id " }}} " :Help {{{ MapAlterCommand h[elp] Help " No -bar command! \ -bang -nargs=* -complete=help \ Help \ vertical rightbelow help " }}} " :NonSortUniq {{{ " " http://lingr.com/room/vim/archives/2010/11/18#message-1023619 " > :let d={}|g/./let l=getline('.')|if has_key(d,l)|d|else|let d[l]=1 command! \ -bar \ NonSortUniq \ let d={}|g/./let l=getline('.')|if has_key(d,l)|d|el|let d[l]=1 " E147: Cannot do :global recursive " command! " \ -bar " \ NonSortUniq " \ g/./let l=getline('.')|g/./if l==getline('.')|d " }}} " :Ctags {{{ MapAlterCommand ctags Ctags command! \ -bar \ Ctags \ call s:cmd_ctags() function! s:cmd_ctags() "{{{ if !executable('ctags') return endif execute '!ctags' (filereadable('.ctags') ? '' : '-R') endfunction "}}} " }}} " }}} " For Plugins {{{ if s:has_plugin('nextfile') " {{{ let g:nf_map_next = '' let g:nf_map_previous = '' Map -remap [n] ,n (nextfile-next) Map -remap [n] ,p (nextfile-previous) let g:nf_include_dotfiles = 1 " don't skip dotfiles let g:nf_ignore_ext = ['o', 'obj', 'exe', 'bin'] function! NFLoopMsg(file_to_open) redraw call s:echomsg('WarningMsg', 'open a file from the start...') " Always open a next/previous file... return 1 endfunction function! NFLoopPrompt(file_to_open) return input('open a file from the start? [y/n]:') =~? 'y\%[es]' endfunction " g:nf_loop_hook_fn only works when g:nf_loop_files is true. let g:nf_loop_files = 1 " Call this function when wrap around. " let g:nf_loop_hook_fn = 'NFLoopPrompt' let g:nf_loop_hook_fn = 'NFLoopMsg' " To avoid |hit-enter| for NFLoopMsg(). let g:nf_open_command = 'silent edit' endif " }}} if s:has_plugin('starter') " {{{ " TODO let g:loaded_starter = 1 " let g:starter_no_default_command = 1 " nnoremap gt :call starter#launch() " function! StarterAfterHookFile(path) "{{{ " if !filereadable(a:path) " return " endif " " Open the file. " execute 'edit' a:path " " Set filetype. " let filetype = fnamemodify(a:path, ':e') " if filetype != '' " \ && globpath(&rtp, 'ftplugin/' . filetype . '.vim') != '' " execute 'setfiletype' filetype " endif " endfunction "}}} " function! s:system_list(args_list) "{{{ " return system(join( " \ map(copy(a:args_list), 'shellescape(v:val)'))) " endfunction "}}} " function! StarterAfterHookDir(path) "{{{ " if !isdirectory(a:path) " return " endif " if filereadable(a:path . '/setup') " call s:system_list(a:path . '/setup', [a:path]) " call delete(a:path . '/setup') " endif " if filereadable(a:path . '/setup.sh') " call s:system_list('/bin/sh', [a:path . '/setup.sh', a:path]) " call delete(a:path . '/setup.sh') " endif " if filereadable(a:path . '/setup.pl') " call s:system_list('perl', [a:path . '/setup.pl', a:path]) " call delete(a:path . '/setup.pl') " endif " if filereadable(a:path . '/setup.py') " call s:system_list('python', [a:path . '/setup.py', a:path]) " call delete(a:path . '/setup.py') " endif " if filereadable(a:path . '/setup.rb') " call s:system_list('ruby', [a:path . '/setup.rb', a:path]) " call delete(a:path . '/setup.rb') " endif " endfunction "}}} " let g:starter#after_hook = [ " \ 'StarterAfterHookFile', " \ 'StarterAfterHookDir', " \] endif " }}} if s:has_plugin('vimtemplate') " {{{ " TODO: starter.vim " let g:loaded_vimtemplate = 1 let g:vt_author = "tyru" let g:vt_email = "tyru.exe@gmail.com" let g:vt_files_metainfo = { \ 'cppsrc-scratch.cpp': {'filetype': "cpp"}, \ 'cppsrc.cpp' : {'filetype': "cpp"}, \ 'csharp.cs' : {'filetype': "cs"}, \ 'csrc.c' : {'filetype': "c"}, \ 'header.h' : {'filetype': "c"}, \ 'hina.html' : {'filetype': "html"}, \ 'javasrc.java' : {'filetype': "java"}, \ 'perl.pl' : {'filetype': "perl"}, \ 'perlmodule.pm' : {'filetype': "perl"}, \ 'python.py' : {'filetype': "python"}, \ 'scala.scala' : {'filetype': "scala"}, \ 'scheme.scm' : {'filetype': "scheme"}, \ 'vimscript.vim' : {'filetype': "vim"} \} let g:vt_open_command = 'botright 7new' " Disable &modeline when opened template file. execute \ 'MyAutocmd BufReadPre' \ $MYVIMDIR . '/template/*' \ 'setlocal nomodeline' endif " }}} if s:has_plugin('winmove') " {{{ let g:wm_move_down = '' let g:wm_move_up = '' let g:wm_move_left = '' let g:wm_move_right = '' endif " }}} if s:has_plugin('sign-diff') " {{{ " let g:SD_debug = 1 let g:SD_disable = 1 if !g:SD_disable Map -silent [n] :SDUpdate endif endif " }}} if s:has_plugin('DumbBuf') " {{{ let dumbbuf_hotkey = 'gb' " たまにQuickBuf.vimの名残でを押してしまう let dumbbuf_mappings = { \'n': { \'': {'alias_to': 'q'}, \} \} let dumbbuf_wrap_cursor = 0 let dumbbuf_remove_marked_when_close = 1 " let dumbbuf_shown_type = 'project' " let dumbbuf_close_when_exec = 1 " DumbBuf nmap s split # " DumbBuf nmap g sbuffer " call dumbbuf#map('n', '', 0, 'g', ':sbuffer %d') " let dumbbuf_cursor_pos = 'keep' " For (compatibility) test " " let dumbbuf_shown_type = 'foobar' " let dumbbuf_listed_buffer_name = "*foo bar*" " " let dumbbuf_verbose = 1 endif " }}} if s:has_plugin('prompt') " {{{ let prompt_debug = 0 endif " }}} if s:has_plugin('skk') || s:has_plugin('eskk') " {{{ call rtputil#append('~/.vim/bundle/skkdict.vim') let s:skk_user_dict = '~/.skkdict/user-dict' let s:skk_user_dict_encoding = 'utf-8' let s:skk_system_dict = '~/.skkdict/system-dict' let s:skk_system_dict_encoding = 'euc-jp' if 1 " Map to eskk, Map to skk.vim let skk_control_j_key = '' else " Map to skk.vim, Map to eskk Map -remap [ic] (eskk:toggle) endif endif " }}} if s:has_plugin('skk') " {{{ let skk_jisyo = s:skk_user_dict let skk_jisyo_encoding = s:skk_user_dict_encoding let skk_large_jisyo = s:skk_system_dict let skk_large_jisyo_encoding = s:skk_system_dict_encoding " let skk_control_j_key = '' " Map -remap [lic] (skk-enable-im) let skk_manual_save_jisyo_keys = '' let skk_egg_like_newline = 1 let skk_auto_save_jisyo = 1 let skk_imdisable_state = -1 let skk_keep_state = 1 let skk_show_candidates_count = 2 let skk_show_annotation = 0 let skk_sticky_key = ';' let skk_use_color_cursor = 1 let skk_remap_lang_mode = 0 if 0 " g:skk_enable_hook test {{{ " Do not map `(skk-toggle-im)`. let skk_control_j_key = '' " `` to enable, `` to disable. Map -remap [ic] (skk-enable-im) Map -remap [ic] function! MySkkMap() lunmap lmap (skk-disable-im) endfunction function! HelloWorld() echomsg 'Hello.' endfunction function! Hogera() echomsg 'hogera' endfunction let skk_enable_hook = 'MySkkMap,HelloWorld,Hogera' " }}} endif endif " }}} if s:has_plugin('eskk') " {{{ if has('vim_starting') let g:eskk#dictionary = { \ 'path': s:skk_user_dict, \ 'encoding': s:skk_user_dict_encoding, \} let g:eskk#large_dictionary = { \ 'path': s:skk_system_dict, \ 'encoding': s:skk_system_dict_encoding, \} endif let g:eskk#debug = 1 if 1 " for debugging default behavior. let g:eskk#egg_like_newline = 1 let g:eskk#egg_like_newline_completion = 1 let g:eskk#show_candidates_count = 2 let g:eskk#show_annotation = 1 let g:eskk#rom_input_style = 'msime' let g:eskk#keep_state = 1 let g:eskk#keep_state_beyond_buffer = 1 let g:eskk#marker_henkan = '$' let g:eskk#marker_okuri = '*' let g:eskk#marker_henkan_select = '@' let g:eskk#marker_jisyo_touroku = '?' let g:eskk#dictionary_save_count = 5 if has('vim_starting') " MyAutocmd User eskk-initialize-pre call s:eskk_initial_pre() function! s:eskk_initial_pre() "{{{ " User can be allowed to modify " eskk global variables (`g:eskk#...`) " until `User eskk-initialize-pre` event. " So user can do something heavy process here. " (I'm a paranoia, eskk#table#new() is not so heavy. " But it loads autoload/vice.vim recursively) for [orgtable, mode] in [['rom_to_hira', 'hira'], ['rom_to_kata', 'kata']] let t = eskk#table#new(orgtable.'*', orgtable) call t.add_map('~', '〜') call t.add_map('vc', '©') call t.add_map('vr', '®') call t.add_map('vh', '☜') call t.add_map('vj', '☟') call t.add_map('vk', '☝') call t.add_map('vl', '☞') call t.add_map('jva', 'ゔぁ') call t.add_map('jvi', 'ゔぃ') call t.add_map('jvu', 'ゔ') call t.add_map('jve', 'ゔぇ') call t.add_map('jvo', 'ゔぉ') call t.add_map('z ', ' ') " Input hankaku characters. call t.add_map('(', '(') call t.add_map(')', ')') " It is better to register the word "Exposé" than to register this map :) call t.add_map('qe', 'é') if g:eskk#rom_input_style ==# 'skk' call t.add_map('zw', 'w', 'z') endif call eskk#register_mode_table(mode, t) endfor endfunction "}}} " by @hinagishi " function! s:eskk_initial_pre() "{{{ " let t = eskk#table#new('rom_to_hira*', 'rom_to_hira') " call t.add_map(',', ', ') " call t.add_map('.', '.') " call eskk#register_mode_table('hira', t) " let t = eskk#table#new('rom_to_kata*', 'rom_to_kata') " call t.add_map(',', ', ') " call t.add_map('.', '.') " call eskk#register_mode_table('kata', t) " endfunction "}}} MyAutocmd User eskk-initialize-post call s:eskk_initial_post() function! s:eskk_initial_post() "{{{ " Disable "qkatakana", but ";katakanaq" works. " NOTE: This makes some eskk tests fail! " EskkMap -type=mode:hira:toggle-kata " map! (eskk:enable) " EskkMap " " EskkMap U (eskk:undo-kakutei) " EskkMap jj " EskkMap -no-unique jj hoge endfunction "}}} endif " Debug command! -bar EskkDumpBuftable PP! eskk#get_buftable().dump() command! -bar -nargs=1 EskkDumpTable PP! eskk#table##load() " EskkMap lhs rhs " EskkMap -silent lhs2 rhs " EskkMap -unique lhs2 foo " EskkMap -expr lhs3 {'foo': 'hoge'}.foo " EskkMap -noremap lhs4 rhs endif endif " }}} if s:has_plugin('restart') " {{{ command! \ -bar \ RestartWithSession \ let g:restart_sessionoptions = 'blank,curdir,folds,help,localoptions,tabpages' \ | Restart MapAlterCommand res[tart] Restart MapAlterCommand ers[tart] Restart MapAlterCommand rse[tart] Restart endif " }}} if s:has_plugin('openbrowser') " {{{ let g:netrw_nogx = 1 Map -remap [nv] gx (openbrowser-smart-search) MapAlterCommand o[pen] OpenBrowserSmartSearch endif " }}} if s:has_plugin('AutoDate') " {{{ let g:autodate_format = "%Y-%m-%d" endif " }}} " anything (ku,fuf,unite,etc.) {{{ DefMacroMap [n] anything s " Which anything do you like? let [s:anything_fuf, s:anything_ku, s:anything_unite] = range(3) let s:anything = s:anything_unite if s:anything == s:anything_fuf && s:has_plugin('fuf') Map [n] d :FufDir Map [n] f :FufFile Map [n] h :FufMruFile Map [n] r :FufRenewCache elseif s:anything == s:anything_ku && s:has_plugin('ku') Map [n] f :Ku file Map [n] h :Ku file/mru Map [n] H :Ku history Map [n] : :Ku cmd_mru/cmd Map [n] / :Ku cmd_mru/search elseif s:has_plugin('unite') " fallback, or you select this :) command! -bar -nargs=* UniteKawaii Unite -prompt='-')/\ -no-split Map [n] f :UniteKawaii -buffer-name=files file buffer file_mru Map [n] F :UniteKawaii -buffer-name=files file_rec Map [n] p :UniteKawaii -buffer-name=files buffer_tab Map [n] h :UniteKawaii -buffer-name=files file_mru Map [n] t :UniteKawaii -immediately tab:no-current Map [n] w :UniteKawaii -immediately window:no-current Map [n] T :UniteKawaii tag Map [n] H :UniteKawaii help Map [n] b :UniteKawaii buffer Map [n] o :UniteKawaii outline Map [n] r :UniteKawaii -input=ref/ source Map [n] s :UniteKawaii source Map [n] g :UniteKawaii grep Map [n] / :UniteKawaii line Map [n] : :UniteKawaii history/command else let s:anything_not_found = 1 endif " abbrev function! s:register_anything_abbrev() "{{{ let abbrev = { \ '^r@': [$VIMRUNTIME . '/'], \ '^p@': map(split(&runtimepath, ','), 'v:val . "/plugin/"'), \ '^h@': ['~/'], \ '^v@': [$MYVIMDIR . '/'], \ '^g@': ['~/git/'], \ '^d@': ['~/git/dotfiles/'], \ '^m@': ['~/Dropbox/memo/'], \ '^s@': ['~/scratch/'], \} if has('win16') || has('win32') || has('win64') || has('win95') call extend(abbrev, { \ '^m@' : ['~/My Dropbox/memo/'], \ '^de@' : ['C:' . substitute($HOMEPATH, '\', '/', 'g') . '/デスクトップ/'], \ '^cy@' : [exists('$CYGHOME') ? $CYGHOME . '/' : 'C:/cygwin/home/'. $USERNAME .'/'], \ '^ms@' : [exists('$MSYSHOME') ? $MSYSHOME . '/' : 'C:/msys/home/'. $USERNAME .'/'], \}) endif " fuf if s:has_plugin('fuf') let g:fuf_abbrevMap = abbrev endif " unite if s:has_plugin('unite') for [pat, subst_list] in items(abbrev) call unite#set_substitute_pattern('files', pat, subst_list) endfor endif endfunction "}}} if !exists('s:anything_not_found') Lazy call s:register_anything_abbrev() endif if s:has_plugin('ku') " {{{ MapAlterCommand ku Ku endif " }}} if s:has_plugin('fuf') " {{{ let g:fuf_modesDisable = ['mrucmd', 'bookmark', 'givenfile', 'givendir', 'givencmd', 'callbackfile', 'callbackitem', 'buffer', 'tag', 'taggedfile'] let fuf_keyOpenTabpage = '' let fuf_keyNextMode = '' let fuf_keyPrevMode = '' let fuf_keyOpenSplit = '' let fuf_keyOpenVsplit = '' let fuf_enumeratingLimit = 20 let fuf_previewHeight = 0 endif " }}} if s:has_plugin('unite') " {{{ let g:unite_enable_start_insert = 1 let g:unite_enable_ignore_case = 1 let g:unite_enable_smart_case = 1 let g:unite_enable_split_vertically = 0 let g:unite_split_rule = \ g:unite_enable_split_vertically ? \ 'topleft' : 'rightbelow' let g:unite_update_time = 50 let g:unite_source_file_mru_ignore_pattern = \ '^/tmp/.*\|^/var/tmp/.*\|\.tmp$\|COMMIT_EDITMSG' " unite-source-menu {{{ let g:unite_source_menu_menus = {} function! UniteSourceMenuMenusMap(key, value) return { \ 'word' : a:key, \ 'kind' : 'command', \ 'action__command' : a:value, \} endfunction " set enc=... {{{ let g:unite_source_menu_menus.enc = { \ 'description' : 'set enc=...', \ 'candidates' : {}, \ 'map': function('UniteSourceMenuMenusMap'), \} for s:tmp in [ \ 'latin1', \ 'cp932', \ 'shift-jis', \ 'iso-2022-jp', \ 'euc-jp', \ 'utf-8', \ 'ucs-bom' \ ] call extend(g:unite_source_menu_menus.enc.candidates, \ {s:tmp : 'edit ++enc='.s:tmp}, \ 'error') endfor unlet s:tmp Map -silent [n] a :Unite menu:enc " }}} " set fenc=... {{{ let g:unite_source_menu_menus.fenc = { \ 'description' : 'set fenc=...', \ 'candidates' : {}, \ 'map': function('UniteSourceMenuMenusMap'), \} for s:tmp in [ \ 'latin1', \ 'cp932', \ 'shift-jis', \ 'iso-2022-jp', \ 'euc-jp', \ 'utf-8', \ 'ucs-bom' \ ] call extend(g:unite_source_menu_menus.fenc.candidates, \ {s:tmp : 'set fenc='.s:tmp}, \ 'error') endfor unlet s:tmp Map -silent [n] s :Unite menu:fenc " }}} " set ff=... {{{ let g:unite_source_menu_menus.ff = { \ 'description' : 'set ff=...', \ 'candidates' : {}, \ 'map': function('UniteSourceMenuMenusMap'), \} for s:tmp in ['dos', 'unix', 'mac'] call extend(g:unite_source_menu_menus.ff.candidates, \ {s:tmp : 'set ff='.s:tmp}, \ 'error') endfor unlet s:tmp Map -silent [n] d :Unite menu:ff " }}} " }}} MyAutocmd FileType unite call s:unite_settings() let g:unite_winheight = 5 " default winheight. let g:unite_winwidth = 10 " default winwidth. function! s:unite_settings() "{{{ Map -remap -buffer [i] (unite_delete_backward_path) Map -remap -buffer [n] (unite_toggle_mark_current_candidate) Map -remap -buffer [i] (expand_unite_window)(unite_select_next_line) Map -remap -buffer [i] (expand_unite_window)(unite_select_previous_line) endfunction "}}} " Expand current unite window width/height 2/3 Map -remap [i] (expand_unite_window) (unite_insert_leave)(expand_unite_window_fn)(unite_insert_enter) Map -silent [n] (expand_unite_window_fn) :call unite_resize_window(&columns / 3 * 2, &lines / 3 * 2) function! s:unite_resize_window(width, height) if winnr('$') is 1 return elseif g:unite_enable_split_vertically execute 'vertical resize' a:width else execute 'resize' a:height endif Map -remap -buffer [i] (unite_select_next_line) Map -remap -buffer [i] (unite_select_previous_line) endfunction endif " }}} " }}} if s:has_plugin('Gtags') " {{{ " for gtags. function! s:JumpTags() "{{{ if expand('%') == '' | return | endif if !exists(':GtagsCursor') echo "gtags.vim is not installed. do default ..." sleep 2 " unmap this function. " use plain next time. Map! [n] execute "normal! \" return endif let gtags = expand('%:h') . '/GTAGS' if filereadable(gtags) " use gtags if found GTAGS. lcd %:p:h GtagsCursor lcd - else " or use ctags. execute "normal! \" endif endfunction "}}} Map [n] :call JumpTags() endif " }}} if s:has_plugin('vimshell') " {{{ MapAlterCommand sh[ell] VimShell let g:vimshell_user_prompt = '"(" . getcwd() . ") --- (" . $USER . "@" . hostname() . ")"' let g:vimshell_prompt = '$ ' let g:vimshell_right_prompt = 'vimshell#vcs#info("(%s)-[%b]", "(%s)-[%b|%a]")' let g:vimshell_ignore_case = 1 let g:vimshell_smart_case = 1 MyAutocmd FileType vimshell call s:vimshell_settings() function! s:vimshell_settings() "{{{ call s:build_env_path() " No -bar command! \ -buffer -nargs=+ \ VimShellAlterCommand \ call vimshell#altercmd#define( \ tyru#util#parse_one_arg_from_q_args()[0], \ tyru#util#eat_n_args_from_q_args(, 1) \ ) " Alias VimShellAlterCommand vi vim VimShellAlterCommand df df -h VimShellAlterCommand diff diff --unified VimShellAlterCommand du du -h VimShellAlterCommand free free -m -l -t VimShellAlterCommand j jobs -l VimShellAlterCommand jobs jobs -l VimShellAlterCommand ll ls -lh VimShellAlterCommand l ll VimShellAlterCommand la ls -A VimShellAlterCommand less less -r VimShellAlterCommand sc screen VimShellAlterCommand whi which VimShellAlterCommand whe where VimShellAlterCommand go gopen " VimShellAlterCommand l. ls -d .* call vimshell#set_alias('l.', 'ls -d .*') " Abbrev inoreabbrev l@ less inoreabbrev g@ grep inoreabbrev p@ perl inoreabbrev s@ sort inoreabbrev u@ sort -u inoreabbrev c@ xsel --input --clipboard inoreabbrev x@ xargs --no-run-if-empty inoreabbrev n@ >/dev/null 2>/dev/null inoreabbrev e@ 2>&1 inoreabbrev h@ --help 2>&1 less inoreabbrev H@ --help 2>&1 if executable('perldocjp') VimShellAlterCommand perldoc perldocjp endif let less_sh = s:Vital.globpath(&rtp, 'macros/less.sh') if !empty(less_sh) call vimshell#altercmd#define('vless', less_sh[0]) endif " Hook call vimshell#hook#set('chpwd', [s:SNR('vimshell_chpwd_ls')]) call vimshell#hook#set('preexec', [s:SNR('vimshell_preexec_iexe')]) " call vimshell#hook#set('preexec', [s:SNR('vimshell_preexec_less')]) " Add/Remove some mappings. Map! [n] -buffer Map! [n] -buffer Map! [i] -buffer Map -buffer -remap [i] -force (vimshell_command_complete) Map -buffer -remap [n] (vimshell_switch) Map -buffer -remap [i] r (vimshell_history_complete_whole) " Misc. setlocal backspace-=eol setlocal updatetime=1000 setlocal nowrap if 0 if !exists(':NeoComplCacheDisable') NeoComplCacheEnable endif NeoComplCacheAutoCompletionLength 1 NeoComplCacheUnlock augroup vimrc-vimshell-settings autocmd! autocmd TabEnter NeoComplCacheUnlock autocmd TabLeave NeoComplCacheLock augroup END endif endfunction "}}} function! s:vimshell_chpwd_ls(args, context) "{{{ call vimshell#execute('ls') endfunction "}}} function! s:vimshell_preexec_iexe(cmdline, context) "{{{ return s:vimshell_preexec_command( \ 'iexe', \ [ \ 'termtter', \ 'sudo', \ ['git', 'add', '-p'], \ ['git', 'log'], \ ['git', 'view'], \ 'earthquake', \ ], \ a:cmdline, \ a:context, \) endfunction "}}} function! s:vimshell_preexec_less(cmdline, context) "{{{ return s:vimshell_preexec_command( \ 'less', \ [ \ ['git', 'log'], \ ['git', 'view'], \ ], \ a:cmdline, \ a:context, \) endfunction "}}} function! s:vimshell_preexec_command(command, patlist, cmdline, context) let args = vimproc#parser#split_args(a:cmdline) if empty(args) return a:cmdline endif if args[0] ==# a:command return a:cmdline endif for i in a:patlist let list_match = type(i) == type([]) && i ==# args[:len(i)-1] let string_match = type(i) == type("") && args[0] ==# i if list_match || string_match return a:command . ' ' . a:cmdline endif unlet i endfor return a:cmdline endfunction let s:has_built_path = 0 function! s:build_env_path() "{{{ if s:has_built_path return endif let s:has_built_path = 1 " build $PATH if vim started w/o shell. " XXX: :gui let $PATH = system(s:is_win ? 'echo %path%' : 'echo $PATH') endfunction "}}} endif " }}} if s:has_plugin('quickrun') " {{{ let g:loaded_quicklaunch = 1 let g:quickrun_no_default_key_mappings = 1 Map -remap [nvo] r (quickrun) if has('vim_starting') let g:quickrun_config = {} let g:quickrun_config['*'] = {'split': 'vertical rightbelow'} if executable('pandoc') let g:quickrun_config['markdown'] = {'command' : 'pandoc'} endif let g:quickrun_config['lisp'] = { \ 'command': 'clisp', \ 'eval': 1, \ 'eval_template': '(print %s)', \} function! s:build_quickrun_config_cpp0x() if !executable('g++') return endif let g:quickrun_config['cpp0x'] = deepcopy(g:quickrun#default_config['cpp']) let g:quickrun_config['cpp0x'].command = 'g++ --std=c++0x' endfunction Lazy call s:build_quickrun_config_cpp0x() endif endif " }}} if s:has_plugin('submode') "{{{ " Move GUI window. call submode#enter_with('guiwinmove', 'n', '', 'mgw') call submode#leave_with('guiwinmove', 'n', '', '') call submode#map ('guiwinmove', 'n', 'r', 'j', '(winmove-down)') call submode#map ('guiwinmove', 'n', 'r', 'k', '(winmove-up)') call submode#map ('guiwinmove', 'n', 'r', 'h', '(winmove-left)') call submode#map ('guiwinmove', 'n', 'r', 'l', '(winmove-right)') " Change GUI window size. call submode#enter_with('guiwinsize', 'n', '', 'mgs', '') call submode#leave_with('guiwinsize', 'n', '', '') call submode#map ('guiwinsize', 'n', '', 'j', ':set lines+=1') call submode#map ('guiwinsize', 'n', '', 'k', ':set lines-=1') call submode#map ('guiwinsize', 'n', '', 'h', ':set columns-=5') call submode#map ('guiwinsize', 'n', '', 'l', ':set columns+=5') " Change current window size. call submode#enter_with('winsize', 'n', '', 'mws', ':call VimrcSubmodeResizeWindow()') call submode#leave_with('winsize', 'n', '', '') " TODO or FIXME: submode#leave_with() can't do that. " call submode#leave_with('winsize', 'n', '', '', ':call VimrcSubmodeResizeWindowRestore()') function! VimrcSubmodeResizeWindow() let curwin = winnr() wincmd j | let target1 = winnr() | exe curwin "wincmd w" wincmd l | let target2 = winnr() | exe curwin "wincmd w" execute printf("call submode#map ('winsize', 'n', 'r', 'j', '%s')", curwin == target1 ? "-" : "+") execute printf("call submode#map ('winsize', 'n', 'r', 'k', '%s')", curwin == target1 ? "+" : "-") execute printf("call submode#map ('winsize', 'n', 'r', 'h', '%s')", curwin == target2 ? ">" : "<") execute printf("call submode#map ('winsize', 'n', 'r', 'l', '%s')", curwin == target2 ? "<" : ">") endfunction " function! VimrcSubmodeResizeWindowRestore() " if exists('s:submode_save_lazyredraw') " let &l:lazyredraw = s:submode_save_lazyredraw " unlet s:submode_save_lazyredraw " endif " endfunction " undo/redo call submode#enter_with('undo/redo', 'n', '', 'g-', 'g-') call submode#enter_with('undo/redo', 'n', '', 'g+', 'g+') call submode#leave_with('undo/redo', 'n', '', '') call submode#map ('undo/redo', 'n', '', '-', 'g-') call submode#map ('undo/redo', 'n', '', '+', 'g+') " Tab walker. call submode#enter_with('tabwalker', 'n', '', 'mt', '') call submode#leave_with('tabwalker', 'n', '', '') call submode#map ('tabwalker', 'n', '', 'h', 'gT') call submode#map ('tabwalker', 'n', '', 'l', 'gt') call submode#map ('tabwalker', 'n', '', 'H', ':execute "tabmove" tabpagenr() - 2') call submode#map ('tabwalker', 'n', '', 'L', ':execute "tabmove" tabpagenr()') " FIXME: Weird character is showed. " call submode#enter_with('indent/dedent', 'i', '', '', '') " call submode#enter_with('indent/dedent', 'i', '', '', '') " call submode#leave_with('indent/dedent', 'i', '', '') " call submode#map ('indent/dedent', 'i', '', 'h', '') " call submode#map ('indent/dedent', 'i', '', 'l', '') " Scroll by j and k. " TODO Stash &scroll value. " TODO Make utility function to generate current shortest map. call submode#enter_with('scroll', 'n', '', 'gj', '') call submode#enter_with('scroll', 'n', '', 'gk', '') call submode#leave_with('scroll', 'n', '', '') call submode#map ('scroll', 'n', '', 'j', '') call submode#map ('scroll', 'n', '', 'k', '') call submode#map ('scroll', 'n', '', 'a', ':let &l:scroll -= 3') call submode#map ('scroll', 'n', '', 's', ':let &l:scroll += 3') endif "}}} if s:has_plugin('ref') " {{{ " 'K' for ':Ref'. MapAlterCommand ref Ref MapAlterCommand alc Ref -new alc MapAlterCommand rfc Ref -new rfc MapAlterCommand man Ref -new man MapAlterCommand pdoc Ref -new perldoc MapAlterCommand cppref Ref -new cppref MapAlterCommand cpp Ref -new cppref MapAlterCommand py[doc] Ref -new pydoc Map [n] K K let g:ref_use_vimproc = 0 let g:ref_open = 'belowright vsplit' if executable('perldocjp') let g:ref_perldoc_cmd = 'perldocjp' endif endif " }}} if s:has_plugin('vimfiler') " {{{ let g:vimfiler_as_default_explorer = 1 let g:vimfiler_safe_mode_by_default = 0 let g:vimfiler_split_command = 'aboveleft split' if executable('trash-put') let g:vimfiler_external_delete_command = 'trash-put $srcs' endif MyAutocmd FileType vimfiler call s:vimfiler_settings() function! s:vimfiler_settings() "{{{ Map -buffer -remap [n] L (vimfiler_move_to_history_forward) Map -buffer -remap [n] H (vimfiler_move_to_history_back) Map -buffer -remap [n] (vimfiler_move_to_history_back) Map -buffer -remap [n] (vimfiler_move_to_history_forward) " TODO " Map! [n] -buffer N j k Map! [n] -buffer N Map! [n] -buffer j Map! [n] -buffer k Map! [n] -buffer ? " dd as (vimfiler_force_delete_file) " because I want to use trash-put. Map! [n] -buffer d Map -remap -buffer [n] dd (vimfiler_force_delete_file) Map -remap -buffer [n] (vimfiler_toggle_mark_current_line) endfunction "}}} endif " }}} if s:has_plugin('prettyprint') " {{{ MapAlterCommand pp PP let g:prettyprint_show_expression = 1 endif " }}} if s:has_plugin('lingr') " {{{ " from thinca's .vimrc {{{ " http://soralabo.net/s/vrcb/s/thinca if !exists('g:lingr') call rtputil#remove('\') endif if 0 " Update GNU screen tab name. augroup vimrc-plugin-lingr autocmd! autocmd User plugin-lingr-* call s:lingr_event( \ matchstr(expand(''), 'plugin-lingr-\zs\w*')) autocmd FileType lingr-* call s:init_lingr(expand('')) augroup END function! s:lingr_ctrl_l() "{{{ call lingr#mark_as_read_current_room() call s:screen_auto_window_name() redraw! endfunction "}}} function! s:init_lingr(ft) "{{{ if exists('s:screen_is_running') Map -silent -buffer [n] :call lingr_ctrl_l() let b:window_name = 'lingr' endif endfunction "}}} function! s:lingr_event(event) "{{{ if a:event ==# 'message' && s:screen_is_running execute printf('WindowName %s(%d)', 'lingr', lingr#unread_count()) endif endfunction "}}} endif " Update GNU screen tab name. " }}} MyAutocmd FileType lingr-messages \ call s:lingr_messages_mappings() function! s:lingr_messages_mappings() "{{{ Map -remap -buffer [n] o (lingr-messages-show-say-buffer) Map -buffer [n] gt Map -buffer [n] gT endfunction "}}} MyAutocmd FileType lingr-say \ call s:lingr_say_mappings() function! s:lingr_say_mappings() "{{{ Map -remap -buffer [n] (lingr-say-say) endfunction "}}} Map -silent [n] (lingr-say-say) :call lingr_say_say() function! s:lingr_say_say() "{{{ let all_lines = getline(1, '$') let blank_line = '^\s*$' call filter(all_lines, 'v:val =~# blank_line') if empty(all_lines) " has blank line(s). let doit = 1 else let doit = input('lingr-say buffer has one or more blank lines. say it?[y/n]:') =~? '^y\%[es]' endif if doit execute "normal \(lingr-say-say)" endif endfunction "}}} let g:lingr_vim_user = 'tyru' let g:lingr_vim_additional_rooms = [ \ 'tyru', \ 'vim', \ 'emacs', \ 'editor', \ 'vim_users_en', \ 'vimperator', \ 'filer', \ 'completion', \ 'shell', \ 'git', \ 'termtter', \ 'lingr', \ 'ruby', \ 'few', \ 'gc', \ 'scala', \ 'lowlevel', \ 'lingr_vim', \ 'vimjolts', \ 'gentoo', \ 'LinuxKernel', \] let g:lingr_vim_rooms_buffer_height = len(g:lingr_vim_additional_rooms) + 3 let g:lingr_vim_count_unread_at_current_room = 1 endif " }}} if s:has_plugin('chalice') " {{{ if !exists('g:chalice') call rtputil#remove('\') endif endif " }}} if s:has_plugin('github') " {{{ MapAlterCommand gh Github MapAlterCommand ghi Github issues endif " }}} if s:has_plugin('neocomplcache') "{{{ let g:neocomplcache_enable_at_startup = 1 let g:neocomplcache_disable_caching_file_path_pattern = '.*' let g:neocomplcache_enable_ignore_case = 1 let g:neocomplcache_enable_underbar_completion = 1 let g:neocomplcache_enable_camel_case_completion = 1 let g:neocomplcache_auto_completion_start_length = 3 Map [n] neo :NeoComplCacheToggle " http://d.hatena.ne.jp/basyura/20120318/p1 MyAutocmd InsertEnter * call s:neco_pre_cache() function! s:neco_pre_cache() if exists('b:neco_pre_cache') return endif let b:neco_pre_cache = 1 if bufname('%') =~ g:neocomplcache_lock_buffer_name_pattern return endif NeoComplCacheCachingBuffer NeoComplCacheCachingDictionary endfunction endif "}}} if s:has_plugin('EasyGrep') " {{{ let g:EasyGrepCommand = 2 let g:EasyGrepInvertWholeWord = 1 endif " }}} if s:has_plugin('gist') "{{{ let g:gist_detect_filetype = 1 let g:gist_open_browser_after_post = 1 let g:gist_browser_command = ":OpenBrowser %URL%" endif "}}} if s:has_plugin('ohmygrep') " {{{ MapAlterCommand gr[ep] OMGrep MapAlterCommand re[place] OMReplace Map -remap [n] gw (omg-grep-cword) Map -remap [n] gW (omg-grep-cWORD) endif " }}} if s:has_plugin('detect-coding-style') " {{{ MyAutocmd User dcs-initialized-styles call s:dcs_register_own_styles() function! s:dcs_register_own_styles() call dcs#register_style('My style', {'hook_excmd': 'setlocal expandtab tabstop=4 shiftwidth=4 softtabstop&'}) call dcs#register_style('Short indent', {'hook_excmd': 'setlocal expandtab tabstop=2 shiftwidth=2 softtabstop&'}) endfunction endif " }}} if s:has_plugin('autocmd-tabclose') " {{{ " :tabprevious on vimrc-tabclose function! s:tabclose_post() if tabpagenr() != 1 " XXX: Doing :tabprevious here cause Vim behavior strange " Decho ':tabprevious' endif endfunction MyAutocmd User tabclose-post call s:tabclose_post() endif " }}} if s:has_plugin('simpletap') " {{{ let g:simpletap#open_command = 'botright vnew' endif " }}} if s:has_plugin('fontzoom') " {{{ let loaded_fontzoom = 1 endif " }}} if s:has_plugin('ftplugin/vim_fold.vim') " {{{ augroup foldmethod-expr autocmd! autocmd InsertEnter * if &l:foldmethod ==# 'expr' \ | let b:foldinfo = [&l:foldmethod, &l:foldexpr] \ | setlocal foldmethod=manual foldexpr=0 \ | endif autocmd InsertLeave * if exists('b:foldmethod') \ | let [&l:foldmethod, &l:foldexpr] = b:foldinfo \ | endif augroup END endif " }}} if s:has_plugin('GraVit') " {{{ " XXX: 2012-09-17 19:48: syntax/vim.vim wrong highlight... " Map -remap [nvo] g/ gravit->forward " Map -remap [nvo] g? gravit->backward " highlight GraVitCurrentMatch term=underline cterm=underline gui=underline ctermfg=4 guifg=Purple endif " }}} if s:has_plugin('hatena.vim') " {{{ let g:hatena_no_default_keymappings = 1 let g:hatena_user = 'tyru' let g:hatena_upload_on_write = 0 endif " }}} if s:has_plugin('fileutils') " {{{ call fileutils#load('noprefix') MapAlterCommand rm Delete MapAlterCommand del[ete] Delete MapAlterCommand mv Rename MapAlterCommand ren[ame] Rename MapAlterCommand mkd[ir] Mkdir MapAlterCommand mkc[d] Mkcd endif "}}} if s:has_plugin('watchdogs') " {{{ if has('vim_starting') call watchdogs#setup(g:quickrun_config) endif let g:watchdogs_check_BufWritePost_enable = 1 endif "}}} if s:has_plugin('hier') " {{{ function! s:quickfix_is_target() " let buftype = getbufvar(expand(''), '&buftype') let winnr = bufwinnr(expand('')) let buftype = getwinvar(winnr, '&buftype') " Dump [winnr, buftype] return buftype ==# 'quickfix' endfunction function! s:stop_hier_on_quickfix_close() if s:quickfix_is_target() || !s:quickfix_exists_window() HierStop endif endfunction function! s:start_hier_on_quickfix_open() if s:quickfix_is_target() || s:quickfix_exists_window() HierStart endif endfunction MyAutocmd BufWinLeave,BufDelete,BufUnload,BufWipeout * \ call s:stop_hier_on_quickfix_close() MyAutocmd QuickFixCmdPost * \ call s:start_hier_on_quickfix_open() function! s:check_auto_commands(evname) " disable if 1 | return | endif echom a:evname.': = '.expand('').', = '.expand('').', = '.expand('') Dump bufexists(expand('')) let winnr = s:quickfix_get_winnr() Dump [getbufvar(expand(''), '&buftype'), winnr, getwinvar(winnr, '&buftype')] let quickfix_is_target = s:quickfix_is_target() let quickfix_exists_window = s:quickfix_exists_window() Dump [quickfix_is_target, quickfix_exists_window] endfunction for s:tmp in [ \ 'BufWinLeave', \ 'BufUnload', \ 'BufDelete', \ 'BufWipeout', \] execute 'MyAutocmd '.s:tmp.' * call s:check_auto_commands('.string(s:tmp).')' endfor unlet s:tmp endif "}}} " test let g:loaded_tyru_event_test = 1 " runtime if s:has_plugin('netrw') " {{{ function! s:filetype_netrw() "{{{ Map -remap -buffer [n] h - Map -remap -buffer [n] l Map -remap -buffer [n] e endfunction "}}} MyAutocmd FileType netrw call s:filetype_netrw() endif " }}} if s:has_plugin('indent/vim.vim') " {{{ let g:vim_indent_cont = 0 endif " }}} if s:has_plugin('changelog') " {{{ let changelog_username = "tyru" endif " }}} if s:has_plugin('syntax/sh.vim') " {{{ let g:is_bash = 1 endif " }}} if s:has_plugin('syntax/scheme.vim') " {{{ let g:is_gauche = 1 endif " }}} if s:has_plugin('syntax/perl.vim') " {{{ " POD highlighting let g:perl_include_pod = 1 " Fold only sub, __END__, < one_day_sec let backup_files = split(expand(&backupdir . '/*'), "\n") let thirty_days_sec = one_day_sec * 30 call filter(backup_files, 'localtime() - getftime(v:val) > thirty_days_sec') for i in backup_files if delete(i) != 0 call s:warn("can't delete " . i) endif endfor call writefile([localtime()], stamp_file) endif endfunction call s:delete_backup() " }}} " }}} " Misc. (bundled with kaoriya vim's .vimrc & etc.) {{{ " Do not load menu {{{ let did_install_default_menus = 1 " }}} " About japanese input method {{{ if has('multi_byte_ime') || has('xim') " Cursor color when IME is on. highlight CursorIM guibg=Purple guifg=NONE set iminsert=0 imsearch=0 endif " }}} " GNU Screen, Tmux {{{ " " from thinca's .vimrc " http://soralabo.net/s/vrcb/s/thinca if $WINDOW != '' || $TMUX != '' let s:screen_is_running = 1 " Use a mouse in screen. if has('mouse') set ttymouse=xterm2 endif function! s:screen_set_window_name(name) let esc = "\" silent! execute '!echo -n "' . esc . 'k' . escape(a:name, '%#!') \ . esc . '\\"' redraw! endfunction command! -bar -nargs=? WindowName call s:screen_set_window_name() function! s:screen_auto_window_name() let varname = 'window_name' for scope in [w:, b:, t:, g:] if has_key(scope, varname) call s:screen_set_window_name(scope[varname]) return endif endfor if bufname('%') !~ '^\[A-Za-z0-9\]*:/' call s:screen_set_window_name('vim:' . expand('%:t')) endif endfunction if 0 augroup vimrc-screen autocmd! autocmd VimEnter * call s:screen_set_window_name(0 < argc() ? \ 'vim:' . fnamemodify(argv(0), ':t') : 'vim') autocmd BufEnter,BufFilePost * call s:screen_auto_window_name() autocmd VimLeave * call s:screen_set_window_name(len($SHELL) ? \ fnamemodify($SHELL, ':t') : 'shell') augroup END endif endif " }}} " own-highlight {{{ " TODO: Plugin-ize augroup own-highlight autocmd! augroup END function! s:register_highlight(hi, hiarg, pat) execute 'highlight' a:hiarg call s:add_pattern(a:hi, a:pat) endfunction function! s:add_pattern(hi, pat) " matchadd() will throw an error " when a:hi is not defined. if !hlexists(a:hi) return endif if !exists('w:did_pattern') let w:did_pattern = {} endif if !has_key(w:did_pattern, a:hi) call matchadd(a:hi, a:pat) let w:did_pattern[a:hi] = 1 endif endfunction function! s:register_own_highlight() " I found that I'm very nervous about whitespaces. " so I'd better think about this. " This settings just notice its presence. for [hi, hiarg, pat] in [ \ ['IdeographicSpace', \ 'IdeographicSpace term=underline cterm=underline gui=underline ctermfg=4 guifg=Cyan', \ ' '], \ ['WhitespaceEOL', \ 'WhitespaceEOL term=underline cterm=underline gui=underline ctermfg=4 guifg=Cyan', \ ' \+$'], \] " TODO: filetype execute \ 'autocmd own-highlight Colorscheme *' \ 'call s:register_highlight(' \ string(hi) ',' string(hiarg) ',' string(pat) \ ')' execute \ 'autocmd own-highlight VimEnter,WinEnter *' \ 'call s:add_pattern(' \ string(hi) ',' string(pat) \ ')' endfor endfunction call s:register_own_highlight() " }}} " }}} " End. {{{ set secure " }}}