" Section: Options {{{1 set nocompatible let s:iswin = has('win32') || has('win64') filetype off set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " Bundle/Vundle {{{2 Plugin 'gmarik/Vundle.vim' Plugin 'fatih/vim-go' Plugin 'mattn/emmet-vim' Plugin 'https://github.com/myhere/vim-nodejs-complete.git' Plugin 'https://github.com/Valloric/YouCompleteMe.git' Plugin 'https://github.com/b4winckler/vim-objc.git' Plugin 'https://github.com/altercation/vim-colors-solarized.git' Plugin 'git://github.com/tyru/operator-camelize.vim.git' Plugin 'git://github.com/myusuf3/numbers.vim.git' Plugin 'https://github.com/Lokaltog/vim-easymotion.git' Plugin 'https://github.com/nono/vim-handlebars.git' Plugin 'https://github.com/sjl/vitality.vim.git' Plugin 'https://github.com/kana/vim-tabpagecd.git' Plugin 'https://github.com/michaeljsmith/vim-indent-object.git' Plugin 'https://github.com/the-isz/MinYankRing.vim.git', {'v': 'events'} Plugin 'https://github.com/kana/vim-smartinput.git' Plugin 'https://github.com/Raimondi/vim_search_objects.git' Plugin 'https://github.com/kana/vim-gf-diff.git' Plugin 'https://github.com/kana/vim-gf-user.git' Plugin 'https://github.com/kana/vim-textobj-line.git' Plugin 'https://github.com/groenewege/vim-less.git' Plugin 'https://github.com/tpope/vim-eunuch.git' Plugin 'https://github.com/tyru/current-func-info.vim.git' Plugin 'https://github.com/digitaltoad/vim-jade.git' Plugin 'https://github.com/juvenn/mustache.vim.git' Plugin 'https://github.com/tpope/vim-markdown.git' Plugin 'https://github.com/mattn/sonictemplate-vim.git' Plugin 'https://github.com/tyru/open-browser.vim.git' Plugin 'https://github.com/mattn/webapi-vim.git' Plugin 'https://github.com/gregsexton/MatchTag.git' Plugin 'https://github.com/thinca/vim-ref.git' Plugin 'https://github.com/ujihisa/quicklearn.git' Plugin 'https://github.com/vim-scripts/ReplaceWithRegister.git' Plugin 'https://github.com/timcharper/textile.vim.git' Plugin 'https://github.com/vim-scripts/AnsiEsc.vim.git' Plugin 'https://github.com/Shougo/unite-build.git' Plugin 'https://github.com/h1mesuke/unite-outline.git' Plugin 'https://github.com/tsukkee/unite-tag.git' Plugin 'https://github.com/majutsushi/tagbar.git' Plugin 'git@github.com:travisjeffery/vim-extradite.git' Plugin 'https://github.com/kchmck/vim-coffee-script.git' Plugin 'git://github.com/Shougo/vim-vcs.git' Plugin 'https://github.com/vim-scripts/Align.git' Plugin 'https://github.com/thinca/vim-github.git' Plugin 'https://github.com/lukaszb/vim-web-indent.git' Plugin 'https://github.com/pangloss/vim-javascript.git' Plugin 'https://github.com/thinca/vim-qfreplace.git' Plugin 'https://github.com/h1mesuke/vim-alignta.git' Plugin 'https://github.com/kien/ctrlp.vim.git' Plugin 'https://github.com/kana/vim-altr.git' Plugin 'git@github.com:travisjeffery/IndexedSearch.git' Plugin 'https://github.com/mileszs/ack.vim.git' Plugin 'https://github.com/vim-scripts/bufkill.vim.git' Plugin 'https://github.com/duff/vim-bufonly.git' Plugin 'https://github.com/tpope/vim-fugitive.git' Plugin 'https://github.com/sjl/gundo.vim.git' Plugin 'https://github.com/travisjeffery/vim-help' Plugin 'https://github.com/tpope/vim-ragtag.git' Plugin 'https://github.com/tpope/vim-repeat.git' Plugin 'https://github.com/tpope/vim-surround.git' Plugin 'https://github.com/kana/vim-textobj-entire.git' Plugin 'https://github.com/kana/vim-textobj-function.git' Plugin 'https://github.com/thinca/vim-textobj-comment.git' Plugin 'https://github.com/kana/vim-textobj-diff.git' Plugin 'https://github.com/kana/vim-textobj-lastpat.git' Plugin 'https://github.com/nelstrom/vim-textobj-rubyblock.git' Plugin 'https://github.com/kana/vim-textobj-user.git' Plugin 'https://github.com/kana/vim-smartword.git' Plugin 'git@github.com:travisjeffery/vim-unimpaired.git' Plugin 'https://github.com/jgdavey/vim-blockle.git' Plugin 'https://github.com/kana/vim-grex.git' Plugin 'https://github.com/kana/vim-operator-user.git' Plugin 'https://github.com/Shougo/unite.vim.git' Plugin 'https://github.com/kana/vim-altercmd.git' Plugin 'https://github.com/kana/vim-operator-replace.git' Plugin 'https://github.com/tpope/vim-commentary.git' Plugin 'https://github.com/vim-ruby/vim-ruby.git' Plugin 'https://github.com/tpope/vim-rake.git' Plugin 'https://github.com/tpope/vim-bundler.git' Plugin 'https://github.com/thinca/vim-quickrun.git' Plugin 'https://github.com/kana/vim-exjumplist.git' Plugin 'https://github.com/thinca/vim-unite-history.git' Plugin 'https://github.com/Shougo/echodoc.git' Plugin 'https://github.com/mattn/gist-vim.git' Plugin 'https://github.com/kana/vim-scratch.git' Plugin 'https://github.com/scrooloose/syntastic.git' call vundle#end() "}}} filetype plugin indent on augroup MyAutoCmd autocmd! augroup END filetype on syntax on set noantialias set lazyredraw set number set autowrite set autowriteall set cmdheight=2 set backspace=indent,eol,start set history=1000 set nostartofline set splitbelow set splitright set previewheight=10 set helpheight=12 set noequalalways set pumheight=20 set showfulltag set cscopetag if has('quickfix') set cscopequickfix=s-,c-,d-,i-,t-,e- endif set cscopeverbose set cmdwinheight=5 set ruler set showcmd set showmode set incsearch set mousemodel=popup set smartcase set hlsearch set nowrap set linebreak if exists('+fuoptions') set fuoptions=maxhorz,maxvert endif if exists('+guicursor') set guicursor& set guicursor=a:blinkwait4000-blinkon1500-blinkoff500 endif if exists('+macmeta') set macmeta endif " set winwidth=84 " set winheight=5 " set winminheight=5 " set winheight=999 set undodir=~/.tmp set undofile set undolevels=1000 set undoreload=10000 if !isdirectory($HOME . "/.tmp") call mkdir($HOME . "/.tmp", 'p') endif set backupdir=~/.tmp set directory=~/.tmp set backup set shiftwidth=2 set softtabstop=2 set expandtab set autoindent set wildmode=list:longest set wildmenu set wildignore=*.o,*.obj,*~,_site,.git,.svn,*.xcodeproj,*.pyc,tmp,node_modules set virtualedit=block set matchpairs+=<:> set autoread set iskeyword+=- set iskeyword+=_ if v:version >= 600 set foldenable set foldlevelstart=1 set foldlevel=1 set foldmethod=marker set foldopen=block,insert,jump,mark,percent,quickfix,search,tag,undo set printoptions=paper:letter set sidescrolloff=5 set sidescroll=1 set mouse=nvi endif set nolist if (&termencoding ==# 'utf-8' || &encoding ==# 'utf-8') && version >= 700 let &listchars = "tab:\u21e5\u00b7,trail:\u2423,extends:\u21c9,precedes:\u21c7,nbsp:\u26ad" else set listchars=tab:>\ ,trail:-,extends:>,precedes:< endif set formatoptions-=o " tabline{{{2 set showtabline=2 set tabline=%!MyTabLine() function! MyTabLine() let s = '' for t in range(tabpagenr('$')) if t + 1 == tabpagenr() let s .= '%#TabLineSel#' else let s .= '%#TabLine#' endif let s .= ' ' let s .= '%' . (t + 1) . 'T' let s .= t + 1 . ' ' let n = '' let m = 0 let bc = len(tabpagebuflist(t + 1)) for b in tabpagebuflist(t + 1) if getbufvar( b, "&buftype" ) == 'help' let n .= '[H]' . fnamemodify( bufname(b), ':t:s/.txt$//' ) elseif getbufvar( b, "&buftype" ) == 'quickfix' let n .= '[Q]' else let n .= pathshorten(bufname(b)) endif if getbufvar( b, "&modified" ) let m += 1 endif if bc > 1 let n .= ' ' endif let bc -= 1 endfor if m > 0 let s.= '+ ' endif if n == '' let s .= '[No Name]' else let s .= n endif let s .= ' ' endfor let s .= '%#TabLineFill#%T' if tabpagenr('$') > 1 let s .= '%=%#TabLine#%999XX' endif return s endfunction"}}}2 " scroll "{{{2 set scroll=5 set scrolloff=0 let g:scrolloff = 15 autocmd 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 "}}}2 " Automatically mkdir when writing file in non-existant directory{{{2 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"}}}2 set mouse=a set ttymouse=xterm2 set t_Co=256 set hidden set textwidth=79 set ignorecase set dictionary-=/usr/share/dict/words dictionary+=/usr/share/dict/words set complete-=k set complete-=i set fileformats=unix,dos,mac set cursorline set relativenumber au BufReadPost * set relativenumber au BufEnter /private/tmp/crontab.* setl backupcopy=yes set timeoutlen=1000 set ttimeoutlen=50 set laststatus=2 set diffopt=filler set diffopt+=iwhite set switchbuf=useopen set noswapfile set updatecount=0 set updatetime=50 set showmatch " let loaded_matchparen = 1 set matchtime=1 if has('unix') set nofsync set swapsync= endif set guioptions-=T set guioptions-=L set guioptions-=r set guioptions+=c set noantialias if has('balloon_eval') autocmd FileType ruby,eruby set noballooneval set noballooneval endif set norestorescreen set t_ti= set t_te= set shortmess=filtIoOA set report=0 set grepprg=ag if has("mac") set clipboard=unnamed let g:gist_clip_command = 'pbcopy' else let g:gist_clip_command = 'xclip -selection clipboard' endif if has("gui") && has("mac") set fuopt+=maxhorz set macmeta set antialias set guifont=Monaco:h10 else set guifont=Monaco\ 10 endif if &term =~ "^screen" augroup MyAutoCmd autocmd VimLeave * :set mouse= augroup END " workaround for freeze when using mouse on GNU screen. set ttymouse=xterm2 endif call cfi#load() set statusline=%f set statusline+=%{exists('g:loaded_fugitive')?fugitive#statusline():''} set statusline+=%{exists('g:loaded_rvm')?rvm#statusline():''} set statusline+=%#warningmsg# set statusline+=%{(cfi#get_func_name()!='')?'['.cfi#get_func_name().']':''} set statusline+=%{&ff!='unix'?'['.&ff.']':''} set statusline+=%* set statusline+=%#warningmsg# set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''} set statusline+=%* set statusline+=%h set statusline+=%y set statusline+=%r set statusline+=%m set statusline+=%#error# set statusline+=%* set statusline+=%#warningmsg# set statusline+=%{exists('g:loaded_syntastic_plugin')?SyntasticStatuslineFlag():''} set statusline+=%* set statusline+=%#error# set statusline+=%{&paste?'[paste]':''} set statusline+=%* set statusline+=%= set statusline+=%c, set statusline+=%l/%L set statusline+=\ %{GetDocumentPosition()} function! GetDocumentPosition() return float2nr(str2float(line('.')) / str2float(line('$')) * 100) . "%" endfunction autocmd MyAutoCmd FileType * setl formatoptions-=ro | setl formatoptions+=mM autocmd MyAutoCmd BufWritePost vimrc source $MYVIMRC autocmd MyAutoCmd BufWritePost .vimrc source $MYVIMRC function! AddInstanceVariablesForArguments() let @a = "" execute 'normal! "ayib' if @a == "" " handle method definitions without parenthsis execute 'normal! ^2wv$h"ay' end let argsstr = @a let argsstr = substitute(argsstr, "^def \k*", "", "g") let argsstr = substitute(argsstr, " ", "", "g") let argslist = split(argsstr, ",") let l = line('.') let argslist = map(argslist, '"@" . argslist[v:key] . " = " . argslist[v:key]') call append(l, argslist) execute "normal jV" . len(argslist) . "j=" endfunction autocmd FileType ruby,eruby \ nnoremap rg :call AddInstanceVariablesForArguments() function! Buffers() let tablist = [] for i in range(tabpagenr('$')) call extend(tablist, tabpagebuflist(i + 1)) endfor return tablist endfunction function! BufferNames() let buffers = [] for i in range(tabpagenr('$')) call extend(buffers, tabpagebuflist(i + 1)) endfor let buffer_names = [] for i in buffers let buffer_names = buffer_names + [bufname(i)] endfor return buffer_names endfunction function! GrepBuffers(pattern) let last_bufno = bufnr("$") let i = 1 let filenames = "" while i <= last_bufno if bufexists(i) && buflisted(i) let filenames = filenames . " " . bufname(i) endif let i = i + 1 endwhile " No buffers if filenames == "" return endif execute "vimgrep /" . a:pattern . "/ " . filenames . " | cw" endfunction command! -nargs=1 GrepBuffers call GrepBuffers() " Close help and git window by pressing q. autocmd FileType fugitiveblame,help,git-status,git-log,qf,gitcommit,quickrun,qfreplace,ref,simpletap-summary,vcs-commit,vcs-status \ nnoremap q :call smart_close() autocmd FileType * if (&readonly || !&modifiable) && !hasmapto('q', 'n') \ | nnoremap q :call smart_close()| endif function! s:smart_close() if winnr('$') != 1 close endif endfunction augroup MyAutoCmd autocmd FileType vim nnoremap [Space]so :write :source % echo "source " . bufname('%') if v:version >= 700 && isdirectory(expand("~/.trash")) autocmd BufWritePre,BufWritePost * if exists("s:backupdir") | set backupext=~ | let &backupdir = s:backupdir | unlet s:backupdir | endif autocmd BufWritePre ~/* \ let s:path = expand("~/.trash").strpart(expand(":p:~:h"),1) | \ if !isdirectory(s:path) | call mkdir(s:path,"p") | endif | \ let s:backupdir = &backupdir | \ let &backupdir = escape(s:path,'\,').','.&backupdir | \ let &backupext = strftime(".%Y%m%d%H%M%S~",getftime(expand(":p"))) endif autocmd CursorHold,BufWritePost,BufReadPost,BufLeave * \ if isdirectory(expand(":h")) | let &swapfile = &modified | endif autocmd FileType vim setlocal ai et sta sw=2 sts=2 keywordprg=:help augroup END " Make a scratch buffer when unnamed buffer{{{2 augroup vimrc-scratch-buffer autocmd! autocmd BufEnter * call s:scratch_buffer() autocmd FileType qfreplace autocmd! vimrc-scratch * function! s:scratch_buffer() if exists('b:scratch_buffer') || bufname('%') != '' || &l:buftype != '' return endif let b:scratch_buffer = 1 setlocal buftype=nofile nobuflisted noswapfile bufhidden=hide augroup vimrc-scratch autocmd! * autocmd BufWriteCmd call s:scratch_on_BufWriteCmd() augroup END endfunction function! s:scratch_on_BufWriteCmd() silent! setl buftype< buflisted< swapfile< bufhidden< nomodified autocmd! vimrc-scratch * unlet! b:scratch_buffer execute 'saveas' . (v:cmdbang ? '!' : '') ' ' filetype detect endfunction augroup END"}}}2 "}}}1 " Section: Plugins {{{1 " EasyMotion {{{1 let g:EasyMotion_leader_key = '' "}}} " powerline {{{2 let g:Powerline_symbols = 'fancy' "}}} " open-browser{{{2 let g:netrw_nogx = 1 " disable netrw's gx mapping. let g:netrw_liststyle = 3 nmap gx (openbrowser-smart-search) vmap gx (openbrowser-smart-search) "}}} " Solarized{{{2 let g:solarized_termtrans=1 let g:solarized_degrade=0 let g:solarized_bold=1 let g:solarized_underline=1 let g:solarized_italic=1 let g:solarized_diffmode="normal" let g:solarized_hitrail=0 let g:solarized_termcolor=256 let g:solarized_visibility="high" let g:solarized_contrast="high" set background=light colorscheme default " colorscheme Tomorrow " colorscheme solarized "}}}2 " netrw {{{2 let g:netrw_list_hide= '*.swp' " nnoremap :Explore " Change default directory. set browsedir=current if executable('wget') let g:netrw_http_cmd = 'wget' endif let g:netrw_list_hide = '^\.,^tags$' "}}}2 " rails {{{2 let g:rails_menu=0 let g:rails_installed_menu=0 let g:rubycomplete_buffer_loading = 1 let g:rubycomplete_rails = 1 autocmd User Rails/app/presenters/*.* \ let b:rails_alternate = substitute(rails#buffer().path(), 'app/','test/unit/','') autocmd User Rails/app/assets/javascripts/*.* \ let b:rails_alternate = fnamemodify(rails#buffer().path(), \ ":s?app/assets/?spec/?:r"). "_spec." . \ fnamemodify(rails#buffer().path(), ":e") autocmd User Rails/spec/javascripts/*.* \ let b:rails_alternate = fnamemodify(rails#buffer().path(), \ ":s?spec/?app/assets/?:s?_spec??") "}}}2 " Syntastic {{{2 let g:syntastic_enable_signs=1 let g:syntastic_auto_jump=0 let g:syntastic_auto_loc_list=1 let g:syntastic_js_checkers = 'jshint' let g:syntastic_javascript_jslint_conf = "--white --lastsemic --eqeqeq --undef --nomen --regexp --plusplus --bitwise --newcap --sloppy --vars --es5=false" "}}}2 " QuickRun {{{2 let g:quickrun_direction = 'rightbelow horizontal' let g:quickrun_config = {} " let g:quickrun_config['ruby'] = {'command': 'testdrb', 'exec': '%c -Itest %s'} let g:quickrun_config['*'] = { \ 'runner/vimproc/updatetime' : 100, \ 'split': 'vertical rightbelow', \ 'targets' : ['quickfix', 'buffer'], \ 'outputter' : 'buffer', \ 'runner' : 'vimproc', \ 'into' : 0, \ 'runmode' : 'async:remote:vimproc' \} "}}}2 " CtrlP {{{2 let g:ctrlp_working_path_mode = 0 let g:ctrlp_persistent_input = 0 let g:ctrlp_open_new_file = 0 let g:ctrlp_clear_cache_on_exit = 0 let g:ctrlp_match_window_bottom = 1 let g:ctrlp_jump_to_buffer = 1 let g:ctrlp_use_caching = 1 let g:ctrlp_mruf_max = 10000 let g:ctrlp_max_files = 0 let g:ctrlp_extensions = ['tag', 'quickfix', 'dir', 'buffertag', 'line', 'change', 'undo'] let g:ctrlp_split_window = 0 " let g:ctrlp_user_command = { " \ 'types': { " \ 1: ['.git/', 'cd %s && git ls-files'], " \ 2: ['.hg/', 'hg --cwd %s locate -I .'], " \ }, " \ 'fallback': 'find %s -type f' " \ } "}}}2 "Fugitive & Gitv {{{2 nnoremap [Space]gd :Gdiff nnoremap [Space]gs :Gstatus nnoremap [Space]gl :Glog nnoremap [Space]gc :Gcommit nnoremap [Space]gC :Git commit -- amend nnoremap [Space]gb :Gblame nnoremap [Space]gr :Gread nnoremap [Space]gw :Gwrite nnoremap [Space]gv :Gitv "}}}2 " Testee {{{2 " noremap rt (testee-test-case) " noremap rf (testee-test-file) " noremap rl (testee-test-last) "}}}2 " grex {{{2 nmap gD (command-line-enter)Gred nmap gy (command-line-enter)Grey "}}}2 " qfreplace.vim {{{2 autocmd MyAutoCmd FileType qf nnoremap r :Qfreplace " Misc {{{2 let g:snips_author = "Travis Jeffery" let g:user_emmet_install_global = 0 autocmd FileType html,css,markdown EmmetInstall let g:user_zen_leader_key = '' let g:use_zen_complete_tag = 1 let g:ragtag_global_maps = 1 " let g:user_zen_settings = { " \ 'indentation' : ' ', " \ 'markdown' : { 'extends' : 'html' } " \} let g:user_zen_settings = { \ 'indentation' : ' ' \} " Unite {{{2 let g:unite_source_history_yank_enable = 1 let g:unite_enable_split_vertically = 1 let g:unite_kind_file_cd_command = 'TabpageCD' let g:unite_kind_file_lcd_command = 'TabpageCD' let g:unite_update_time = 50 let g:unite_winheight = 20 let g:unite_enable_start_insert = 1 let g:unite_cursor_line_highlight = 'TabLineSel' let g:unite_abbr_highlight = 'TabLine' let g:unite_source_file_mru_time_format = '' let g:unite_source_file_mru_filename_format = ':~:.' let g:unite_source_file_mru_limit = 300 let g:unite_source_directory_mru_time_format = '' let g:unite_source_directory_mru_limit = 300 call unite#filters#matcher_default#use(['matcher_fuzzy']) call unite#filters#converter_default#use(['converter_relative_abbr']) call unite#custom_filters('file,buffer,file_rec,file_rec/async,outline', \ ['converter_relative_abbr', 'converter_relative_word', 'matcher_fuzzy', 'sorter_default', 'converter_default']) " nnoremap :Unite buffer " nnoremap :CommandTBuffer nnoremap :CtrlPBuffer " nnoremap :CtrlPBuffer nnoremap [Space]: :Unite history/command command "}}}2 " echodoc {{{2 let g:echodoc_enable_at_startup = 1 "}}}2 " delimitmate {{{2 let delimitMate_expand_cr = 1 let delimitMate_expand_space = 1 let delimitMate_matchpairs = "(:),[:],{:}" let delimitMate_balance_matchpairs = 1 let delimitMate_smart_quotes = 1 let delimitMate_smart_matchpairs = 1 let delimitMate_autoclose = 1 "}}}2 " YankRing {{{2 let g:yankring_max_history = 1000 let g:yankring_max_display = 100 let g:yankring_persist = 1 let g:yankring_share_between_instances = 1 let g:yankring_window_use_separate = 1 let g:yankring_window_use_horiz = 1 let g:yankring_window_auto_close = 1 let g:yankring_window_width = 30 let g:yankring_window_use_right = 1 let g:yankring_window_increment = 15 let g:yankring_history_dir = '$HOME/.tmp' "}}}2 " surround {{{2 let g:surround_{char2nr('-')} = "<% \r %>" let g:surround_{char2nr('=')} = "<%= \r %>" let g:surround_{char2nr('8')} = "/* \r */" let g:surround_{char2nr('s')} = " \r" let g:surround_{char2nr('^')} = "/^\r$/" let g:surround_indent = 1 "}}}2 " vimfiler {{{2 let g:vimfiler_as_default_explorer = 1 let g:vimfiler_safe_mode_by_default = 0 let g:vimfiler_enable_clipboard = 0 " vimshell.vim"{{{ "let g:vimshell_user_prompt = "3\ngetcwd()" "let g:vimshell_user_prompt = 'fnamemodify(getcwd(), ":~")' "let g:vimshell_user_prompt = 'printf("%s %50s", fnamemodify(getcwd(), ":~"), vimshell#vcs#info("(%s)-[%b]"))' let g:vimshell_user_prompt = 'fnamemodify(getcwd(), ":~")' let g:vimshell_right_prompt = 'vcs#info("(%s)-[%b]%p", "(%s)-[%b|%a]%p")' let g:vimshell_prompt = '% ' "let g:vimshell_environment_term = 'xterm' " let g:vimshell_cd_command = 'TabpageCD' let g:vimshell_split_command = '' if s:iswin " Display user name on Windows. "let g:vimshell_prompt = $USERNAME."% " " Use ckw. let g:vimshell_use_terminal_command = 'ckw -e' else " Display user name on Linux. "let g:vimshell_prompt = $USER."% " " Use zsh history. let g:vimshell_external_history_path = expand('~/.zsh-history') " call vimshell#set_execute_file('bmp,jpg,png,gif', 'gexe eog') " call vimshell#set_execute_file('mp3,m4a,ogg', 'gexe amarok') " let g:vimshell_execute_file_list['zip'] = 'zipinfo' " call vimshell#set_execute_file('tgz,gz', 'gzcat') " call vimshell#set_execute_file('tbz,bz2', 'bzcat') " Use gnome-terminal. let g:vimshell_use_terminal_command = 'gnome-terminal -e' endif " Initialize execute file list. let g:vimshell_execute_file_list = {} " call vimshell#set_execute_file('txt,vim,c,h,cpp,d,xml,java', 'vim') let g:vimshell_execute_file_list['rb'] = 'ruby' let g:vimshell_execute_file_list['pl'] = 'perl' let g:vimshell_execute_file_list['py'] = 'python' " call vimshell#set_execute_file('html,xhtml', 'gexe firefox') autocmd MyAutoCmd FileType vimshell call s:vimshell_settings() function! s:vimshell_settings() imap & :call vimshell#mappings#push_and_execute('cd ..') inoremap ' pumvisible() ? "\" : "'" imap (vimshell_another_delete_backward_char) imap (vimshell_another_delete_backward_char) inoremap unite#sources#vimshell_history#start_complete(!0) call vimshell#altercmd#define('g', 'git') call vimshell#altercmd#define('i', 'iexe') call vimshell#altercmd#define('t', 'texe') call vimshell#set_alias('l.', 'ls -d .*') call vimshell#set_galias('L', 'ls -l') call vimshell#hook#add('chpwd', 'my_chpwd', s:vimshell_hooks.chpwd) call vimshell#hook#add('emptycmd', 'my_emptycmd', s:vimshell_hooks.emptycmd) call vimshell#hook#add('preprompt', 'my_preprompt', s:vimshell_hooks.preprompt) call vimshell#hook#add('preexec', 'my_preexec', s:vimshell_hooks.preexec) " call vimshell#hook#set('preexec', [s:SID_PREFIX() . 'vimshell_hooks_preexec']) endfunction autocmd MyAutoCmd FileType int-* call s:interactive_settings() function! s:interactive_settings() call vimshell#hook#set('input', [s:vimshell_hooks.input]) endfunction autocmd MyAutoCmd FileType term-* call s:terminal_settings() function! s:terminal_settings() inoremap (vimshell_term_send_semicolon) vimshell#term_mappings#send_key(';') inoremap j vimshell#term_mappings#send_key('j') "inoremap vimshell#term_mappings#send_keys("\[A") " Sticky key. imap ; texe_sticky_func() " Escape key. iunmap imap (vimshell_term_send_escape) endfunction function! s:texe_sticky_func() let sticky_table = { \',' : '<', '.' : '>', '/' : '?', \'1' : '!', '2' : '@', '3' : '#', '4' : '$', '5' : '%', \'6' : '^', '7' : '&', '8' : '*', '9' : '(', '0' : ')', '-' : '_', '=' : '+', \';' : ':', '[' : '{', ']' : '}', '`' : '~', "'" : "\"", '\' : '|', \} let special_table = { \"\" : "\", "\" : "\(vimshell_term_send_semicolon)", "\" : ";\" \} if mode() !~# '^c' echo 'Input sticky key: ' endif let char = '' while char == '' let char = nr2char(getchar()) endwhile if char =~ '\l' return toupper(char) elseif has_key(sticky_table, char) return sticky_table[char] elseif has_key(special_table, char) return special_table[char] else return '' endif endfunction let s:vimshell_hooks = {} function! s:vimshell_hooks.chpwd(args, context) if len(split(glob('*'), '\n')) < 100 call vimshell#execute('ls') endif endfunction function! s:vimshell_hooks.emptycmd(cmdline, context) call vimshell#set_prompt_command('ls') return 'ls' endfunction function! s:vimshell_hooks.preprompt(args, context) " call vimshell#execute('echo "preprompt"') endfunction function! s:vimshell_hooks.preexec(cmdline, context) " call vimshell#execute('echo "preexec"') let args = vimproc#parser#split_args(a:cmdline) if len(args) > 0 && args[0] ==# 'diff' call vimshell#set_syntax('diff') endif return a:cmdline endfunction function! s:vimshell_hooks.input(input, context) " echomsg 'input' return a:input endfunction command! -nargs=0 VF :VimFiler nnoremap [Space]v :VimFiler nmap [Space]h :edit %:h "}}}2 " SuperTab {{{2 let g:SuperTabLongestEnhanced = 1 let g:SuperTabDefaultCompletionType = "context" "}}}2 " CommandT {{{2 let g:CommandTMatchWindowReverse = 1 let g:CommandTMaxHeight = 10 let g:CommandTMaxFiles = 30000 let g:CommandTScanDotDirectories = 1 let g:CommandTMatchWindowAtTop = 0 let g:CommandTCancelMap=['', ''] "}}}2 " neocomplcache{{{2 let g:neocomplcache_enable_at_startup = 0 let g:neocomplcache_enable_smart_case = 1 let g:neocomplcache_enable_camel_case_completion = 1 let g:neocomplcache_enable_underbar_completion = 1 let g:neocomplcache_min_syntax_length = 4 let g:neocomplcache_manual_completion_start_length = 0 let g:neocomplcache_min_keyword_length = 4 let g:neocomplcache_enable_auto_select = 1 let g:neocomplcache_enable_auto_delimiter = 1 let g:neocomplcache_disable_auto_select_buffer_name_pattern = '\[Command Line\]' let g:neocomplcache_cursor_hold_i_time = 50 let g:neocomplcache_auto_completion_start_length = 4 let g:neocomplcache_max_list = 100 let g:neocomplcache_force_overwrite_completefunc = 1 let g:neocomplcache_enable_cursor_hold_i = v:version > 703 || \ v:version == 703 && has('patch289') let g:neocomplcache_dictionary_filetype_lists = { \ 'default' : '', \ 'ruby' : expand('$DOTVIM/dict/ruby.dict'), \ } let g:neocomplcache_omni_functions = { \ 'python' : 'pythoncomplete#Complete', \ 'ruby' : 'rubycomplete#Complete', \ } " let g:neocomplcache_cursor_hold_i_time = 300 if !exists('g:neocomplcache_keyword_patterns') let g:neocomplcache_keyword_patterns = {} endif let g:neocomplcache_keyword_patterns['default'] = '\h\w*' let g:neocomplcache_snippets_dir = $HOME . '/snippets' " if !exists('g:neocomplcache_omni_patterns') " let g:neocomplcache_omni_patterns = {} " endif " let g:neocomplcache_omni_patterns.ruby = '[^. *\t]\.\w*\h\w*::' " if !exists('g:neocomplcache_same_filetype_lists') " let g:neocomplcache_same_filetype_lists = {} " endif let g:neocomplcache_source_look_dictionary_path = '' let g:neocomplcache_vim_completefuncs = { \ 'Ref' : 'ref#complete', \ 'Unite' : 'unite#complete_source', \ 'VimShellExecute' : 'vimshell#complete#vimshell_execute_complete#completefunc', \ 'VimShellInteractive' : 'vimshell#complete#vimshell_execute_complete#completefunc', \ 'VimShellTerminal' : 'vimshell#complete#vimshell_execute_complete#completefunc', \ 'VimFiler' : 'vimfiler#complete', \} if !exists('g:neocomplcache_plugin_completion_length') let g:neocomplcache_plugin_completion_length = { \ 'look' : 4, \ } endif "}}}2 " Clojure {{{2 let g:vimclojure#HighlightBuiltins=1 let vimclojure#FuzzyIndent = 1 "}}}2 let g:template_vim_template_dir = $HOME.'.vim/template' let g:AutoPairs = {'(':')', '[':']', '{':'}','"':'"'} let g:indexed_search_shortmess=1 let g:HammerQuiet=1 let g:CSApprox_verbose_level=0 if filereadable("/usr/local/bin/ctags") let g:tagbar_ctags_bin="/usr/local/bin/ctags" else let g:tagbar_ctags_bin="/usr/bin/ctags" endif if filereadable($HOME . "/.githubrc") source $HOME/.githubrc endif if filereadable($HOME . "/.passwords") source $HOME/.passwords endif "}}}1 " Section: Commands {{{1 call altercmd#load() command! -nargs=* -bang W :w command! -nargs=0 E :Explore command! -nargs=0 DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis command! -bar -nargs=0 SudoW :setl nomod|silent exe 'write !sudo tee % >/dev/null'|let &mod = v:shell_error " Rename {{{2 command! -bar -nargs=* -bang -complete=file Rename : \ let v:errmsg = ""| \ saveas | \ if v:errmsg == ""| \ call delete(expand("#"))| \ endif "}}}2 " Remove {{{2 command! -bar -nargs=0 -bang -complete=file Remove : \ let v:errmsg = ''| \ let s:removable = expand('%:p')| \ bdelete| \ if v:errmsg == ''| \ call delete(s:removable)| \ endif| \ unlet s:removable "}}}2 " CD - alternative :cd with more user-friendly completion "{{{2 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')[1:], ' ') . '*/'), \ "\n") endfunction AlterCommand cd CD " TabpageCD - wrapper of :cd to keep cwd for each tabpage "{{{2 command! -nargs=? TabpageCD \ execute 'cd' fnameescape() \ | let t:cwd = getcwd() "}}}1 " Section: Autocommands {{{1 " autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS " autocmd FileType javascript " \ :setl omnifunc=jscomplete#CompleteJS " let g:jscomplete_use = ['dom'] autocmd FileType html set omnifunc=htmlcomplete#CompleteTags autocmd FileType vim set omnifunc=syntaxcomplete#Complete autocmd FileType css set omnifunc=csscomplete#CompleteCSS autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags autocmd FileType php set omnifunc=phpcomplete#CompletePHP autocmd FileType c set omnifunc=ccomplete#Complete autocmd FileType ruby,eruby \ set omnifunc=rubycomplete#Complete | \ set foldmethod=expr | \ set foldexpr=getline(v:lnum)=~'^\\s*#' " \ exe "normal zM``" " \ set foldlevel=1 | autocmd BufNewFile,BufRead *.coffee set ft=coffee sw=2 sts=2 autocmd BufNewFile,BufRead *.bats set ft=sh sw=2 sts=2 autocmd BufNewFile,BufRead *.txt set ft=markdown autocmd BufNewFile,BufRead *.css set ft=css sw=2 sts=2 autocmd BufNewFile,BufRead *.json set ft=javascript sw=2 sts=2 autocmd BufNewFile,BufRead *.rb set ft=ruby sw=2 sts=2 autocmd BufNewFile,BufRead Podfile set ft=ruby sw=2 sts=2 autocmd FileType vimperator set ft=vim autocmd filetype svn,*commit*,markdown set spell autocmd FileType cucumber compiler cucumber | setl makeprg=cucumber\ \"%:p\" autocmd FileType python \ setl makeprg=python\ \"%:p\" autocmd FileType clojure \ setl makeprg=clj\ \"%:p\" autocmd User Bundler \ if &makeprg !~ 'bundle' | setl makeprg^=bundle\ exec\ | endif autocmd FileType ruby \ compiler rubyunit | setl makeprg=ruby\ -Itest\ \"%:p\" " autocmd User Bundler " \ if &makeprg !~ 'bundle' | setl makeprg^=bundle\ exec\ | endif autocmd BufReadPost fugitive://* set bufhidden=delete let g:do_filetype = 0 au GUIEnter,BufAdd * if expand('') == "" | let g:do_filetype = 1 | endif au BufEnter * if g:do_filetype | setf markdown | let g:do_filetype = 0 | endif au BufNewFile,BufRead,BufWinEnter * if search("diff --git", 'cp', 1) | set filetype=git | endif command! OpenChangedFiles :call OpenChangedFiles() function! OpenChangedFiles() only let status = system('git status -s | grep "^ \?\(M\|A\)" | cut -d " " -f 3') let filenames = split(status, "\n") exec "edit " . filenames[0] for filename in filenames[1:] exec "sp " . filename endfor endfunction autocmd BufReadPost * call SetCursorPosition() function! SetCursorPosition() if &filetype !~ 'svn\|commit\c' if line("'\"") > 0 && line("'\"") <= line("$") exe "normal! g`\"" normal! zz endif end endfunction function! InlineVariable() normal "ayiw normal 4diw normal "bd$ normal dd normal k$ exec '/\<' . @a . '\>' exec ':.s/\<' . @a . '\>/' . @b endfunction function! HtmlEscape() silent s/&/\&/eg silent s//\>/eg endfunction function! HtmlUnEscape() silent s/<//eg silent s/&/\&/eg endfunction command! -nargs=0 JSBeautify call JSBeautify() function! JSBeautify() silent! exe "%! jsbeautifier --stdin" endfunction "}}}1 " Section: Abbreviations{{{1 cabbrev E e cabbrev ack grep cabbrev BUndle Bundle cabbrev gg; Ggrep -P iabbrev ddate strftime("%Y-%m-%d") " rails cabbrevs cabbrev rm; Rmodel cabbrev rc; Rcontroller cabbrev rv; Rview cabbrev ru; Runittest cabbrev rf; Rfunctional cabbrev rs; Rschema iabbrev mmit; The MIT License (MIT) \ \Copyright (c) \ \Permission is hereby granted, free of charge, to any person obtaining a copy \of this software and associated documentation files (the "Software"), to deal \in the Software without restriction, including without limitation the rights \to use, copy, modify, merge, publish, distribute, sublicense, and/or sell \copies of the Software, and to permit persons to whom the Software is \furnished to do so, subject to the following conditions: \ \The above copyright notice and this permission notice shall be included in \all copies or substantial portions of the Software. \ \THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR \IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, \FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE \AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER \LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN \THE SOFTWARE. command! Ctags \ execute "!ctags --extra=+f --exclude=.git --exclude=log -R *" cabbrev RModel Rmodel autocmd FileType ruby,eruby \ iabbrev rw; attr_accessor| \ iabbrev rr; attr_reader| \ iabbrev ww; attr_writer " cabbrev git Git cabbrev ~? ~/ iabbrev Utitlies Utilities iabbrev utitlies utilities iabbrev init; initialize iabbrev innit init iabbrev innitialize initialize iabbrev seperate separate iabbrev teh the iabbrev ;; => iabbrev shuold should iabbrev shulod should iabbrev PgTOols PgTools iabbrev PgTOOls PgTools if has('quickfix') cnoreabbrev csa \ ((getcmdtype() == ':' && getcmdpos() <= 4)? 'cs add' : 'csa') cnoreabbrev csf \ ((getcmdtype() == ':' && getcmdpos() <= 4)? 'cs find' : 'csf') cnoreabbrev csk \ ((getcmdtype() == ':' && getcmdpos() <= 4)? 'cs kill' : 'csk') cnoreabbrev csr \ ((getcmdtype() == ':' && getcmdpos() <= 4)? 'cs reset' : 'csr') cnoreabbrev css \ ((getcmdtype() == ':' && getcmdpos() <= 4)? 'cs show' : 'css') cnoreabbrev csh \ ((getcmdtype() == ':' && getcmdpos() <= 4)? 'cs help' : 'csh') endif abbrev shuold should "}}}1 " Section: Mappings {{{1 inoremap kj let mapleader="," nmap [Space] xmap [Space] nnoremap [Space] xnoremap [Space] " nnoremap ; " xnoremap ; nnoremap : xnoremap : nnoremap (command-line-enter) : xnoremap (command-line-enter) : " nmap ; (command-line-enter) " xmap ; (command-line-enter) nmap : (command-line-enter) xmap : (command-line-enter) " nnoremap ' " nnoremap ' ; nnoremap [Space]; :normal!; nnoremap [Space], :normal!, nnoremap [Space]yh :Unite history/yank nnoremap [Space]mk :marks nnoremap [Space]re :registers nnoremap [Space]ya :1,$y:1,$y+ nnoremap [Space]y% :1,$y:1,$y+ function! s:SID() "{{{ return matchstr(expand(''), '\zs\d\+\ze_SID$') endfunction "}}} function! s:SNR(map) "{{{ return printf("%d_%s", s:SID(), a:map) endfunction "}}} if (exists("g:indexed_search_plugin")) nnoremap n :let v:errmsg='':silent! norm! nzv:ShowSearchIndex nnoremap N :let v:errmsg='':silent! norm! Nzv:ShowSearchIndex nnoremap * :let v:errmsg='':silent! norm! *zv:ShowSearchIndex nnoremap # :let v:errmsg='':silent! norm! #zv:ShowSearchIndex endif nmap b (command-line-enter)CtrlPBufTagAll nmap d (command-line-enter)CtrlPDir nmap q (command-line-enter)CtrlPQuickfix nmap l (command-line-enter)CtrlPLine " nmap : q: " nmap / q/ " nmap ? q? nmap [Space]r (command-line-enter)QuickRun nnoremap s* ':%substitute/\<' . expand('') . '\>/' " Ruby block to yo face nmap [Space]b BlockToggle if exists('g:loaded_delimitMate') && g:loaded_delimitMate == 1 autocmd FileType * imap delimitMateC-Left autocmd FileType * imap delimitMateC-Right imap delimitMateC-Left imap delimitMateC-Right else inoremap =getline('.')=~'^\s*$'&&col('.')>strlen(getline('.'))?"0\C-D>\Esc>kJs":"\Left>" inoremap =col('.')>strlen(getline('.'))?"\C-F>":"\Right>" endif map [Space]c (operator-camelize-toggle) " Copy current buffer's path to clipboard{{{2 nnoremap % :call copy_path() function! s:copy_path() let @*=expand('%') let @"=expand('%') let @+=expand('%') endfunction"}}}2 " Copy current buffer's path to clipboard{{{2 nnoremap [Space]% :call copy_path() function! s:copy_path() let @*=expand('%') let @"=expand('%') let @+=expand('%') endfunction"}}}2 " Altr {{{2 autocmd MyAutoCmd FileType vim call altr#define('autoload/%.vim', 'doc/%.txt', 'doc/%.jax', 'plugin/%.vim') autocmd MyAutoCmd FileType clojure call altr#define('src/*/%.clj', 'test/*/%.clj', 'test/*/test/%.clj') autocmd FileType ruby call altr#define('lib/%/*.rb', 'lib/%.rb', 'test/%_*.rb', 'test/%.rb') autocmd FileType coffee call altr#define('src/%/*.coffee', 'src/%.coffee', 'test/%_*.coffee', 'test/%.coffee') autocmd FileType * command! -buffer A call altr#forward() "}}}2 " To keep legacy surround mapping{{{2 let g:surround_no_mappings=1 nmap ds Dsurround nmap cs Csurround nmap ys Ysurround nmap yS YSurround nmap yss Yssurround nmap ySs YSsurround nmap ySS YSsurround xmap S VSurround xmap gS VgSurround if !hasmapto("Isurround","i") && "" == mapcheck("","i") imap Isurround endif imap s Isurround imap S ISurround vmap s VSurround xmap s VSurround " neocomplcache {{{2 " inoremap neocomplcache#manual_filename_complete() " nnoremap &bt == "" ? ":nohlsearch" : "\" " imap CrInInsertModeBetterWay() " function! s:CrInInsertModeBetterWay() " return pumvisible() ? "\=neocomplcache#cancel_popup()" : "\" " endfunction " inoremap pumvisible() ? "\" : " \neocomplcache#sources#completefunc_complete#call_completefunc('googlesuggest_complete#completefunc') " inoremap pumvisible() ? neocomplcache#close_popup() : "\" " inoremap pumvisible() ? neocomplcache#cancel_popup() : "\" " imap (neocomplcache_start_unite_complete) " inoremap neocomplcache#smart_close_popup()."\" " inoremap neocomplcache#smart_close_popup()."\" inoremap pumvisible() ? "\" : "\" " inoremap pumvisible() ? neocomplcache#close_popup(): "\" " inoremap pumvisible() ? neocomplcache#cancel_popup()."\" : "\" " inoremap pumvisible() ? "\" : "\\\\" inoremap pumvisible() ? "\" : "\\" " inoremap pumvisible() ? "\" : check_back_space() ? "\" : "\\\\" " inoremap pumvisible() ? "\" : "\" " inoremap pumvisible() ? "\" : check_back_space() ? "\" : "\\\\" " inoremap pumvisible() ? "\" : "\" "{{{2 " Useful save mappings{{{2 nnoremap [Space]w :update nnoremap [Space]fw :write! nnoremap [Space]q :quit nnoremap [Space]aq :quitall nnoremap [Space]fq :quitall! nnoremap :update "}}}2 " Change current directory{{{2 nnoremap [Space]cd :call cd_buffer_dir() function! s:cd_buffer_dir()"{{{ let l:filetype = getbufvar(bufnr('%'), '&filetype') if l:filetype ==# 'vimfiler' let l:dir = getbufvar(bufnr('%'), 'vimfiler').current_dir elseif l:filetype ==# 'vimshell' let l:dir = getbufvar(bufnr('%'), 'vimshell').save_dir else let l:dir = isdirectory(bufname('%')) ? bufname('%') : fnamemodify(bufname('%'), ':p:h') endif TabpageCD `=l:dir` endfunction"}}}2 nnoremap :redraw!nohlsearch nnoremap &bt == "" ? "/": "\" nmap R nmap R (command-line-enter)%s// nnoremap 5 nnoremap 5 " Fast search pair. nnoremap [Space]p % xnoremap [Space]p % " Fast screen move. nnoremap [Space]j zz. xnoremap [Space]j zz. nnoremap [Space]k z-z. xnoremap [Space]k z-z. nnoremap [Space]ev :edit $MYVIMRC nnoremap [Space]sv :source $MYVIMRC " q commands "{{{2 nnoremap Q gq vnoremap Q gq "}}} " Tags {{{2 nnoremap [Space]tt nnoremap [Space]tn :tn nnoremap [Space]tp :tp nnoremap [Space]tl :tags nnoremap [Space]ts :ts nnoremap [Space]tP :tf nnoremap [Space]tN :tl nnoremap [Space]tk :tp nnoremap [Space]tsn :split:tn nnoremap [Space]tsp :split:tp nnoremap [Space]tsP :split:tf nnoremap [Space]tsN :split:tl "}}}2 " q: Quickfix "{{{ " The prefix key. nnoremap [Quickfix] " nmap q [Quickfix] " Disable Ex-mode. " For quickfix list "{{{ nnoremap [Quickfix]n :cnext nnoremap [Quickfix]p :cprevious nnoremap [Quickfix]r :crewind nnoremap [Quickfix]N :cfirst nnoremap [Quickfix]P :clast nnoremap [Quickfix]fn :cnfile nnoremap [Quickfix]fp :cpfile nnoremap [Quickfix]l :clist nnoremap [Quickfix]q :cc nnoremap [Quickfix]o :copen nnoremap [Quickfix]c :cclose nnoremap [Quickfix]en :cnewer nnoremap [Quickfix]ep :colder nnoremap [Quickfix]m :make nnoremap [Quickfix]M q:make nnoremap [Quickfix]g q:grep " Toggle quickfix window. nnoremap [Quickfix] :call toggle_quickfix_window() function! s:toggle_quickfix_window() let _ = winnr('$') cclose if _ == winnr('$') copen setlocal nowrap setlocal whichwrap=b,s endif endfunction "}}} " For location list (mnemonic: Quickfix list for the current Window) "{{{ nnoremap [Quickfix]wn :lnext nnoremap [Quickfix]wp :lprevious nnoremap [Quickfix]wr :lrewind nnoremap [Quickfix]wP :lfirst nnoremap [Quickfix]wN :llast nnoremap [Quickfix]wfn :lnfile nnoremap [Quickfix]wfp :lpfile nnoremap [Quickfix]wl :llist nnoremap [Quickfix]wq :ll nnoremap [Quickfix]wo :lopen nnoremap [Quickfix]wc :lclose nnoremap [Quickfix]wep :lolder nnoremap [Quickfix]wen :lnewer nnoremap [Quickfix]wm :lmake nnoremap [Quickfix]wM q:lmake nnoremap [Quickfix]w q:lmake nnoremap [Quickfix]wg q:lgrep "}}} "}}}2 " s: Windows and buffers(High priority) "{{{2 " The prefix key. nnoremap [Window] nmap s [Window] nnoremap [Window]p :call split_nicely() nnoremap [Window]v :vsplit nnoremap [Window]c :call smart_close() " nnoremap - :call smart_close() nnoremap [Window]o :only nnoremap [Window] :call ToggleSplit() nnoremap [Window]s (golden_ratio_resize) function! s:MovePreviousWindow() let l:prev_name = winnr() silent! wincmd p if l:prev_name == winnr() silent! wincmd w endif endfunction " If window isn't splited, split buffer. function! s:ToggleSplit() let l:prev_name = winnr() silent! wincmd w if l:prev_name == winnr() split else call s:smart_close() endif endfunction "}}}2 " Move search word and fold open"{{{2 " nnoremap N Nzv " nnoremap n nzv nnoremap g* g*zv nnoremap g# g#zv "}}}2 " smartword.vim"{{{2 " Replace w and others with smartword-mappings nmap w (smartword-w) nmap b (smartword-b) nmap e (smartword-e) nmap ge (smartword-ge) xmap w (smartword-w) xmap b (smartword-b) " Operator pending mode. omap w (smartword-w) omap b (smartword-b) omap ge (smartword-ge) "}}}2 " Command line buffer {{{2 nnoremap (command-buffer-enter) q: xnoremap (command-buffer-enter) q: nnoremap (command-buffer-norange) q: " nmap : (command-buffer-enter) " xmap : (command-buffer-enter) " nmap ; (command-buffer-enter) " xmap ; (command-buffer-enter) autocmd MyAutoCmd CmdwinEnter * call s:init_cmdwin() function! s:init_cmdwin() nnoremap q :quit inoremap pumvisible() ? "\" : check_back_space() ? "\" : "\" startinsert! endfunction "}}} function! s:check_back_space()"{{{ let col = col('.') - 1 return !col || getline('.')[col - 1] =~ '\s' endfunction"}}} "}}}2 " camlcasemotion.vim"{{{2 nmap W CamelCaseMotion_w xmap W CamelCaseMotion_w nmap B CamelCaseMotion_b xmap W CamelCaseMotion_b "}}}2 vnoremap [Space]a :Alignta =>/= xnoremap [Space]a :Alignta =>\= nnoremap m :TagbarToggle " nnoremap d :TagbarOpenAutoClose nmap z (command-line-enter)ZoomWin nnoremap v :vsplit nnoremap s :split nnoremap \ :%!fmt -w 79 xnoremap \ :!fmt -w 79 vnoremap \ :!fmt -w 79 nnoremap ` :%s/\s*$//ge nnoremap cd :cd %:p:h nnoremap y :YRShow nnoremap Y :GundoToggle imap o imap nmap ' ""yls={'"': "'", "'": '"'}[@"] vmap g/ y/=substitute(escape(@", '\\/.*$^~[]'), '\n', '\\n', 'g') nnoremap VV 0v$h nnoremap X :set winwidth=80:set winwidth=31 nnoremap gff gf " imap (( () " inoremap nmap - ivs-2lxi nmap + :cd %:p:hnew imap $a imap 0i " imap ha " imap la imap imap bvec cmap nmap [2 :diffget //2 nmap ]3 :diffget //3 vmap rv :call ExtractVariable() nmap ri :call InlineVariable() nmap /# /^ *# nmap /f /^ *def\> nmap /c /^ *class\> nmap /i /^ *if\> nmap \# /^ *# nnoremap gs nmap gs :vimgrep /^ *\(context\test\def\should\class\)/ %:cw nmap \/ /\<\> nnoremap gqq vapgq " nmap a= :Tabularize /= " vmap a= :Tabularize /= " nmap a: :Tabularize /:\zs " vmap a: :Tabularize /:\zs " nmap a :Tabularize / " vmap a :Tabularize / command! -nargs=? -range Align ,call AlignSection('') vnoremap a :Align function! AlignSection(regex) range let extra = 1 let sep = empty(a:regex) ? '=' : a:regex let maxpos = 0 let section = getline(a:firstline, a:lastline) for line in section let pos = match(line, ' *'.sep) if maxpos < pos let maxpos = pos endif endfor call map(section, 'AlignLine(v:val, sep, maxpos, extra)') call setline(a:firstline, section) endfunction function! AlignLine(line, sep, maxpos, extra) let m = matchlist(a:line, '\(.\{-}\) \{-}\('.a:sep.'.*\)') if empty(m) return a:line endif let spaces = repeat(' ', a:maxpos - strlen(m[1]) + a:extra) return m[1] . spaces . m[2] endfunction nnoremap =p m`=ap`` nmap = maG=gg`a nmap h :help =expand("") vmap h "ry:helpr nmap yyp imap $o nnoremap d$Op0x " Split movement{{{2 nnoremap nnoremap nnoremap nnoremap "}}}2 inoremap => cnoremap %% =expand('%:h').'/' cnoremap %& =expand('%:p') " Search slashes easily (too lazy to prefix backslashes to slashes) cnoremap / getcmdtype() == '/' ? '\/' : '/' nnoremap gc keys_to_select_the_last_changed_text() nnoremap gV `[v`] nmap \v /\v nmap g, nmap g; " nnoremap / /\v " vnoremap / /\v " nmap (jump-x2-to-previous) " nmap (jump-x2-to-next) cnoremap =PasteEscaped() " cnoremap "\" function! s:PasteEscaped() echo "\\".getcmdline()."\"" let char = getchar() if char == "\" return '' else let register_content = getreg(nr2char(char)) let escaped_register = escape(register_content, '\'.getcmdtype()) return substitute(escaped_register, '\n', '\\n', 'g') endif endfunction function! s:jump_section_n(pattern) let pattern = a:pattern[1:] let forward_p = a:pattern[0] == '/' let flags = forward_p ? 'W' : 'Wb' mark ' let i = 0 while i < v:count1 if search(pattern, flags) == 0 if forward_p normal! G else normal! gg endif break endif let i = i + 1 endwhile endfunction " for visual mode. a:motion is '[[', '[]', ']]' or ']['. function! s:jump_section_v(motion) execute 'normal!' "gv\" execute 'normal' v:count1 . a:motion let line = line('.') let col = col('.') normal! gv call cursor(line, col) endfunction " for operator-pending mode. a:motion is '[[', '[]', ']]' or ']['. function! s:jump_section_o(motion) execute 'normal' v:count1 . a:motion endfunction xmap Commentary nmap CommentaryLine if hasmapto('s', 'v') vunmap s endif vmap s S xmap s S " nnoremap :call NextWindow() " nnoremap :call PreviousWindowOrTab() function! s:keys_to_select_the_last_changed_text() " It is not possible to determine whether the last operation to change text " is linewise or not, so guess the wise of the last operation from the range " of '[ and '], like wise of a register content set by setreg() without " {option}. let col_begin = col("'[") let col_end = col("']") let length_end = len(getline("']")) let maybe_linewise_p = (col_begin == 1 \ && (col_end == length_end \ || (length_end == 0 && col_end == 1))) return '`[' . (maybe_linewise_p ? 'V' : 'v') . '`]' endfunction function! s:NextWindow() if winnr('$') == 1 call s:split_nicely() else wincmd w endif endfunction function! s:NextWindowOrTab() if tabpagenr('$') == 1 && winnr('$') == 1 call s:split_nicely() elseif winnr() < winnr("$") wincmd w else tabnext 1wincmd w endif endfunction function! s:PreviousWindowOrTab() if winnr() > 1 wincmd W else tabprevious execute winnr("$") . "wincmd w" endif endfunction " Split nicely"{{{2 command! SplitNicely call s:split_nicely() function! s:split_nicely() " Split nicely. if winwidth(0) > 2 * &winwidth vsplit else split endif wincmd p endfunction "}}}2 " Delete current buffer."{{{ nnoremap [Window]d :call CustomBufferDelete(0) " Force delete current buffer. nnoremap [Window]D :call CustomBufferDelete(1) function! s:CustomBufferDelete(is_force) let current = bufnr('%') call s:CustomAlternateBuffer() if a:is_force silent! execute 'bdelete! ' . current else silent! execute 'bdelete ' . current endif endfunction "}}} " Buffer move. " Fast buffer switch."{{{ function! s:CustomAlternateBuffer() if bufnr('%') != bufnr('#') && buflisted(bufnr('#')) buffer # else let l:cnt = 0 let l:pos = 1 let l:current = 0 while l:pos <= bufnr('$') if buflisted(l:pos) if l:pos == bufnr('%') let l:current = l:cnt endif let l:cnt += 1 endif let l:pos += 1 endwhile if l:current > l:cnt / 2 bprevious else bnext endif endif endfunction "}}} " Edit"{{{ nnoremap [Window]en :new nnoremap [Window]ee :JunkFile "}}} " Scroll other window. " nnoremap :call ScrollOtherWindow(1) " inoremap :call ScrollOtherWindow(1) " nnoremap :call ScrollOtherWindow(0) " inoremap :call ScrollOtherWindow(0) function! s:ScrollOtherWindow(direction) execute 'wincmd' (winnr('#') == 0 ? 'w' : 'p') execute (a:direction ? "normal! \" : "normal! \") wincmd p endfunction "}}} " Smart }"{{{2 nnoremap } :call ForwardParagraph() onoremap } :call ForwardParagraph() xnoremap } :call ForwardParagraph()mzgv`z function! ForwardParagraph() let cnt = v:count ? v:count : 1 let i = 0 while i < cnt if !search('^\s*\n.*\S','W') normal! G$ return endif let i = i + 1 endwhile endfunction "}}} nnoremap [Space] :buffer # nnoremap 0 ^ nnoremap ^ 0 xnoremap 0 ^ xnoremap ^ 0 vnoremap 0 ^ vnoremap ^ 0 xmap p (operator-replace) xmap P (operator-replace) " Move to top/center/bottom. noremap zz (winline() == (winheight(0)+1)/ 2) ? 'zt' : (winline() == 1)? 'zb' : 'zz' " Auto escape / substitute. xnoremap [Space]s y:%s/=substitute(@0, '/', '\\/', 'g')//g if exists('g:loaded_poslist') nmap (poslist-prev-buf) nmap (poslist-next-buf) nmap [Space][ (poslist-prev-buf) nmap [Space]] (poslist-next-buf) else nmap [Space][ (exjumplist-previous-buffer) nmap [Space]] (exjumplist-next-buffer) endif iabbrev em; — function! YRRunAfterMaps() nnoremap Y :YRYankCount 'y$' endfunction nnoremap Y y$ nnoremap . .`[ function! s:VSetSearch() let temp = @@ norm! gvy let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g') let @@ = temp endfunction vmap * :call VSetSearch()// vmap # :call VSetSearch()?? nmap gr :topleft :split config/routes.rb function! ShowRoutes() topleft 100 :split __Routes__ set buftype=nofile normal 1GdG 0r! rake -s routes exec ":normal " . line("$") . "_ " normal 1GG normal dd endfunction nnoremap gR :call ShowRoutes() nnoremap gv :CommandTFlush:CommandT app/views nnoremap gc :CommandTFlush:CommandT app/controllers nnoremap gu :CommandTFlush:CommandT test/unit nnoremap gF :CommandTFlush:CommandT test/functional nnoremap gt :CommandTFlush:CommandT test nnoremap gm :CommandTFlush:CommandT app/models nnoremap gh :CommandTFlush:CommandT app/helpers nnoremap gl :CommandTFlush:CommandT lib nnoremap gp :CommandTFlush:CommandT public nnoremap gs :CommandTFlush:CommandT public/stylesheets nnoremap gS :CommandTFlush:CommandT spec nnoremap gg :topleft 100 :split Gemfile nnoremap gf :CommandT %%/ " nnoremap , :CommandT nnoremap ! :CommandTFlush nnoremap , :CommandTFlush:CommandT nnoremap :CommandTFlush:CommandTBuffer " Delete the content of the current line (not the line itself). nnoremap dl 0d$ command! -nargs=+ Allmap \ execute 'map' \ | execute 'map!' command! -nargs=+ Allnoremap \ execute 'noremap' \ | execute 'noremap!' command! -nargs=+ Allunmap \ execute 'unmap' \ | execute 'unmap!' command! -bang -nargs=* Cmap call s:cmd_Cmap('', '', []) command! -nargs=* Ccmap call s:cmd_Cmap('c', '', []) command! -nargs=* Cimap call s:cmd_Cmap('i', '', []) command! -nargs=* Clmap call s:cmd_Cmap('l', '', []) command! -nargs=* Cnmap call s:cmd_Cmap('n', '', []) command! -nargs=* Comap call s:cmd_Cmap('o', '', []) command! -nargs=* Csmap call s:cmd_Cmap('s', '', []) command! -nargs=* Cvmap call s:cmd_Cmap('v', '', []) command! -nargs=* Cxmap call s:cmd_Cmap('x', '', []) command! -nargs=* Callmap call s:cmd_Cmap('All', '', []) command! -nargs=* Cobjmap call s:cmd_Cmap('Obj', '', []) function! s:separate_list(list, regexp) let i = 0 while i < len(a:list) && a:list[i] =~# a:regexp let i += 1 endwhile return [(0 < i ? a:list[:i-1] : []), a:list[(i):]] endfunction function! s:contains_p(list, regexp) for item in a:list if item =~# a:regexp return s:TRUE endif endfor return s:FALSE endfunction function! s:cmd_Cmap(prefix, suffix, args) " FIXME: This parsing may not be compatible with the original one. let [options, rest] = s:separate_list(a:args, \ '^\c<\(buffer\|expr\|script\|silent\|special\|unique\|count\|noexec\)>$') if len(rest) < 2 throw 'Insufficient number of arglineuments: ' . string(rest) endif let lhs = rest[0] let script = rest[1:] let count_p = s:contains_p(options, '^\c$') let noexec_p = s:contains_p(options, '^\c$') call filter(options, 'v:val !~# ''^\c<\(count\|noexec\)>$''') execute a:prefix.'noremap'.a:suffix join(options) lhs \ ':'.(count_p ? '' : '') . join(script) . (noexec_p ? '' : '') endfunction let s:FALSE = 0 let s:TRUE = !s:FALSE command! -bang -nargs=* Fmap call s:cmd_Fmap('', '', []) command! -nargs=* Fcmap call s:cmd_Fmap('c', '', []) command! -nargs=* Fimap call s:cmd_Fmap('i', '', []) command! -nargs=* Flmap call s:cmd_Fmap('l', '', []) command! -nargs=* Fnmap call s:cmd_Fmap('n', '', []) command! -nargs=* Fomap call s:cmd_Fmap('o', '', []) command! -nargs=* Fsmap call s:cmd_Fmap('s', '', []) command! -nargs=* Fvmap call s:cmd_Fmap('v', '', []) command! -nargs=* Fxmap call s:cmd_Fmap('x', '', []) command! -nargs=* Fallmap call s:cmd_Fmap('All', '', []) command! -nargs=* Fobjmap call s:cmd_Fmap('Obj', '', []) function! RunTests(filename) " Write the file and run tests for the given filename :w :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo if match(a:filename, '\.feature$') != -1 exec ":!script/features " . a:filename else if filereadable("script/test") exec ":!script/test " . a:filename elseif filereadable("Gemfile") exec ":!bundle exec rspec --color " . a:filename else exec ":!rspec --color " . a:filename end end endfunction function! SetTestFile() " Set the spec file that tests will be run for. let t:grb_test_file=@% endfunction function! RunTestFile(...) if a:0 let command_suffix = a:1 else let command_suffix = "" endif " Run the tests for the previously-marked file. let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\)$') != -1 if in_test_file call SetTestFile() elseif !exists("t:grb_test_file") return end call RunTests(t:grb_test_file . command_suffix) endfunction function! RunNearestTest() let spec_line_number = line('.') call RunTestFile(":" . spec_line_number . " -b") endfunction nnoremap T :RunAllRubyTests " nnoremap T :RunRubyFocusedTest " nnoremap t RunRubyFocusedContext :call s:RunRubyFocusedContext() " map t :call RunTestFile() " map T :call RunNearestTest() " map a :call RunTests('') map c :w\|:!script/features map w :w\|:!script/features --profile wip Allnoremap Cnmap SuspendWithAutomticCD if !exists('s:GNU_SCREEN_AVAILABLE_P') if has('gui_running') " In GUI, $WINDOW is not reliable, because GUI process is independent from " GNU screen process. Check availability of executable instead. let s:GNU_SCREEN_AVAILABLE_P = executable('screen') else " In CUI, availability of executable is not reliable, because Vim may be " invoked with "screen ssh example.com vim" and GNU screen may be " available at example.com. Check $WINDOW instead. let s:GNU_SCREEN_AVAILABLE_P = len($WINDOW) != 0 endif endif command! -bar -nargs=0 SuspendWithAutomticCD \ call s:cmd_SuspendWithAutomticCD() function! s:cmd_SuspendWithAutomticCD() if s:GNU_SCREEN_AVAILABLE_P call s:activate_terminal() " \015 = " To avoid adding the cd script into the command-line history, " there are extra leading whitespaces in the cd script. silent execute '!screen -X eval' \ '''select another''' \ '''stuff " cd \"'.getcwd().'\" ' " \#\#,vim-auto-cd\015"''' redraw! let s:GNU_SCREEN_AVAILABLE_P = (v:shell_error == 0) endif if !s:GNU_SCREEN_AVAILABLE_P suspend endif endfunction function! s:activate_terminal() "{{{2 if !has('gui_running') return endif if has('macunix') " There is alternative way to activate, but it's slow: " !osascript -e 'tell application "Terminal" to activate the front window' silent !open -a Terminal else " This platform is not supported. endif endfunction " Show the lines which match to the last search pattern. " Cnmap g/ global//print " Cvmap g/ global//print " Ditto for quickfix Cnmap g/ :vimgrep ///j %:cw Cvmap g/ :vimgrep ///j %:cw nmap go nmap go (command-line-enter)Unite outline function! s:cmd_Fmap(prefix, suffix, args) " FIXME: This parsing may not be compatible with the original one. let [options, rest] = s:separate_list(a:args, \ '^\c<\(buffer\|expr\|script\|silent\|special\|unique\)>$') if len(rest) < 2 throw 'Insufficient number of arguments: ' . string(rest) endif let lhs = rest[0] let rhs = rest[1:] execute a:prefix.'noremap'.a:suffix join(options) lhs \ ':call' join(rhs) '' endfunction " Objmap - :map for text objects "{{{3 " " Keys for text objects should be mapped in Visual mode and Operator-pending " mode. The following commands are just wrappers to avoid DRY violation. command! -nargs=+ Objmap \ execute 'omap' \ | execute 'vmap' command! -nargs=+ Objnoremap \ execute 'onoremap' \ | execute 'vnoremap' command! -nargs=+ Objunmap \ execute 'ounmap' \ | execute 'vunmap' " Operatormap - :map for oeprators "{{{3 " " Keys for operators should be mapped in Normal mode and Visual mode. The " following commands are just wrappers to avoid DRY violation. " " FIXME: How about mapping to g@ in Operator-pending mode " to use {operator}{operator} pattern? command! -nargs=+ Operatormap \ execute 'nmap' \ | execute 'vmap' command! -nargs=+ Operatornoremap \ execute 'nnoremap' \ | execute 'vnoremap' command! -nargs=+ Operatorunmap \ execute 'nunmap' \ | execute 'vunmap' Fvmap * search_the_selected_text_literaly('n') Fvmap # search_the_selected_text_literaly('N') Fvmap ]] jump_section_v(']]') Fvmap ][ jump_section_v('][') Fvmap [[ jump_section_v('[[') Fvmap [] jump_section_v('[]') Fomap ]] jump_section_o(']]') Fomap ][ jump_section_o('][') Fomap [[ jump_section_o('[[') Fomap [] jump_section_o('[]') function! s:search_the_selected_text_literaly(search_command) let reg_0 = [@0, getregtype('0')] let reg_u = [@", getregtype('"')] normal! gvy let @/ = @0 call histadd('/', '\V' . escape(@0, '\')) execute 'normal!' a:search_command let v:searchforward = a:search_command ==# 'n' call setreg('0', reg_0[0], reg_0[1]) call setreg('"', reg_u[0], reg_u[1]) endfunction function! Preserve(command) let _s=@/ let l = line(".") let c = col(".") execute a:command let @/=_s call cursor(l, c) endfunction nmap _$ :call Preserve("%s/\\s\\+$//e") nmap _= :call Preserve("normal gg=G") function! Titlecase() if !executable("toTitleCase") echo "Missing toTitleCase excutable." return endif normal gv"xy let @x = system('echo "'.@x.'"| toTitleCase | tr -d "\n"') let @x = substitute(@x, '^\s*\(.\{-}\)\s*$', '\1', '') normal gv normal "xp endfunction vmap t :call Titlecase() inoremap nmap x (command-line-enter)sp =expand("%:h")/ inoremap =InsertTabWrapper() inoremap function! InsertTabWrapper() let col = col('.') - 1 if !col || getline('.')[col - 1] !~ '\k' return "\" else return "\" endif endfunction "}}}1 " Platform depends:"{{{1 " For Linux"{{{ if exists('$WINDIR') " Cygwin. " Use bash. set shell=bash else " Use zsh. set shell=sh endif " Set path. let $PATH = expand('~/bin').':/usr/local/bin/:'.$PATH " For non GVim. if !has('gui_running') " Enable 256 color terminal. if !exists('$TMUX') set t_Co=256 " For screen."{{{ if &term =~ '^screen' augroup MyAutoCmd " Show filename on screen statusline. " But invalid 'another' screen buffer. autocmd BufEnter * if $WINDOW != 0 && bufname("") !~ "[A-Za-z0-9\]*://" \ | silent! exe '!echo -n "kv:%:t\\"' | endif " When 'mouse' isn't empty, Vim will freeze. Why? autocmd VimLeave * :set mouse= augroup END " For Vim inside screen. set ttymouse=xterm2 endif " For prevent bug. autocmd MyAutoCmd VimLeave * set term=screen "}}} endif if has('gui') " Use CSApprox.vim " Convert colorscheme in Konsole. let g:CSApprox_konsole = 1 let g:CSApprox_attr_map = { 'bold' : 'bold', 'italic' : '', 'sp' : '' } else " Disable error messages. let g:CSApprox_verbose_level = 0 endif " Change cursor shape. " if &term =~ "xterm" " let &t_SI = "\]12;lightgreen\x7" " let &t_EI = "\]12;white\x7" " endif endif "}}}1 set secure " vim: foldmethod=marker