if !has('gui') " {{{ finish endif " }}} " neobundle {{{ if has('vim_starting') set runtimepath+=~/.vimbundles/neobundle.vim endif call neobundle#begin(expand('~/.vimbundles')) let g:neobundle#enable_name_conversion = 1 NeoBundle 'Shougo/neobundle.vim' NeoBundle 'Shougo/neobundle-vim-recipes' " NeoBundle 'Shougo/neocomplete', {'depends': [ " \ 'Shougo/neoinclude.vim', " \ 'Shougo/neco-syntax', " \ 'Shougo/neco-vim', " \ 'Shougo/neopairs.vim']} NeoBundle 'Shougo/deoplete.nvim', {'depends': [ \ 'roxma/nvim-yarp', \ 'roxma/vim-hug-neovim-rpc', \ 'Shougo/neoinclude.vim', \ 'Shougo/neco-syntax', \ 'Shougo/neco-vim', \ 'Shougo/neopairs.vim']} NeoBundle 'Shougo/unite.vim' NeoBundle 'Shougo/unite-ssh' NeoBundle 'Shougo/unite-build' NeoBundle 'Shougo/vimshell' NeoBundle 'Shougo/deol.nvim' NeoBundle 'Shougo/tabpagebuffer.vim' if has('mac') call neobundle#local("~/.vimbundles2", {}, \ ['vimproc']) else NeoBundle 'Shougo/vimproc', {'build': { \ 'windows': 'tools\\update-dll-mingw', \ 'cygwin': 'make -f make_cygwin.mak', \ 'mac': 'make -f make_mac.mak', \ 'linux': 'make', \ 'unix': 'gmake'}} endif NeoBundle 'Shougo/neosnippet-snippets', {'depends': 'Shougo/neosnippet'} NeoBundle 'Shougo/context_filetype.vim' NeoBundle 'eagletmt/ghcmod-vim' NeoBundle 'thinca/vim-ft-clojure' NeoBundle 'kana/vim-tabpagecd' NeoBundle 'kana/vim-filetype-haskell' NeoBundle 'kana/vim-smartchr' let s:vimrc_use_lexima = 1 if s:vimrc_use_lexima NeoBundle 'cohama/lexima.vim' else NeoBundle 'kana/vim-smartinput' NeoBundle 'cohama/vim-smartinput-endwise' endif NeoBundle 'vim-jp/vital.vim' NeoBundle 'thinca/vim-ref' NeoBundle 'veloce/vim-aldmeris' NeoBundle 'thinca/vim-quickrun' NeoBundle 'ujihisa/quicklearn' NeoBundle 'thinca/vim-poslist' NeoBundle 'trapd00r/neverland-vim-theme' NeoBundle 'vim-scripts/sudo.vim' NeoBundle 'eagletmt/neco-ghc' NeoBundle 'thinca/vim-showtime' NeoBundle 'thinca/vim-unite-history' NeoBundle 'chikatoike/concealedyank.vim' NeoBundle 'ujihisa/vimshell-ssh' NeoBundle 'ujihisa/ref-hoogle' NeoBundle 'vim-scripts/zenesque.vim' NeoBundle 'tyru/open-browser.vim' NeoBundle 'kossnocorp/perfect.vim' NeoBundle 'fatih/vim-go' NeoBundle 'vim-scripts/groovyindent' NeoBundle 'kana/vim-textobj-syntax', {'depends': 'kana/vim-textobj-user'} NeoBundle 'basyura/J6uil.vim' NeoBundle 'thinca/vim-fontzoom' NeoBundle 'vim-scripts/Colour-Sampler-Pack' NeoBundleLazy 'AndrewRadev/splitjoin.vim', { \ 'autoload': {'mappings': ['gS', 'gJ']}} NeoBundle 'git@github.com:ujihisa/unite-ruby-require.vim.git' NeoBundle 'osyo-manga/jplus' NeoBundle 'deris/rengbang' NeoBundle 'lambdalisue/gina.vim' NeoBundle 'kamichidu/vim-unite-javaimport', { \ 'depends': [ \ 'kamichidu/vim-javaclasspath']} NeoBundle 'mopp/autodirmake.vim' NeoBundle 'vim-scripts/haskell.vim' NeoBundle 'git@github.com:ujihisa/nclipper.vim.git' NeoBundle 'tpope/vim-surround' " NeoBundle 'ujihisa/neco-look' NeoBundle 'vim-scripts/Rainbow-Parenthsis-Bundle' NeoBundle 'rhysd/textobj-wiw', {'depends': 'kana/vim-textobj-user'} " NeoBundle 'terryma/vim-expand-region' NeoBundle 'ujihisa/unite-colorscheme' NeoBundle 'ujihisa/unite-haskellimport' NeoBundle 'tsukkee/unite-help' NeoBundle 'ujihisa/unite-locate' NeoBundle 'Shougo/unite-outline' NeoBundle 'altercation/vim-colors-solarized' NeoBundle 'derekwyatt/vim-scala' NeoBundle 'vim-ruby/vim-ruby' NeoBundleLazy 'thinca/vim-painter', { \ 'autoload': { \ 'commands': 'PainterStart', \ }} NeoBundleLazy 'Shougo/javacomplete' NeoBundle 'AndrewRadev/linediff.vim' NeoBundle 'ujihisa/vimport' NeoBundle 'tyru/caw.vim' NeoBundle 'ujihisa/ft-cmake' " NeoBundle 'Rip-Rip/clang_complete' NeoBundleLazy 'vim-jp/cpp-vim', { \ 'autoload': {'filetypes': 'cpp'}} NeoBundle 'ujihisa/unite-include-reversed' NeoBundle 'itchyny/calendar.vim' NeoBundle 'guns/vim-sexp' NeoBundle 'Shougo/neomru.vim', { \ 'depends': [ \ 'Shougo/unite.vim']} NeoBundle 'jimenezrick/vimerl' NeoBundle 'sickill/vim-monokai' " NeoBundle 'osyo-manga/vim-brightest' NeoBundle 'itchyny/vim-cursorword' NeoBundle 'ujihisa/neoclojure.vim' " NeoBundle 'ujihisa/ft-mongo.vim' call neobundle#local("~/.vimbundles", {}, \ ['ft-mongo', 'metaffer', 'neochat.vim']) NeoBundle 'chase/vim-ansible-yaml' NeoBundle 'rbtnn/mario.vim', { \ 'depends': [ \ 'rbtnn/game_engine.vim'] } NeoBundle 'rbtnn/puyo.vim' NeoBundle 'rbtnn/reversi.vim' NeoBundle 'kmnk/vim-unite-giti' NeoBundle 'kana/vim-operator-replace', { \ 'depends': [ \ 'kana/vim-operator-user'] } NeoBundle 'syngan/vim-vimlint', { \ 'depends': 'ynkdir/vim-vimlparser'} NeoBundle 'cohama/agit.vim' NeoBundle 'haya14busa/incsearch.vim' NeoBundle 'haya14busa/vim-asterisk' NeoBundle 'thinca/vim-themis' NeoBundle 'kana/vim-altr' NeoBundle 'reedes/vim-colors-pencil' NeoBundle 'yuku-t/vim-ref-ri' NeoBundle 'udalov/kotlin-vim' NeoBundle 'elixir-lang/vim-elixir' NeoBundle 'johngrib/vim-game-code-break' NeoBundle 'mrkn/vim-cruby' NeoBundle 'moznion/vim-ltsv' NeoBundle 'NLKNguyen/papercolor-theme' NeoBundle 'koron/translua-vim' NeoBundle 'leafgarland/typescript-vim' NeoBundle 'thinca/vim-prettyprint' if 0 NeoBundle 'Shougo/echodoc' " NeoBundle 'ujihisa/repl.vim' " NeoBundle 'Shougo/vimfiler' NeoBundle 'Shougo/vesting' " NeoBundle 'tpope/vim-fireplace' NeoBundle 'mattn/gist-vim', {'depends': 'mattn/webapi-vim'} NeoBundle 'mrkn/mrkn256.vim', 'light_background' NeoBundle 'shiracha/shiracha-vim' NeoBundle 'Pychimp/vim-luna' NeoBundle 'ujihisa/unite-font' NeoBundle 'ujihisa/unite-equery' NeoBundle 'ujihisa/unite-gem' NeoBundle 'kchmck/vim-coffee-script' endif call neobundle#end() filetype plugin indent on " }}} " augroup ujihisa-vimrc {{{ augroup ujihisa-vimrc autocmd! augroup END " }}} " g:V {{{ if !has_key(g:, 'V') let g:V = vital#of('vital') call extend(g:V, g:V.import('Prelude')) endif " }}} " settings {{{ set encoding=utf-8 set termencoding=utf-8 set fileformats=unix,dos,mac set ignorecase set smartcase set number set ruler set expandtab set hlsearch set splitbelow set splitright set switchbuf=useopen syntax enable set wildmode=list:longest set list set listchars=tab:>-,trail:-,extends:>,precedes:< set hidden set autoread set title set backspace=indent,eol,start set modeline set t_Co=256 set cmdheight=3 " http://vim-users.jp/2009/06/hack32/ " set directory-=. set directory=~/tmp/ " http://vim-users.jp/2010/07/hack162/ if has('persistent_undo') set undodir=~/.vimundo augroup ujihisa-vimrc autocmd BufReadPre ~/* setlocal undofile augroup END endif set equalalways set eadirection=ver set updatetime=500 "set scrolljump=10 set timeoutlen=300 set synmaxcol=700 set history=1000 set viminfo+=:1000 set display=lastline setglobal autoindent " setglobal cinkeys= setglobal shiftwidth=2 setglobal tabstop=2 " Some ftplugin sets tw=78 is tw is 0. Set this to extremely high " so that those ftplugins give up. " bad e.g. /usr/share/vim/vim74/ftplugin/gitcommit.vim set textwidth=9999999999999 set nobackup set spelllang=en,cjk " MacVim default is 5. Stupid set scrolloff=0 if has('balloon_eval') set noballooneval endif " scala " set wildignore+=*/target/* " disabled because this also disables :( " }}} " landscape / portrait detect {{{ function! s:is_display_landscape() return &lines * 2 < &columns endfunction " }}} " mappings {{{ let g:incsearch#auto_nohlsearch = 1 if g:V.is_mac() let g:transparency = 10 " for MacVim's bug " nnoremap :set nohlsearch:let &transparency = g:transparency else " incsearch " nnoremap :set nohlsearch end " insearch uses them " nnoremap / :set hlsearch/ " nnoremap ? :set hlsearch? " nnoremap * :set hlsearch* " nnoremap # :set hlsearch# command! -nargs=0 Amp execute 'normal!' printf('/\<%s\>', expand('')) nnoremap & :set hlsearch:Amp vmap p (operator-replace) nnoremap -- :e %:h omap p % omap % nmap p % nmap % vmap p % vmap % nnoremap vv "nnoremap ]p p`[=`] nnoremap sh h:call good_width() nnoremap sj j nnoremap sk k nnoremap sl l:call good_width() nnoremap H H:call good_width() nnoremap sJ J nnoremap sK K nnoremap L L:call good_width() function! s:good_width() let size = 84 if winwidth(0) < size execute "vertical resize" size endif endfunction nnoremap q nnoremap Q q " for plugins rewrite j/k nnoremap j nnoremap k nnoremap w :write nnoremap q :quit " nnoremap q :hide nnoremap Q :quit! nnoremap . :OpenVimrcTab "nnoremap ] ] noremap j noremap k " undoable inoremap u inoremap u inoremap cnoremap "nnoremap a nnoremap aa :tabnew:pwd:VimShell nnoremap av :tabnew:cd ~/.vimbundles:VimShell nnoremap an :tabnew:cd ~/:VimShell "nnoremap ac :tabclose nnoremap aj :execute 'tabnext' 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$'):redraw " nnoremap :execute 'tabnext' 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$'):redraw nnoremap :execute 'tabnext' 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$'):redraw inoremap :execute 'tabnext' 1 + (tabpagenr() + v:count1 - 1) % tabpagenr('$'):redraw nnoremap ak gT " nnoremap gT nnoremap gT inoremap gT nnoremap :e # nnoremap :NeoSnippetEdit -split nnoremap Y y$ nnoremap co zo nnoremap cc zc " use mark `m for , and nnoremap mmggVG vnoremap "+yG`m vnoremap Y "+y "inoremap k smartchr#one_of('k', "\") " memo: " MacBook Pro Apple Keyboard (both built-in and bluetooth) Gentoo (with xmodmap?) " Command = and " inoremap TabOrCompl() " function! TabOrCompl() " return (col('.') == 1 || matchstr(getline('.'), '.', col('.')-2) == "\t") ? "\\" : "\" " endfunction nnoremap s q:set filetype= nnoremap S q:set filetype= nnoremap sr :set filetype=ruby "nnoremap sm :set filetype=markdown "nnoremap sh :set filetype=haskell "nnoremap sj :set filetype=javascript nnoremap spp :set filetype=phpierror_reporting(E_ERROR \| E_WARNING \| E_PARSE \| E_NOTICE \| E_STRICT); "nnoremap shs :set filetype=haskelli{-# LANGUAGE OverloadedStrings #-}import qualified Data.Text as Timport qualified Data.Text.IO as Tmain = doprint $ nnoremap shs :set filetype=haskellimain = doprint $ nnoremap ssl :set filetype=scala nnoremap scl :set filetype=clojure nnoremap ssh :set filetype=sh nnoremap b 100+ nnoremap I $i "nnoremap C $C nnoremap X ^x nnoremap cp Pjdd " nnoremap // /^ nnoremap s* ':%substitute/\<' . expand('') . '\>/' nnoremap n :new nnoremap N :call new_with_the_filetype() function! s:new_with_the_filetype() let f = &filetype new let &filetype = f endfunction " visual shifting (does not exit Visual mode) vnoremap < >gv " paste in insert mode is p while paste in command-line mode is ". " it's confusing. cnoremap p " cnoremap + " for speedup nnoremap /p /" " filetype specific key mappings silent nnoremap M :echo 'space-M Not defined' silent nnoremap m :echo 'space-m Not defined' " is to swap visual mode and select mode. is difficult to type. " Use Alt-g instead vnoremap g snoremap g nnoremap f nmap (openbrowser-open) vmap (openbrowser-open) " yank without newlines vnoremap gy y:let @" = substitute(@", "\n\s\*", ' ', 'g') " go insert new line below directly from insert mode inoremap o " }}} " kana/vim-smartinput {{{ if s:vimrc_use_lexima " let g:lexima_enable_basic_rules = 0 let g:lexima_enable_basic_rules = 0 let g:lexima_enable_newline_rules = 1 let g:lexima_enable_space_rules = 0 let g:lexima_enable_endwise_rules = 0 " jlj = call lexima#add_rule({ \ 'at': 'jl\%#', \ 'char': 'j', \ 'input': ''}) inoremap (vimrc-lexima-bs) lexima#expand('', 'i') else " call smartinput#clear_rules() let g:smartinput_no_default_key_mappings = 1 function! s:vimrc_smartinput_rules_add(x, ys) abort call smartinput#map_to_trigger('i', a:x[0], a:x[0], a:x[0]) call smartinput#map_to_trigger('i', a:x[1], a:x[1], a:x[1]) for y in a:ys call smartinput#define_rule(y) endfor endfunction " excerpt from smartinput itself call s:vimrc_smartinput_rules_add('()', [ \ {'at': '\%#', 'char': '(', 'input': '()'}, \ {'at': '\%#\_s*)', 'char': ')', 'input': '=smartinput#_leave_block('')'')'}, \ {'at': '(\%#)', 'char': '', 'input': ''}, \ {'at': '()\%#', 'char': '', 'input': ''}, \ {'at': '\\\%#', 'char': '(', 'input': '('}, \ {'at': '(\%#)', 'char': '', 'input': '"_S'}, \ ]) call s:vimrc_smartinput_rules_add('[]', [ \ {'at': '\%#', 'char': '[', 'input': '[]'}, \ {'at': '\%#\_s*\]', 'char': ']', 'input': '=smartinput#_leave_block('']'')'}, \ {'at': '\[\%#\]', 'char': '', 'input': ''}, \ {'at': '\[\]\%#', 'char': '', 'input': ''}, \ {'at': '\\\%#', 'char': '[', 'input': '['}, \ ]) call s:vimrc_smartinput_rules_add('{}', [ \ {'at': '\%#', 'char': '{', 'input': '{}'}, \ {'at': '\%#\_s*}', 'char': '}', 'input': '=smartinput#_leave_block(''}'')'}, \ {'at': '{\%#}', 'char': '', 'input': ''}, \ {'at': '{}\%#', 'char': '', 'input': ''}, \ {'at': '\\\%#', 'char': '{', 'input': '{'}, \ {'at': '{\%#}', 'char': '', 'input': '"_S'}, \ ]) call smartinput_endwise#define_default_rules() call smartinput#map_to_trigger('i', '(vimrc-smartinput-bs)', '', '') " jlj = call smartinput#map_to_trigger('i', 'j', 'j', 'j') call smartinput#define_rule({ \ 'at': 'jl\%#', \ 'char': 'j', \ 'input': ''}) " uiu = () call smartinput#map_to_trigger('i', 'u', 'u', 'u') call smartinput#define_rule({ \ 'at': 'ui\%#', \ 'char': 'u', \ 'input': '()'}) " {{ in scala string literal = ${} call smartinput#map_to_trigger('i', '{', '{', '{') call smartinput#define_rule({ \ 'at': '{\%#}', \ 'char': '{', \ 'input': '${', \ 'filetype': ['scala'], \ 'syntax': ['String']}) call smartinput#define_rule({ \ 'at': '{\%#', \ 'char': '{', \ 'input': '${}', \ 'filetype': ['scala'], \ 'syntax': ['String']}) " {{ in clojure string literal = ~{} call smartinput#define_rule({ \ 'at': '{\%#}', \ 'char': '{', \ 'input': '~{', \ 'filetype': ['clojure'], \ 'syntax': ['String']}) call smartinput#define_rule({ \ 'at': '{\%#', \ 'char': '{', \ 'input': '~{}', \ 'filetype': ['clojure'], \ 'syntax': ['String']}) " (( in clojure string literal = ~() call smartinput#map_to_trigger('i', '(', '(', '(') call smartinput#define_rule({ \ 'at': '(\%#)', \ 'char': '(', \ 'input': '~(', \ 'filetype': ['clojure'], \ 'syntax': ['String']}) call smartinput#define_rule({ \ 'at': '(\%#', \ 'char': '(', \ 'input': '~()', \ 'filetype': ['clojure'], \ 'syntax': ['String']}) " s: in c++ = std:: call smartinput#map_to_trigger('i', ':', ':', ':') call smartinput#define_rule({ \ 'at': '\:', \ 'filetype': ['cpp']}) " \ 'syntax': ['cBlock']}) " in vimshell closes popup in advance. call smartinput#map_to_trigger('i', '', '', '') call smartinput#define_rule({ \ 'at': '$\%#', \ 'char': '', \ 'input': '', \ 'filetype': ['vimshell', 'int-*']}) " in vimshell closes it when it's on the head " call smartinput#map_to_trigger('i', '', '', '') " call smartinput#define_rule({ " \ 'at': '\%#', " \ 'char': '', " \ 'input': '(vimshell_another_delete_backward_char)', " \ 'filetype': ['vimshell']}) endif "}}} " = for completion and for cancel {{{ inoremap = pumvisible() ? "\" : '=' inoremap = if s:vimrc_use_lexima " TODO imap deoplete#smart_close_popup() . "\(vimrc-lexima-bs)" else imap deoplete#smart_close_popup() . "\(vimrc-smartinput-bs)" endif " }}} " vimshell {{{ function! EmptyBufferP() return expand('%') ==# '' && !&modified endfunction "nnoremap v EmptyBufferP() ? ":VimShell" : ":new:VimShell" "nnoremap V EmptyBufferP() ? ":VimShell" : ":vnew:VimShell" "nmap V (vimshell_split_switch) "nmap v (vimshell_switch) nmap v (vimshell_split_switch) "nnoremap V :VimShellCreate -split " close vimshell from anywhere " nmap V (vimshell_split_switch)(vimshell_hide) nnoremap V :VimShellClose let g:vimshell_user_prompt = 'fnamemodify(getcwd(), ":~")' let g:vimshell_prompt = '$ ' let g:vimshell_split_command = 'split' let g:vimshell_scrollback_limit = 4000 let g:vimshell_interactive_update_time = 400 let g:vimshell_max_command_history = 100000 " default is 1000 let g:vimshell_editor_command = 'vim' " do not use 'gvim -g --servername=GVIM --remote-tab-wait-silent' augroup ujihisa-vimrc autocmd FileType vimshell call s:vimshell_local() augroup END function! s:vimshell_local() imap pumvisible() ? \ "\\" : \ "\(vimshell_another_delete_backward_char)" " to use smartinput " iunmap nmap j (vimshell_next_prompt) nmap k (vimshell_previous_prompt) " deleting (vimshell_delete_previous_output) nunmap nmap (vimshell_delete_previous_output) inoremap unite#sources#vimshell_history#start_complete(!0) endfunction augroup ujihisa-vimrc autocmd FileType int-* call s:vimshell_iexe() " TODO augroup END function! s:vimshell_iexe() "imap (vimshell_int_another_delete_backward_char) if 0 " Let's se.. nmap j (vimshell_int_next_prompt) nmap k (vimshell_int_previous_prompt) endif inoremap unite#sources#vimshell_history#start_complete(!0) endfunction let g:vimshell_escape_colors = [ \'#3c3c3c', '#ff6666', '#66ff66', '#ffd30a', '#1e95fd', '#ff13ff', '#1bc8c8', '#C0C0C0', \'#686868', '#ff6666', '#66ff66', '#ffd30a', '#6699ff', '#f820ff', '#4ae2e2', '#ffffff' \] " }}} " tag opens in a new window {{{ function! s:tagjump_in_new_window() execute "normal! \s\" "http://d.hatena.ne.jp/thinca/20110202 "UniteWithCursorWord -immediately -no-start-insert -auto-preview -default-action=split tag endfunction function! s:tagjump_or_cr() if bufname('%') == '[Command Line]' || &buftype == 'quickfix' return "\" else return "\" "http://d.hatena.ne.jp/thinca/20110202 "UniteWithCursorWord -immediately -no-start-insert -auto-preview tag endif endfunction nnoremap :call tagjump_in_new_window() nnoremap tagjump_or_cr() " }}} " unite-grep {{{ nnoremap sg :Unite grep:. -default-action=split nnoremap sG :execute 'Unite grep:.:-iR:' . expand('') . ' -default-action=split' " }}} " {{{ thinca/poslist.vim nmap (poslist-prev-pos) nmap (poslist-next-pos) vmap (poslist-prev-pos) " }}} " remote {{{ command! -nargs=1 RunOnVm !run_on_vm % " }}} " Neocomplecache/Neocomplete/Deoplete {{{ " let g:neocomplete#enable_at_startup = 1 " let g:neocomplete#max_list = 200 let g:deoplete#enable_at_startup = 1 let g:deoplete#max_list = 200 imap (neocomplete_start_unite_complete) " see also " * snippets section let g:neocomplete#skip_auto_completion_time = "" " disabling it let g:necoghc_enable_detailed_browse = 1 let g:neocomplete#lock_iminsert = 1 function! s:my_cr_function() abort return deoplete#close_popup() . "\" endfunction if s:vimrc_use_lexima " why doesn't lexima need deoplete#close_popup()? else inoremap =my_cr_function() end if filereadable('/usr/local/opt/python3/bin/python3.6') let g:python3_host_prog = '/usr/local/opt/python3/bin/python3.6' endif " }}} " thinca's local vimrc http://vim-users.jp/2009/12/hack112/ {{{ " Load settings for eacy location. augroup ujihisa-vimrc autocmd BufNewFile,BufReadPost * call s:vimrc_local(expand(':p:h')) augroup END function! s:vimrc_local(loc) let files = findfile('.vimrc.local', escape(a:loc, ' ') . ';', -1) for i in reverse(filter(files, 'filereadable(v:val)')) source `=i` endfor endfunction " }}} function! OpenVimrcTab() " {{{ tabnew cd ~/git/config edit ~/git/config/_vimrc endfunction " }}} " My commands {{{ command! -nargs=0 OpenVimrcTab call OpenVimrcTab() command! -nargs=0 Ctags call Ctags() function! Ctags() let cmdname = globpath(&rtp, 'plugin/vimproc.vim') != '' ? 'VimProcBang' : '!' execute cmdname 'ctags -R' NeoCompleteTagMakeCache endfunction " }}} command! SplitNicely call s:split_nicely() " {{{ function! s:split_nicely() if 80*2 * 15/16 <= winwidth(0) " FIXME: threshold customization vsplit else split endif endfunction " }}} " unite {{{ if globpath(&rtp, 'plugin/unite.vim') != '' nnoremap s nnoremap sS :Unite file_rec -default-action=split -direction=rightbelow nnoremap ss :Unite file_rec/git file -default-action=split -direction=rightbelow -hide-source-names nnoremap se :Unite file_rec/async nnoremap so :Unite outline -auto-preview -buffer-name=outline nnoremap sc :Unite colorscheme -auto-preview nnoremap sf :UniteWithBufferDir file_rec -default-action=split nnoremap sm :Unite file_mru -default-action=split nnoremap sb :Unite buffer -default-action=split nnoremap sre :Unite ref/man ref/hoogle ref/pydoc -default-action=split nnoremap su :Unite history/command source command nnoremap sp :Unite process -no-split -buffer-name=process nnoremap sq :UniteClose build "nnoremap M :Unite -buffer-name=build -no-focus build:: "nnoremap m :write:Unite -buffer-name=build -no-focus build: endif augroup ujihisa-vimrc autocmd GUIEnter * \ call unite#custom#profile('default', 'context', { \ 'vertical': 1, \ 'no_split': !s:is_display_landscape(), \ 'start_insert': 1}) autocmd VimResized * \ call unite#custom#profile('default', 'context', { \ 'vertical': 1, \ 'no_split': !s:is_display_landscape(), \ 'start_insert': 1}) augroup END " I wanted to simply refer the default ignore pattern with using g:unite_source_file_rec_ignore_pattern, but unite sets it lazily. " here I force unite defining file_rec and referes the default value. "let s:file_rec_ignore_pattern = (unite#sources#rec#define()[0]['ignore_pattern']) . '\|\$global\|\.class$\|\' " added "lib_managed" if 0 let s:file_rec_ignore_pattern = (unite#sources#rec#define()[0]['ignore_pattern']) . '\|\$global\|\.class$\|\\|\' call unite#custom#source('file_rec', 'ignore_pattern', s:file_rec_ignore_pattern) call unite#custom#source('grep', 'ignore_pattern', s:file_rec_ignore_pattern) else " let s:unite_file_rec_ignore_globs = unite#sources#rec#define()[0]['ignore_globs'] + ['**/target/**', 'lib_managed'] let s:unite_file_rec_ignore_globs = ['**/target/**', 'lib_managed', '.vagrant/**'] call unite#custom#source('file_rec', 'ignore_globs', s:unite_file_rec_ignore_globs) let s:unite_grep_ignore_globs = unite#sources#grep#define()['ignore_globs'] + ['**/target/**', 'lib_managed', '.vagrant'] call unite#custom#source('grep', 'ignore_globs', s:unite_grep_ignore_globs) endif let g:unite_source_file_rec_max_cache_files = 9000 if executable('ag') let g:unite_source_grep_command = 'ag' let g:unite_source_grep_default_opts = \ '-i --vimgrep --hidden --ignore ' . \ '''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'' --ignore tags --ignore target' let g:unite_source_grep_recursive_opt = '' endif "let g:unite_quick_match_table = { " \'a' : 1, 's' : 2, 'd' : 3, 'f' : 4, 'g' : 5, 'h' : 6, 'j' : 7, 'k' : 8, 'l' : 9, ':' : 10, " \'q' : 11, 'w' : 12, 'e' : 13, 'r' : 14, 't' : 15, 'y' : 16, 'u' : 17, 'i' : 18, 'o' : 19, 'p' : 20, " \'1' : 21, '2' : 22, '3' : 23, '4' : 24, '5' : 25, '6' : 26, '7' : 27, '8' : 28, '9' : 29, '0' : 30, " \} " in other words, it just swaps : and ; let g:unite_source_process_enable_confirm = 0 function! s:unite_my_settings() silent! nunmap silent! nunmap silent! iunmap silent! iunmap silent! nunmap " swapping q and Q nmap Q (unite_exit) nmap q (unite_all_exit) " overwrite p (preview) as print nmap p (unite_print_candidate) endfunction augroup ujihisa-vimrc autocmd FileType unite call s:unite_my_settings() augroup END " }}} " Big {{{ " " ^big = Big if !s:vimrc_use_lexima call smartinput#map_to_trigger('i', 'g', 'g', 'g') call smartinput#define_rule({ \ 'at': '^bi\%#', \ 'char': 'g', \ 'input': 'Big', \ 'filetype': ['vim']}) endif command! Big wincmd _ | wincmd | " }}} if has('mac') " {{{ " Option+Arrow keys set =OC set =OD set =OA set =OB nnoremap > nnoremap nnoremap + nnoremap - " Arrow keys nnoremap  l nnoremap  h nnoremap  nnoremap  " Shift+Arrow keys (actually I cannot use it on a terminal) nnoremap O2C :bn nnoremap O2D :bp nnoremap O2A i上 nnoremap O2B i下 " arrow and arrow keys nnoremap  j nnoremap  k endif " }}} augroup RubyTrunk " {{{ autocmd! autocmd BufWinEnter,BufNewFile ~/git/ruby/*.c setl ts=8 noexpandtab autocmd BufWinEnter,BufNewFile ~/git/ruby/*.y setl ts=8 noexpandtab "autocmd BufWinEnter,BufNewFile ~/rubies/src/**/*.c setl ts=8 noexpandtab augroup END " }}} " quickrun for thinca {{{ let g:quickrun_no_default_key_mappings = 0 " suspend to map r nmap r (quickrun) vmap r (quickrun) nmap R (quickrun-op) let g:quickrun_config = {} let g:quickrun_config._ = {'runner': 'vimproc', 'split': 'below'} " let g:quickrun_config._ = {'runner': 'job', 'split': 'below'} "let g:quickrun_config.coffee = {'command': 'coffee', 'exec': '%c -cpb %s'} let g:quickrun_config.coffee = {'command': '~/node_modules/.bin/coffee', 'cmdopt': '-pb'} let g:quickrun_config.asm = {'command': 'gcc', 'exec': ['gcc %s -o ./aaaaa', './aaaaa', 'rm ./aaaaa']} " let g:quickrun_config.textile = { " \ 'command': 'redcloth', " \ 'tempfile': '%{tempname()}.textile', " \ 'exec': ['%c %s > %s:p:r.html', 'open %s:p:r.html', 'sleep 1', 'rm %s:p:r.html'] } " let g:quickrun_config['R'] = {'command': 'R', 'exec': ['%c -s --no-save -f %s', ':%s/.\b//g']} let g:quickrun_config['markdown'] = {'outputter': 'browser'} let g:quickrun_config.lua = {'type': 'lua/vim'} let g:quickrun_config.javascript = {'type': 'javascript/nodejs'} " let s:clojure_libs = split(glob('~/.m2/repository/org/clojure/core.*/*/*.jar'), "\n") " let g:quickrun_config.clojure = { " \ 'type': 'clojure/concurrent_process', " \ 'command': printf( " \ 'java -cp %s:/usr/share/clojure-1.6/lib/clojure.jar clojure.main', " \ join(s:clojure_libs, ':'))} let g:quickrun_config.clojure = { \ 'runner': 'neoclojure', 'command': 'dummy', \ 'tempfile': '%{tempname()}.clj'} " \ 'unnamed_projdir': '/tmp/neoclojure-quickrun'} " let g:quickrun_config.scala = { " \ 'cmdopt': g:quickrun#default_config.scala.cmdopt . ' -deprecation'} " let g:quickrun_config.scala = {'type': 'scala/concurrent_process', 'command': 'scala-2.11'} let g:quickrun_config.scala = {'type': 'scala/concurrent_process', 'command': 'sbt console'} let g:quickrun_config.cpp = { \ 'type': 'cpp/clang++', \ 'cmdopt': '-std=c++11 -Wall -Wextra'} let g:quickrun_config.jq = { \ 'cmdopt': '.'} " \ 'erlang': { " \ 'command': 'escript', " +\ 'exec': ['echo "#!escript\n%%%%! -smp enable -sname quickrun -mnesia debug verbose" > %s.tmp', 'cat %s >> %s.tmp', 'mv %s.tmp %s', '%c %s %a', ':call delete("%s.tmp")', ':call delete("%s")'], " +\ 'tempfile': '{fnamemodify(tempname(), ":h")}/quickrun', " \ }, " }}} " filetype aliases http://vim-users.jp/2010/04/hack138/ {{{ augroup FiletypeAliases autocmd! autocmd FileType md set filetype=markdown autocmd FileType js set filetype=javascript autocmd FileType cf set filetype=coffee augroup END " }}} " for gina {{{ augroup vimrc-local autocmd FileType diff nnoremap q :quit autocmd FileType git nnoremap q :quit augroup END nnoremap gd :Gina diff --opener=vsplit nnoremap gD :Gina diff --no-prefix --opener=vsplit nnoremap gs :Gina status --opener=vsplit nnoremap gh :Gina show --opener=vsplit nnoremap ga :Gina add % nnoremap gc :Gina commit --verbose --opener=vsplit nnoremap gp :Gina!! push nnoremap go :Gina changes HEAD~ --opener=vsplit " }}} " html {{{ function! s:HtmlEscape() silent s/&/\&/eg silent s//\>/eg endfunction function! s:HtmlUnEscape() silent s/<//eg silent s/&/\&/eg endfunction vnoremap e :call HtmlEscape() vnoremap ue :call HtmlUnEscape() " }}} " kana's useful tab function {{{ function! s:move_window_into_tab_page(target_tabpagenr) " Move the current window into a:target_tabpagenr. " If a:target_tabpagenr is 0, move into new tab page. if a:target_tabpagenr < 0 " ignore invalid number. return endif let original_tabnr = tabpagenr() let target_bufnr = bufnr('') let window_view = winsaveview() if a:target_tabpagenr == 0 tabnew tabmove " Move new tabpage at the last. execute target_bufnr 'buffer' let target_tabpagenr = tabpagenr() else execute a:target_tabpagenr 'tabnext' let target_tabpagenr = a:target_tabpagenr topleft new " FIXME: be customizable? execute target_bufnr 'buffer' endif call winrestview(window_view) execute original_tabnr 'tabnext' if 1 < winnr('$') close else enew endif execute target_tabpagenr 'tabnext' endfunction " }}} " ao move current buffer into a new tab. {{{ "nnoremap ao :call move_window_into_tab_page(0) nnoremap ao T " }}} " open lib and corresponding test at a new tab {{{ command! -nargs=1 Lib call s:open_lib_and_corresponding_test() function! s:open_lib_and_corresponding_test(fname) execute 'tabnew lib/' . a:fname . '.rb' execute 'vnew spec/' . a:fname . '_test.rb' execute "normal \(quickrun)\J\7_" endfunction " }}} " gist.vim {{{ if g:V.is_mac() let g:gist_clip_command = 'pbcopy' else let g:gist_clip_command = 'xclip -selection clipboard' endif let g:gist_detect_filetype = 1 let g:gist_open_browser_after_post = 1 " }}} command! LeftSpace call s:left_space() " {{{ function! s:left_space() let bufname = printf('[leftspace:%s]', tabpagenr()) let bufnr = bufnr(bufname) " FIXME: escape. let winnr = bufwinnr(bufnr) if winnr == -1 " create execute "topleft 20vnew " . bufname setlocal nomodifiable wincmd p else " destroy execute winnr "wincmd w" wincmd c wincmd p endif endfunction " }}} " Substitute all spaces for indentation to underlines {{{ " " before: " def aaa " hi " end " after: " def aaa " __hi " end command! -nargs=0 LeadUnderscores %s/^\s*/\=repeat('_', strlen(submatch(0)))/g " }}} " Require secret password file {{{ if filereadable(expand('~/.vimrc_secret')) source ~/.vimrc_secret endif " This file should let following variables: " * g:lingr_vim_user " * g:lingr_vim_password " }}} " Rename (See Vim Hacks #17) {{{ command! -nargs=1 -complete=file Rename f |call delete(expand('#')) " }}} " mspec/rubyspec supports {{{ function! DoMspec() new read! /usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t ~/git/ruby-trunk/ruby19/bin/ruby # call append(line('$'), '--------------------------------------------------------------') normal G read! /usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t ~/rubies/bin/ruby191 # call append(line('$'), '--------------------------------------------------------------') normal G read! /usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t ~/rubies/bin/ruby187 # call append(line('$'), '--------------------------------------------------------------') normal G read! /usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t /opt/local/bin/ruby # call append(line('$'), '--------------------------------------------------------------') normal G read! /usr/bin/ruby ~/git/ruby-trunk/spec/mspec/bin/mspec -t /usr/bin/ruby # endfunction " }}} " Haskell Tag {{{ if 0 " see also: ~/bin/update-cabal-tags set tag+=~/.cabal/tags endif " }}} " thinca vim development environment {{{ " http://d.hatena.ne.jp/thinca/20100216/1266294717 " Load settings for each location. augroup vimrc-local autocmd! autocmd BufNewFile,BufReadPost * call s:vimrc_local(expand(':p:h')) augroup END function! s:vimrc_local(loc) let files = findfile('vimrc_local.vim', escape(a:loc, ' ') . ';', -1) for i in reverse(filter(files, 'filereadable(v:val)')) source `=i` endfor endfunction if exists('g:loaded_vimrc') && g:loaded_vimrc == 0 call s:vimrc_local(getcwd()) endif let g:loaded_vimrc = 1 " }}} " ] for completion (dirty hack) {{{ " see also: hack #135 "augroup CloseOrCompl " autocmd! " autocmd BufWinEnter,BufNewFile ~/blog/dre/*.txt inoremap ] CloseOrCompl() "augroup END "inoremap ] searchpair('\[', '', '\]', 'nbW', 'synIDattr(synID(line("."), col("."), 1), "name") =~? "String"') ? ']' : "\" " inoremap ] searchpair('\[', '', '\]', 'nbW', 'synIDattr(synID(line("."), col("."), 1), "name") =~? "String"') ? ']' : pumvisible() ? "\" : "\\\" " }}} " Open junk file. by Shougo "{{{ command! -nargs=0 JunkFile call s:open_junk_file() function! s:open_junk_file() let l:junk_dir = $HOME . '/.Trash/vim_junk'. strftime('/%Y/%m') if !isdirectory(l:junk_dir) call mkdir(l:junk_dir, 'p') endif let l:filename = input('Junk Code: ', l:junk_dir.strftime('/%Y-%m-%d-%H%M%S.')) if l:filename != '' execute 'edit ' . l:filename endif endfunction " }}} " vim filetype specific conf in general {{{ " also for No Command-line window by Shougo http://vim-users.jp/2010/07/hack161/ nnoremap (command-line-enter) q: xnoremap (command-line-enter) q: nnoremap (command-line-norange) q: nmap : (command-line-enter) xmap : (command-line-enter) imap (command-line-enter) " I added "nnoremap q: q: augroup ujihisa-vimrc autocmd CmdwinEnter * call s:init_cmdwin() augroup END " MacVim is shit augroup ujihisa-vimrc autocmd CmdwinEnter * nnoremap CmdwinRun() autocmd CmdwinEnter * inoremap CmdwinRun() augroup END function! CmdwinRun() let a = getline(line('.')) return "\\\:" . a . "\" endfunction function! s:cmdwin_backslash() return matchstr(getline('.'), '\w\+') =~# '^s\(ubstitute\)\?$' ? '\' : smartchr#one_of('~/', '\') endfunction inoremap (vimrc_cmdwin_close) :quit function! s:init_cmdwin() inoremap pumvisible() ? "\\" : "\" inoremap pumvisible() ? "\\" : "\" "inoremap pumvisible() ? "\\" : "\" "I added imap col('.') == 1 ? \ "\(vimrc_cmdwin_close)" : \ pumvisible() ? \ "\\" : \ "\" inoremap : col('.') == 1 ? "VimProcBang " : col('.') == 2 && getline('.')[0] == 'r' ? "VimProcRead " : ":" "inoremap \ smartchr#one_of('~/', '\') inoremap \ deoplete#close_popup() . cmdwin_backslash() " Completion. "inoremap pumvisible() ? "\" : "\" " nnoremap! q :quit inoremap expand('%:h') startinsert! endfunction "function! s:vimrc_vim() " " to disable sw= -> swapfile= auto completion " inoremap w= w= "endfunction "augroup vimrc-vim " autocmd! " autocmd FileType vim call vimrc_vim() "augroup END " }}} " load PATH from ~/.zshrc {{{ "function! LoadPathFromZshrc() " for cmd in split(system("~/bin/loadpathfromzshrc"), "\n") " execute cmd " endfor "endfunction "call LoadPathFromZshrc() " }}} " few {{{ function! s:vimrc_few() abort let path = expand('~/git/few/bin/few') if filereadable(path) execute 'QuickRun ruby' path else echoerr printf("'%s' not found", path) endif endfunction command! -nargs=0 Few call vimrc_few() " }}} " Swap window without moving cursor {{{ " https://gist.github.com/654701 "nmap j (swap-window-down-no-cursor-move) "nmap k (swap-window-up-no-cursor-move) nmap h (swap-window-left-no-cursor-move) nmap l (swap-window-right-no-cursor-move) nnoremap (swap-window-down-no-cursor-move) :call swap_with_wincmd(v:count1, 'j') nnoremap (swap-window-up-no-cursor-move) :call swap_with_wincmd(v:count1, 'k') nnoremap (swap-window-left-no-cursor-move) :call swap_with_wincmd(v:count1, 'h') nnoremap (swap-window-right-no-cursor-move) :call swap_with_wincmd(v:count1, 'l') function! s:swap_with_wincmd(n, dir) let curwin = winnr() execute a:n 'wincmd' a:dir let targetwin = winnr() wincmd p call s:swap_window(curwin, targetwin) endfunction function! s:swap_window(curwin, targetwin) let curbuf = winbufnr(a:curwin) let targetbuf = winbufnr(a:targetwin) if curbuf == targetbuf " TODO: Swap also same buffer! else execute 'hide' targetbuf . 'buffer' execute a:targetwin 'wincmd w' execute curbuf 'buffer' wincmd p " Behave like x ? endif endfunction " }}} " copy the current file name {{{ command! -nargs=0 CopyTheCurrentFileName let @+ = expand('%') " }}} " unite-neco {{{ let s:unite_source = {'name': 'neco'} function! s:unite_source.gather_candidates(args, context) let necos = [ \ "~(-'_'-) goes right", \ "~(-'_'-) goes right and left", \ "~(-'_'-) goes right quickly", \ "~(-'_'-) skips right", \ "~(-'_'-) -8(*'_'*) go right and left", \ "(=' .' ) ~w", \ ] return map(necos, '{ \ "word": v:val, \ "source": "neco", \ "kind": "command", \ "action__command": "Neco " . v:key, \ }') endfunction call unite#define_source(s:unite_source) " }}} " PATH {{{ command! -nargs=1 AddPath let $PATH = expand() . ':' .$PATH AddPath /usr/bin AddPath /usr/local/bin AddPath /sbin AddPath /usr/sbin AddPath ~/.vimbundles/themis/bin/ " pip install --user AddPath ~/.local/bin if isdirectory(expand('~/bin')) AddPath ~/bin endif AddPath /home/ujihisa/git/termtter/bin AddPath /home/ujihisa/git/ruby/local/bin AddPath /home/ujihisa/src/llvm-git-build/local/bin AddPath /home/ujihisa/git/Gyazo-for-Linux/ " AddPath ~/.gem/bin if has('mac') AddPath ~/.rbenv/versions/2.3.1/bin/ AddPath ~/.gem/ruby/2.4.0/bin/ else AddPath ~/.rbenv/shims " AddPath ~/.rbenv/versions/2.5.0/bin endif " }}} " macvim proportional {{{ function! Proportional() set guifontwide= set macproportionalfont endfunction command! -nargs=0 Proportional call Proportional() " }}} " last two digit move {{{ " inspired by tavis' emacs voice line number movement feature "command! -count=1 -nargs=0 LastTwoDigitMove call LastTwoDigitMove() "function! LastTwoDigitMove(bound) " " for example when you are at line num 123 and typed 3gl " " getpos('.')[1] is 123 " " a:bound is 125 " " the goal is 103 " let current = getpos('.')[1] " let to = current / 100 * 100 + a:bound - current + 1 " execute to "endfunction "nnoremap gl :LastTwoDigitMove " version 2.0 " thanks MarcWeber " not it's not only two-digit command! -count=1 -nargs=0 GoToTheLine silent execute getpos('.')[1][:-len(v:count)-1] . v:count nnoremap gl :GoToTheLine " }}} " Haskell Type {{{ function! s:haskell_type(fname, expression) if filereadable(a:fname) let fname = a:fname else let fname = tempname() call writefile(getline(0, '$'), fname, 'b') "return {'left': printf("File not found: %s", a:fname)} endif let r = ref#system(['ghc-mod', 'type', fname, 'main', a:expression]) if r.result != 0 return {'left': r.stderr} endif return {'right': r.stdout} endfunction command! -nargs=1 HaskellType echo s:haskell_type(expand('%'), ) " }}} " echodoc {{{ let g:echodoc_enable_at_startup = 0 " }}} " echodoc for clojure {{{ "let s:clojure_doc_dict = { " \ 'name': 'clojure', " \ 'rank': 10, " \ 'filetypes' : {'clojure': 1}, " \ } "let s:P = g:V.import('ProcessManager') "function! s:clojure_doc_dict.search(cur_text) " let tmp = matchlist(a:cur_text, "\\([a-z][a-z0-9.'_]*\\)\\s*$") " let tmp = filter(tmp, 'v:val != ""') " if len(tmp) == 2 " let query = tmp[1] " else " return [] " endif " let t = s:P.touch('vimrc-echodoc-clojure', 'clojure-1.5') " if t ==# 'new' " call s:P.read_wait('vimrc-echodoc-clojure', 2.0) " call s:P.writeln('vimrc-echodoc-clojure', '(ns vim-ref (:use [clojure.repl :only (doc find-doc)]))') " endif " call s:P.writeln('vimrc-echodoc-clojure', printf('(doc %s)', query)) " let result = s:P.read('vimrc-echodoc-clojure')[0] " let result = get(matchlist(result, printf('[a-z.]\+/%s', query)), 0, '') " return [ " \ {'text': query, 'highlight': 'Identifier'}, " \ {'text': ' ' . substitute(string(result), '\n', "", "")}] "endfunction "call echodoc#register('clojure', s:clojure_doc_dict) " }}} " testing neco-ghc {{{ "nnoremap :e ~/.vimbundles/neco-ghc/fixtures/a.hs " }}} " vim-ref {{{ let $MANPAGER='cat' "call ref#rmcache() " let g:ref_clojure_cmd = [ " \ 'java', '-XX:+TieredCompilation', '-XX:TieredStopAtLevel=1', '-Xverify:none', " \ '-cp', '/usr/share/clojure-1.5/lib/clojure.jar', 'clojure.main'] let g:ref_clojure_use_persistent = 1 " }}} " special git log viewer {{{ function! s:git_log_viewer() abort if s:is_display_landscape() vnew else new endif "VimProcRead git log -u 'HEAD@{1}..HEAD' --reverse VimProcRead git log -u 'ORIG_HEAD..HEAD' -- set filetype=git.git-log.git-diff setl foldmethod=expr setl foldexpr=getline(v:lnum)!~'^commit' endfunction command! GitLogViewer call s:git_log_viewer() function! s:cd_pull_log(path) abort tabnew execute 'cd' expand(a:path) VimShell GitLogViewer wincmd L endfunction command! -nargs=1 CdPullLog call s:cd_pull_log() " }}} " disable macvim vimrc_examples {{{ let g:no_vimrc_example = 1 " }}} " Git Diff -> The file {{{ function! SGoDiff() let [maybe, fname] = s:latest_fname() if maybe ==# 'nothing' echoerr 'failed to find the filename' return endif let [maybe, linenum] = s:latest_linenum() if maybe ==# 'nothing' echoerr 'failed to find the linenum' return endif execute "vnew" fname execute linenum execute "normal! z\" endfunction augroup vimrc-sgodiff autocmd! autocmd FileType git-diff nnoremap :call SGoDiff() augroup END function! s:latest_fname() for i in reverse(range(1, line('.'))) if getline(i) =~ '^+++ ' return ['just', substitute(getline(i)[4:], '\t.*$', '', 'b')] endif endfor return ['nothing', ''] endfunction function! s:latest_linenum() for i in reverse(range(1, line('.'))) if getline(i) =~ '^@@ ' let a = matchlist(getline(i), '^@@ -.\{-},.\{-} +\(.\{-}\),') if exists('a[1]') return ['just', a[1]] endif endif endfor return ['nothing', ''] endfunction " }}} " yet another star {{{ "function! s:star_with_smartcase() " set hlsearch " echo expand('') " execute printf('/\<%s\>', expand('')) "endfunction "nnoremap * :call star_with_smartcase() " }}} " vital toplevel func for hand-testing {{{ command! Letv let V = vital#__latest__#new() | echo 'V: ' . string(keys(V)) " }}} " setl list is very often {{{ " nnoremap ` :setl list! function! s:toggle_wrap() setlocal wrap! if exists('b:interactive.terminal.wrap') let b:interactive.terminal.wrap = &l:wrap endif endfunction nnoremap ` :silent call toggle_wrap() " }}} " too much t). I dont' use ). ) should be t). {{{ onoremap ) t) onoremap ( t( vnoremap ) t) vnoremap ( t( " I don't use [(, so I remap [. onoremap ] t] onoremap [ t[ vnoremap ] t] "vnoremap [ t[ " }}} " hack 104 http://vim-users.jp/2009/11/hack104/ {{{ vnoremap * "vy/\V=substitute(escape(@v,'\/'),"\n",'\\n','g') " }}} " MacVim is unko {{{ function! s:macvim_is_unko() abort let rtp = split(&rtp, ',') unlet rtp[index(rtp, '/Applications/MacVim.app/Contents/Resources/vim/plugins/kaoriya')] let &rtp = join(rtp, ',') endfunction call s:macvim_is_unko() " }}} " golden ratio {{{ command! -nargs=0 GoldenRatio execute 'vertical resize' &columns * 5 / 8 nnoremap ] :GoldenRatio " }}} " unite-transparency {{{ let s:unite_source = {'name': 'transparency', 'action_table': {'*': {}} } " avoid triple closes function! s:unite_source.gather_candidates(args, context) return map(range(0, 100, 4), '{ \ "word": v:val, \ "source": "transparency", \ "kind": "command", \ "action__command": "set transparency=" . v:val, \ }') endfunction let s:unite_source.action_table.preview = { \ 'description': 'preview this transparency', 'is_quit': 0 } function! s:unite_source.action_table.preview.func(candidate) execute a:candidate.action__command endfunction call unite#define_source(s:unite_source) " }}} " quickrun + haskell = infinite loop {{{ command! -nargs=0 KillHaskell execute '!killall runghc' | execute '!killall ghc' " }}} " conceallevel changer {{{ nnoremap ` :setl conceallevel=0 " }}} " :TOhtmlAndBrowse {{{ " http://d.hatena.ne.jp/tyru/20110710/tenuki " changing command name from TOhtmlAndBrowse to TOhtmAndBrowse to avoid Vim bug " also.. it doesn't delete the file because this computer is slow.. command! \ TOhtmAndBrowse \ call s:TOhtmlAndBrowse() function! s:TOhtmlAndBrowse() TOhtml " begin callback...? %s/font-family: monospace/font-family: Myriad Pro/ %s/.lnr { /\0font-family: monospace; / %s/^[ 0-9]\+<\/span> */\0<\/font>/ %s/\s*[0-9]\+\s*<\/span>\zs \+\ze/\='' . repeat("_", len(submatch(0))) . "<\/font>"/g " end saveas `=tempname()` let save = get(g:, 'openbrowser_open_filepath_in_vim') let g:openbrowser_open_filepath_in_vim = 0 try OpenBrowser file://% finally let g:openbrowser_open_filepath_in_vim = save endtry "sleep 1 "call delete(expand('%')) endfunction " }}} " ENV {{{ if !$LANG let $LANG='en_US.UTF-8' endif " http://lingr.com/room/vim/archives/2011/09/19#message-4881743 " }}} " for vital spec {{{ " /Users/ujihisa/git/MacVim/src/MacVim/build/Release/MacVim.app/Contents/MacOS/Vim -g -u NONE -i NONE -N --cmd 'filetype indent on' -S spec/data/string.vim -c 'Fin /tmp/prelude.result' " }}} " neosnippet {{{ imap (pumvisible() && neosnippet#expandable()) ? \ "\(neosnippet_expand)" : '\' nnoremap :Unite neosnippet imap (neosnippet_jump_or_expand) smap (neosnippet_jump_or_expand) nmap a xmap (neosnippet_start_unite_snippet_target) " only for MacBook Pro (gentoo) imap (neosnippet_jump_or_expand) smap (neosnippet_jump_or_expand) nmap a xmap (neosnippet_start_unite_snippet_target) " uses system snippet as personal snippet! " let g:neosnippet#snippets_directory = '~/.vimbundles/neosnippet/autoload/neosnippet/snippets/' let g:neosnippet#snippets_directory = '~/.vimbundles/neosnippet-snippets/neosnippets/' " }}} " vimshell platform-dependent aliases {{{ let s:is_gentoo = vimproc#system('uname -a') =~ 'gentoo' function! s:vimshell_settings() if s:is_gentoo call vimshell#set_alias('time', 'exe time -p') let xfce4_docker_cmd = 'xfce4-terminal --maximize -e "docker exec -it `docker ps -lq` /bin/bash" && wmctrl -a `wmctrl -l | tail -1 | sed "s/ .*//"` -i' call vimshell#set_alias('dockersh', printf('sh -c %s', string(xfce4_docker_cmd))) endif " from vimshell's doc call vimshell#set_alias('j', ':Unite -buffer-name=files \ -default-action=lcd -no-split -input=$$args directory_mru') " it's the default behaviour of in vimshell's insert mode imap (vimshell_enter) " expands snippet! imap neosnippet#expandable() ? \ "\(neosnippet_expand)\(vimshell_enter)" : "\(vimshell_enter)" inoremap \ smartchr#one_of('~/', '\') endfunction augroup vimshell-settings autocmd! autocmd FileType vimshell call s:vimshell_settings() augroup END " }}} " copy&paste {{{ " col('$') <= col('.'): at the end of line or not, considering virtualedit. " it didn't work for some reason... " nnoremap (vimrc-cmd-v-paste) col('$') <= col('.') ? '"+p' : '"+P' " inoremap (vimrc-temporary-normal-mode) " imap ö (vimrc-temporary-normal-mode)(vimrc-cmd-v-paste) imap col('$') <= col('.') ? '"+p' : '"+P' nnoremap "+p set linespace=2 " }}} " jruby {{{ function! VimrcJruby() if &filetype != 'ruby' echoerr 'not ruby' return endif call vimproc#system_bg('jruby --ng-server') let b:quickrun_config = {'command': 'jruby', 'cmdopt': '--ng --1.9'} endfunction " }}} " pseudo rm command {{{ command! -nargs=* Rm echo " }}} " no python preview {{{ set completeopt-=preview " }}} " minecraft {{{ function! VimrcSwank() VimShellInteractive java -jar /home/ujihisa/git/swank-client/swank-client-1.1.0-standalone.jar -p 4006 set filetype=clojure normal! A(ns mc68.core) endfunction "function! VimrcSendSwank() " "let @" = substitute(vimclojure#ExtractSexpr(1)[1], '\(;.*\)\?\n *', ' ', 'g') " execute 'VimShellSendString' vimclojure#ExtractSexpr(1)[1] "endfunction " experimental nnoremap 9 V%yjGpkVGJ " }}} " vim-scala {{{ let g:scala_use_default_keymappings = 0 " }}} " haskell snippets {{{ " import qualified Control.Monad.State as S " import Control.Applicative ((<$>), (<*>)) " import Data.Maybe (fromMaybe) " import qualified Data.Map as M " import Control.Monad (unless) " " {-# LANGUAGE QuasiQuotes #-} " import Data.String.Interpolation (str) " }}} " unite-file_rec with file-extension {{{ function! s:file_extension() let table = { \ 'ruby': 'rb', \ 'haskell': 'hs', \ 'clojure': 'clj' } return '.' . get(table, &filetype, &filetype) endfunction command! -nargs=0 UniteFilerecWithFiletype execute "Unite file_rec -input=" . file_extension() " }}} " lingr-vim {{{ augroup vimrc-lingr autocmd! autocmd FileType lingr-messages nmap i (lingr-messages-show-say-buffer) autocmd FileType lingr-say inoremap :wq augroup END " }}} " javascript {{{ function! s:vimrc_javascript() setl ts=4 setl sw=4 setl expandtab setl nolist "inoremap \ smartchr#one_of('function(', '\') inoremap ` console.log(); "runtime! ftplugin/coffee.vim endfunction augroup vimrc-javascript autocmd! autocmd FileType javascript call vimrc_javascript() augroup END " }}} " python {{{ function! s:vimrc_python() " setl ts=4 " setl sw=4 " setl noexpandtab " setl nolist "inoremap \ smartchr#one_of('function(', '\') inoremap ` print() endfunction augroup vimrc-python autocmd! autocmd FileType python call vimrc_python() augroup END " }}} " coffeescript {{{ function! s:vimrc_coffeescript() setl sw=2 setl sts=2 setl expandtab setl list endfunction augroup vimrc-coffeescript autocmd! autocmd FileType coffee call vimrc_coffeescript() augroup END " }}} " yacc {{{ " mostly for ruby/parse.y augroup vimrc-yacc autocmd! autocmd FileType yacc setl nolist autocmd FileType yacc setl noexpandtab autocmd FileType yacc setl ts=8 autocmd FileType yacc setl sw=4 augroup END " }}} " java {{{ function! s:vimrc_java() compiler javac nnoremap m :make % inoremap ` System.out.println(); endfunction augroup vimrc-java autocmd! autocmd FileType java call vimrc_java() augroup END " }}} " Vital.Vim.Buffer {{{ function! VitalVimBuffer_all() redir => output silent! ls redir END let flag_dict = {} for out in map(split(output, '\n'), 'split(v:val)') let flag_dict[out[0]] = [ \ matchstr(join(out), '^.*\ze\s\+"'), \ matchstr(join(out), '"\zs.*\ze"')] endfor echo flag_dict endfunction " }}} " scala sbt interaction {{{ function! s:start_sbt(vsm_cmds) abort execute 'normal' "\(vimshell_split_switch)\(vimshell_hide)" " execute 'VimShellInteractive sbt -no-colors' execute 'VimShellInteractive bash -c "TEST_TARGET=dev exec sbt"' " execute 'VimShellInteractive bash -c "TEST_TARGET=stage exec sbt"' stopinsert let t:vsm_bufname = bufname('%') wincmd H wincmd p endfunction function! s:sbt_run(vsm_cmds) abort let vsm_bufname = get(t:, 'vsm_bufname', '*not-found*') if vsm_bufname == '*not-found*' call s:start_sbt(a:vsm_cmds) call s:sbt_run(a:vsm_cmds) else let vsm_cmds = copy(a:vsm_cmds) " copy for later modifications " detect subproject let known_subprojects = [ \ 'crypto-common', \ 'sdk-crypto', \ 'sdk-kms', \ 'service-crypto', \ 'crypto-cli', \ 'service-crypto-root', \ 'util-core', \ 'service-member', \ 'sdk-member', \ 'member-common', \ 'test-integration-member'] for subproject in known_subprojects if expand('%:.') =~ subproject call map(vsm_cmds, printf('v:val == "reload" ? v:val : "%s/" . v:val', subproject)) break endif endfor " go to the window let wn = bufwinnr(vsm_bufname) if !bufexists(vsm_bufname) unlet! t:vsm_bufname return s:sbt_run(a:vsm_cmds) " retry elseif wn == -1 echo "buffer exists but window doesn't exist. opening it." execute 'sbuffer' vsm_bufname wincmd H else execute wn . 'wincmd w' endif " make sure if it's vimshell if !has_key(b:, 'interactive') close unlet t:vsm_bufname call s:sbt_run(a:vsm_cmds) return endif normal! Gzt " go back to the previous window wincmd p call vimshell#interactive#set_send_buffer(vsm_bufname) call vimshell#interactive#clear() let joined_vsm_cmds = "; " . join(vsm_cmds, '; ') call vimshell#interactive#send(joined_vsm_cmds) " explosion "call vimproc#system_bg('curl -s http://localhost:8080/requests/status.xml?command=pl_play') endif endfunction function! s:vimrc_scala() nnoremap m :write:call sbt_run(get(t:, 'vsm_cmds', ['compile'])) endfunction augroup vimrc_scala autocmd! autocmd FileType scala call s:vimrc_scala() autocmd FileType sbt.scala call s:vimrc_scala() augroup END " }}} " clojure leininge integrate (deadcopy from scala. really bad.) {{{ function! s:start_leiningen() if !has_key(t:, 'vsm_cmds') let t:vsm_cmds = ['compile'] endif execute 'normal' "\(vimshell_split_switch)\(vimshell_hide)" execute 'VimShellInteractive lein interactive' stopinsert let t:vsm_bufname = bufname('%') wincmd H wincmd p endfunction function! s:lein_run() let vsm_bufname = get(t:, 'vsm_bufname', '*not-found*') if vsm_bufname == '*not-found*' call s:start_leiningen() else if !has_key(t:, 'vsm_cmds') echoerr 'please give t:vsm_cmds a list' return endif " go to the window let wn = bufwinnr(vsm_bufname) if !bufexists(vsm_bufname) unlet! t:vsm_bufname return s:lein_run() " retry elseif wn == -1 echo "buffer exists but window doesn't exist. opening it." execute 'sbuffer' vsm_bufname wincmd H else execute wn . 'wincmd w' endif " make sure if it's vimshell if !has_key(b:, 'interactive') close unlet t:vsm_bufname call s:lein_run() return endif normal! Gzt " go back to the previous window wincmd p call vimshell#interactive#set_send_buffer(vsm_bufname) call vimshell#interactive#clear() call vimshell#interactive#send(t:vsm_cmds) endif endfunction function! s:vimrc_clojure() nnoremap m :write:call lein_run() endfunction augroup vimrc_clojure autocmd! autocmd FileType clojure call s:vimrc_clojure() augroup END " }}} " clojure {{{ " for " * clojure.tools.cli/cli " * anything that begins with def let g:clojure#indent#special = '\(vimrc-yankprefix-clipboard) "+ vnoremap (vimrc-go-back-to-mark) Gmm vmap (vimrc-yankprefix-clipboard)(operator-concealedyank)(vimrc-go-back-to-mark) " }}} " iexe-sbt {{{ function! s:vimrc_int_sbt() silent! nunmap j silent! nunmap k syntax case ignore syntax match intsbtPrompt /^> .*/ contains=intsbtPromptBody,intsbtPromptHead syntax match intsbtPromptBody /.*/ contained syntax match intsbtPromptHead /^> / contained syntax match intsbtDebug /^\[debug\] .*\|^\d\d:\d\d:\d\d/ contains=intsbtDebugHead,intsbtDebugBody syntax match intsbtDebugBody /.*/ contained syntax match intsbtDebugHead /\[debug\]/ contained syntax match intsbtInfo /^\[info\] .*/ contains=intsbtInfoHead,intsbtInfoBody syntax match intsbtInfoBody /.*/ contained syntax match intsbtInfoHead /\[info\]/ contained syntax match intsbtWarn /^\[warn\] .*/ contains=intsbtWarnHead,intsbtWarnBody syntax match intsbtWarnBody /.*/ contained syntax match intsbtWarnHead /\[warn\]/ contained syntax match intsbtError /^\[error\] .*/ contains=intsbtErrorHead,intsbtErrorBody syntax match intsbtErrorBody /.*/ contained syntax match intsbtErrorHead /\[error\]/ contained syntax match intsbtSuccess /^\[success\] .*/ hi def link intsbtPromptBody Statement hi def link intsbtPromptHead Operator hi def link intsbtDebugBody Comment hi def link intsbtDebugHead LineNr hi def link intsbtInfoBody Comment hi def link intsbtInfoHead LineNr " intsbtWarnBody: something easy to read and doesn't look too strong hi def link intsbtWarnBody String hi def link intsbtWarnHead LineNr " intsbtErrorBody: something easy to read and does look strong hi def link intsbtErrorBody Normal hi def link intsbtErrorHead LineNr hi def link intsbtSuccess LineNr endfunction augroup vimrc-int-sbt autocmd! autocmd FileType int-sbt call vimrc_int_sbt() augroup END " }}} " unite-menu {{{ let g:unite_source_menu_menus = {} let g:unite_source_menu_menus.neobundle = { \ 'description' : 'Test menu', \ 'command_candidates': [ \ ['all', 'Unite -no-start-insert -horizontal -log neobundle/update:all'], \ ['shougo', 'Unite -no-start-insert -horizontal -log neobundle/update:vimshell neobundle/update:vimproc neobundle/update:unite.vim neobundle/update:neocomplete neobundle/update:neosnippet'] \ ] \ } let g:unite_source_menu_menus.quickrun_set = { \ 'description': "change b:quickrun_config to enable more", \ 'command_candidates': [ \ ['esprima', 'call vimrc_esparse()'] \ ] \ } let g:unite_source_menu_menus.myset = { \ 'description': 'from vimrc', \ 'command_candidates': [ \ ['CopyTheCurrentFileName', 'CopyTheCurrentFileName'], \ ['GitLogViewer', 'GitLogViewer'], \ ], \ } nnoremap sn :Unite menu -buffer-name=menu " }}} " groovy {{{ augroup vimrc-groovy autocmd! autocmd BufWinEnter,BufNewFile *.gradle set filetype=groovy augroup END " }}} " ghcmod {{{ augroup vimrc-ghcmod autocmd! autocmd FileType haskell silent nnoremap \t :GhcModTypeClear:GhcModType autocmd FileType haskell silent nnoremap \i :GhcModTypeClear:GhcModInfo autocmd FileType haskell silent nnoremap \c :GhcModTypeClear augroup END " }}} " ebuild {{{ augroup vimrc-ebuild autocmd! autocmd FileType ebuild nnoremap m :write:Unite -buffer-name=build build:repoman:manifest build:repoman:full -horizontal -no-start-insert " :GitAdd Manifest augroup END " }}} " c {{{ let $CPP_STDLIB = '/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/include/g++-v4' augroup vimrc-c autocmd! autocmd FileType c nnoremap m :write:Unite -buffer-name=build build:make -horizontal -no-start-insert -no-focus autocmd FileType cpp nnoremap m :write:Unite -buffer-name=build build:make -horizontal -no-start-insert -no-focus autocmd FileType cpp setl path+=$CPP_STDLIB cinoptions+=:0,g0 autocmd FileType cpp nnoremap sB :UniteWithCursorWord boost-online-doc autocmd BufReadPost $CPP_STDLIB/* if empty(&filetype) | set filetype=cpp | endif "autocmd FileType cpp setl suffixesadd+=.hpp " no-focus augroup END " }}} " sound {{{ " augroup vimrc-sound " autocmd! " autocmd BufWritePost * call vimproc#system_bg('curl -s http://localhost:8080/requests/status.xml?command=pl_play') " augroup END " }}} " iexe git-log -u {{{ function! s:vimrc_git_log_u() if bufname('%') =~ '^less-git log -u' set filetype=git-log.git-diff endif endfunction augroup vimrc-git-log-u autocmd! autocmd FileType vimshell-less call vimrc_git_log_u() augroup END " }}} " postgresql {{{ let g:quickrun_config['sql/postgresql'] = { \ 'cmdopt': '-h 0.0.0.0 mydb postgres' \ } " }}} " scrot (screenshot by ) {{{ let g:scrot_n = 0 function! s:scrot() call vimproc#system(printf('scrot /tmp/%04d.png', g:scrot_n)) let g:scrot_n += 1 return "" endfunction nnoremap :call scrot() inoremap scrot() " }}} " fontzoom {{{ let g:fontzoom_no_default_key_mappings = 1 nmap (fontzoom-smaller) nmap (fontzoom-larger) " }}} " bare vim {{{ " $ vim -u NONE -U NONE --noplugin " }}} " j6uil {{{ let g:J6uil_display_icon = 1 let g:J6uil_empty_separator = 1 let g:J6uil_open_buffer_cmd = 'new' let g:J6uil_align_message = 0 augroup my-j6uil autocmd! autocmd FileType J6uil call s:j6uil_settings() augroup END function! s:j6uil_settings() nunmap s nmap i (J6uil_open_say_buffer) "imap endfunction " }}} " mongodb {{{ "function! s:vimrc_filetype_mongodb() " setl syntax=javascript " " remote mongo " let b:quickrun_config = { " \ 'command': 'ssh -t', " \ 'runner': 'process_manager', " \ 'runner/process_manager/load': '(load-file "%s")', " \ 'runner/process_manager/prompt': 'rs_a:SECONDARY> ', " \ }, " echo 'let b:quickrun_config.cmdopt = ' "endfunction " }}} " maxlength {{{ let s:L = g:V.import('Data.List') function! s:vimrc_currentfile_maxlength(limit) let buf_max_len = s:L.max_by(map(getline(1, line('$')), 'len(v:val)'), 'v:val') return s:L.min_by([buf_max_len, a:limit], 'v:val') endfunction nnoremap :execute printf( \ 'vertical resize %s', \ vimrc_currentfile_maxlength(&columns * 9 / 10)) " }}} " jplus {{{ nmap (jplus-input) vmap (jplus-input) " }}} " clojure-ns {{{ if 0 function! s:vimrc_clojure_current_ns(contents) for line in a:contents[:4] " take 5 items let x = matchlist(line, '^(ns \(.*\)')[1] if len(x) return x endif endfor echomsg 'could not find ns' return '' endfunction function! s:vimrc_clojure_current_ns_current_file() return s:vimrc_clojure_current_ns(getline(1, '$')) endfunction endif " }}} " Database.SQLite {{{ " let g:S = g:V.import('Database.SQLite') " call g:S.debug_mode_to(1) " }}} " showtime {{{ augroup vimrc-showtime autocmd! " By default it's just "s" but it takes time to trigger. " Just use instead. autocmd FileType showtime nmap (showtime-cursor) augroup END nnoremap st :ShowtimeResume " }}} " unite-file/mru {{{ let g:neomru#filename_format = ':~:.' let g:neomru#file_mru_limit = 50000 " default is 1000 let g:neomru#directory_mru_limit = 50000 " default is 1000 " }}} " unite-build {{{ augroup vimrc-unite-build autocmd! "autocmd FileType clojure nnoremap m :write:Unite -buffer-name=build -no-focus -no-start-insert build:lein augroup END "let g:quickrun_config['lein-test'] = { " \ 'command': 'lein run -m clojure.main/repl', " \ 'runner': 'process_manager', " \ 'runner/process_manager/load': "(do (use 'rabbitmq-client.core-test :reload-all) (clojure.test/run-tests 'rabbitmq-client.core-test))", " \ 'runner/process_manager/prompt': 'user=> ', " \ } "augroup vimrc-lein-test " autocmd! " autocmd FileType clojure nnoremap m :write:QuickRun -type lein-test "augroup END " }}} " just for now -- vuls {{{ let g:unite_feedback_report_level = 2 let g:unite_feedback_report_destination = 'http://vuls.ap01.aws.af.cm' " }}} " vimshell-benri {{{ " let g:B = g:V.import('Vim.Buffer') " augroup vimshell-benri " autocmd! " autocmd CursorHold * if !g:B.is_cmdwin() | silent call feedkeys("g\", 'n') | endif " augroup END " }}} " lein repl {{{ function! s:ft_lein_repl() set filetype=clojure endfunction augroup lein-repl autocmd! autocmd FileType int-lein call s:ft_lein_repl() augroup END " }}} " tpope/vim-surround {{{ " To start operator-pending mode nmap Ysurround " To surround from visual mode w/ shortcut. " Note that there's no { vmap s VSurround vmap ( VSurround( vmap [ VSurround[ vmap ' VSurround' " vmap " VSurround" vmap ` VSurround` " }}} " tyru/caw.vim {{{ let g:caw_no_default_keymappings = 1 nmap (caw:hatpos:toggle) nmap (caw:hatpos:uncomment) vmap (caw:hatpos:toggle)gv vmap (caw:hatpos:uncomment)gv " }}} " vitalista.vim {{{ function! s:vitalista() abort if empty(neobundle#get('vital.vim')) call g:V.import('Vim.Message').error('vital.vim not installed globally.') return endif if &l:path =~ 'vital.vim' return endif let &l:path .= printf( \ ',%s/autoload/vital/__latest__/', \ neobundle#get('vital.vim').path) let &l:suffixesadd = '.vim' let &l:includeexpr = 'substitute(v:fname, "\\.", "/", "g")' let &l:include = '^\s*let\s\+s:\w\+\s*=\s*.\{-}\%(import\|load\)' endfunction augroup vitalista autocmd! " autocmd FileType vim call vitalista() augroup END " }}} " clang_complete.vim {{{ imap (neocomplete_start_unite_complete) " }}} " d.vim {{{ augroup vimrc-d autocmd! autocmd FileType d setl expandtab shiftwidth=4 tabstop=4 softtabstop=4 augroup END " }}} " textobj-wiw {{{ " doesn't seem to be working though... xmap ,w (textobj-wiw-n) xmap ,e (textobj-wiw-p) omap ,w (textobj-wiw-n) omap ,e (textobj-wiw-p) nmap ,w (textobj-wiw-n) " }}} " unite-include-reversed {{{ nnoremap 0 :source /home/ujihisa/Dropbox/vimbundles/unite-include-reversed/autoload/unite_include_reversed.vim:call unite_include_reversed#identifiers() " }}} " paredit from slimv {{{ " let g:paredit_electric_return = 1 let g:paredit_smartjump = 1 " Don't use all the shortmaps, but use some of them. let g:paredit_shortmaps = 0 " with different key augroup vimrc-paredit-clojure " (aa bb cc ) anywhere in the expr " -> " (aa bb cc) " ^ function! s:expredit_normalize() call PareditSmartJumpClosing(0) execute 'normal!' "geli\\kJ" endfunction " (aa)(b) or (aa )(b) " ^ ^ " -> " (aa (b)) function! s:expredit_moveright() call s:expredit_normalize() execute 'normal!' "a\\h" call PareditMoveRight() endfunction autocmd! autocmd FileType clojure nmap < ,< autocmd FileType clojure nnoremap :silent call PareditMoveLeft() autocmd FileType clojure inoremap :call PareditMoveLeft() autocmd FileType clojure nmap > ,> autocmd FileType clojure nnoremap :silent call PareditMoveRight():silent call poslist#move_pos(1) autocmd FileType clojure inoremap :silent call PareditMoveRight():silent call poslist#move_pos(1) autocmd FileType clojure nmap R ,W autocmd FileType clojure nmap S ,S augroup END " nnoremap :echo synIDattr(synID(line("."), col("."), 0), "name") " inoremap :echo synIDattr(synID(line("."), col("."), 0), "name") " nnoremap O " }}} " slimv {{{ let g:slimv_disable_clojure = 1 " }}} " ansible gf {{{ function! Vimrc_ansible_includeexpr(fname) let isfname_bak = &g:isfname let &g:isfname = &g:isfname . ',32,{,}' " 32 is space let memo = expand('') let memo = substitute(memo, '{{ basedir }}', expand('%:h/../../..'), '') for env in ['vagrant', 'dev', 'stage', 'production'] let tmp = substitute(memo, '{{ env }}', env, '') echomsg string([filereadable(tmp), tmp]) if filereadable(tmp) let memo = tmp break endif endfor " echomsg string([isfname_bak, &g:isfname, memo]) let &g:isfname = isfname_bak return memo endfunction augroup vimrc-ansible autocmd! " the autocmd is very rough. autocmd FileType yaml let &l:includeexpr = 'Vimrc_ansible_includeexpr(v:fname)' augroup END " }}} " Spanish {{{ inoremap ¿ inoremap ¡ " }}} " mysql {{{ function! HootsuiteMysqlQuickrunSetup() if &l:filetype !=# 'mysql' echoerr printf('filetype is not mysql: %s', &l:filetype) return endif if !has_key(t:, 'vimrc_mysql_password') let t:vimrc_mysql_password = inputsecret('password: ') endif let b:quickrun_config = { \ 'exec': 'cat %s | %c %o %a', \ 'command': 'mysql', \ 'cmdopt': printf( \ '-h 127.0.0.1 -P 3306 -u uji -p --password=%s hootsuite', \ t:vimrc_mysql_password) \ } endfunction " }}} " manga-brightest {{{ let g:brightest#highlight = { \ "group" : "BrightestUnderline"} let g:brightest#pattern = '\k\+' " }}} " gentoo {{{ " gentoo's vim is terrible let g:leave_my_textwidth_alone = 1 " }}} " neoclojure {{{ augroup vimrc-neoclojure autocmd! autocmd FileType clojure setlocal omnifunc=neoclojure#complete#omni_auto autocmd FileType clojure nnoremap :call neoclojure#killall() augroup END let g:neocomplete#sources#omni#input_patterns = get(g:, 'neocomplete#sources#omni#input_patterns', {}) let g:neocomplete#sources#omni#input_patterns.clojure = '\.\|/' let g:neoclojure_autowarmup = 1 " }}} " calendar {{{ let g:calendar_first_day = 'sunday' " }}} " incsearch + asterisk {{{ nmap / (incsearch-forward) nmap ? (incsearch-backward) map n (incsearch-nohl-n) map N (incsearch-nohl-N) map * (incsearch-nohl)(asterisk-*) map g* (incsearch-nohl)(asterisk-g*) map # (incsearch-nohl)(asterisk-#) map g# (incsearch-nohl)(asterisk-g#) map z* (incsearch-nohl0)(asterisk-z*) map gz* (incsearch-nohl0)(asterisk-gz*) map z# (incsearch-nohl0)(asterisk-z#) map gz# (incsearch-nohl0)(asterisk-gz#) " }}} " PM3 (concproc) -- just for now {{{ " if 0 function! s:cpcp() abort let s:V = vital#of('vital') let s:CP = s:V.import('ConcurrentProcess') let label = s:CP.of('sh -c "sleep 2; echo done"', '', [ \ ['*read-all*', 'x']]) echomsg string([s:CP.consume(label, 'x')]) echomsg string([s:CP.consume_all_blocking(label, 'x', 3)]) endfunction nnoremap [ :call cpcp() " endif " }}} " cursorword {{{ " disable on MacVim if g:V.is_mac() let g:loaded_cursorword = 1 endif augroup vimrc-cursorword autocmd! autocmd WinLeave * let b:cursorword = 0 | call cursorword#matchadd() autocmd WinEnter * let b:cursorword = 1 augroup END " }}} " kana-altr {{{ call altr#define('main/scala/**/%.scala', 'test/scala/**/%Test.scala') call altr#define('src/%/%.clj', 'test/%/%_test.clj') nmap (altr-forward) imap (altr-forward) " Experimental use of altr to create corresponding file function! s:altr_guess_forward_file(bufname) abort for r in altr#_sort_rules(altr#_rule_table()) let [matchedp, match] = altr#_match_with_buffer_name(r, a:bufname) if matchedp let placeholders = filter(match[1 :], 'len(v:val)') let forward = r['forward_pattern'] for placeholder in placeholders let forward = substitute(forward, '%', placeholder, '') endfor return forward endif endfor endfunction function! s:altr_open_forward_file(bufname) abort let fname = s:altr_guess_forward_file(a:bufname) if len(fname) execute 'edit' fname endif endfunction nnoremap :call altr_open_forward_file(expand('%')) " }}} " kana-operator-replace {{{ map _ (operator-replace) " }}} " expand_region {{{ " nmap - (expand_region_shrink) " }}} " ujihisa-scala {{{ function! s:ujihisa_scala_yank_current_package() abort let search_maxln = 3 " assumption: package declaration must be at line 1 to 3 for i in range(1, search_maxln) let package = matchstr(getline(i), '^\s*package\s\+\zs.*') if len(package) break endif endfor if len(package) echo printf('Yanked %s', string(package)) let @@ = package else echoerr printf('No package declaration found til line %d of this file!', search_maxln) endif endfunction command! -nargs=0 ScalaYankCurrentPackage call s:ujihisa_scala_yank_current_package() " }}} " neochat {{{ " }}} " go {{{ let $GOPATH = expand('~/gopath') let $PATH = printf('%s/bin:%s', $GOPATH, $PATH) " }}} "fatih/vim-go {{{ " enable af and if let g:go_textobj_enabled = 1 augroup vimrc-go autocmd! autocmd FileType go setlocal nolist augroup END "}}} " macvim {{{ if g:V.is_mac() augroup vimrc-macvim autocmd! autocmd BufEnter * set macmeta augroup END endif " }}} " vim-sexp {{{ let g:sexp_mappings = {} " Default is let g:sexp_mappings['sexp_swap_list_backward'] = '' " Default is let g:sexp_mappings['sexp_swap_list_forward'] = '' " Default is let g:sexp_mappings['sexp_swap_element_backward'] = '' " Default is let g:sexp_mappings['sexp_swap_element_forward'] = '' let g:sexp_mappings['sexp_round_head_wrap_list'] = '' augroup ujihisa-vimrc autocmd FileType clojure imap augroup END " }}} " {{{ GithubPRTemplate " Returns a markdown-ish summary of your git commit messages " (1) Extract all commits since the newest commit in the `origin` " (2) Do some text processing, assuming commit messages are like this: " "Short summary\n\n* details" " (3) Return multiple lines as a list of strings function! s:github_pullreq_review_template() abort let git_log_text = vimproc#system('git log origin..HEAD') let result = [] for line in split(git_log_text, "\n") if line =~# '^ \u' let result += ['* ' . line[4:]] elseif line =~# '^ $' elseif line =~# '^ ' let result += [line] elseif line =~# '^commit' endif endfor return result endfunction function! s:GithubPRTemplate() abort let lines = s:github_pullreq_review_template() new setfiletype markdown call append(0, lines) endfunction command! -nargs=0 GithubPRTemplate call GithubPRTemplate() " }}} " neopairs {{{ let g:neopairs#enable = 1 " }}} " gitcommit.vim is evil {{{ augroup ujihisa-vimrc autocmd FileType gitcommit set textwidth=9999999999999 augroup END " }}} " markdown {{{ " function! s:vimrc_markdown() abort setlocal tabstop=4 setlocal shiftwidth=4 setlocal softtabstop=4 endfunction augroup ujihisa-vimrc autocmd FileType markdown call s:vimrc_markdown() augroup END " }}} " {{{ let g:ruby_indent_block_style = 'do' " }}} " netrw is evil {{{ let g:netrw_nobeval = 1 " }}} " quicklearn {{{ augroup ujihisa-vimrc autocmd FileType ruby nnoremap R :Unite quicklearn -immediately augroup END " }}} " vim-ruby does not know about ruby {{{ augroup ujihisa-vimrc autocmd FileType ruby setlocal iskeyword+=?,! augroup END " }}} " kotlin {{{ augroup ujihisa-vimrc autocmd FileType kotlin set tabstop=4 shiftwidth=4 softtabstop=4 augroup END " }}} " deol {{{ let g:deol#prompt_pattern = '\[.\{-}\]\$ $' " }}} tnoremap " __END__ "{{{1 " vim: expandtab softtabstop=2 shiftwidth=2 " vim: foldmethod=marker