scriptencoding utf-8 " basic settings {{{ " skip when vim-tiny or vim-small if !1 | finish | endif " vimrc augroup augroup MyVimrc autocmd! augroup END " encoding set encoding=utf-8 set fileencoding=utf=8 set fileencodings=utf-8,cp932,euc-jp set fileformats=unix,dos,mac " show cursorline set cursorline " show line number set number " show ruler set ruler " always show statusline set laststatus=2 " always show tabline set showtabline=2 " margin during scrolling set scrolloff=5 " disable beep set vb t_vb= " use fast terminal connection set ttyfast " show title set title " hide startup messages set shortmess& shortmess+=I " show tabs set list listchars=tab:>-,trail:-,eol:¬,nbsp:% " command-line completion set wildmenu wildignorecase wildmode=longest,full " separator set fillchars+=vert:\ " open file in tab set switchbuf+=usetab,newtab " add <> to matchpairs set matchpairs+=<:> " history set history=100 " backspace set backspace=indent,eol,start " use japanese-help first set helplang=ja,en " folding set foldmethod=marker set foldlevel=99 set nofoldenable " indent set smartindent autoindent " use instead of set expandtab smarttab set tabstop=2 shiftwidth=2 softtabstop=2 backspace=2 " smartcase search set ignorecase smartcase " incremental search set incsearch " highlight results set hlsearch " searches wrap around set wrapscan " timeout set timeoutlen=500 set updatetime=200 " clipboard set clipboard& if has('mac') set clipboard^=unnamed else set clipboard^=unnamedplus endif " no backup files set nobackup " swapfile if !isdirectory($HOME.'/.vim/swap') call mkdir($HOME.'/.vim/swap', 'p') endif set directory=~/.vim/swap " undofile if !isdirectory($HOME.'/.vim/undo') call mkdir($HOME.'/.vim/undo', 'p') endif set undodir=~/.vim/undo set undofile " disable auto comment autocmd MyVimrc BufEnter * setlocal formatoptions-=ro " open last position autocmd MyVimrc BufRead * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g`\"" | endif " }}} " keybind {{{ let mapleader = "," " disable arrow keys noremap noremap noremap noremap inoremap inoremap inoremap inoremap vnoremap vnoremap vnoremap vnoremap " remap j/k nnoremap j gj nnoremap k gk " change window size nnoremap - nnoremap + nnoremap < nnoremap > " }}} " filetypes {{{ " C++ autocmd MyVimrc FileType cpp call s:cpp_config() function! s:cpp_config() setlocal cindent setlocal cinoptions& cinoptions+=g0,m1,j1,(0,ws,Ws,N-s " // indent sample " " class foo { " public: " void hello() const { " std::cout << "Hello!" << std::endl; " } " }; " " auto main() -> int { " std::array a{}; " std::for_each(a.begin(), a.end(), [](const auto& i) { " i.hello(); " }); " } " include path let s:incpath = [ \ '/usr/include/boost', \ '/usr/include/c++/v1', \ expand('~/.ghq/github.com/bolero-MURAKAMI/Sprout'), \ ] execute 'setlocal path+=' . join(s:incpath, ',') " expand namespace " http://rhysd.hatenablog.com/entry/2013/12/10/233201#namespace inoremap ; expand_namespace() function! s:expand_namespace() let s = getline('.')[0:col('.') - 2] if s =~# '\oost::" elseif s =~# '\td::" elseif s =~# '\etail::" else return ';' endif endfunction endfunction " markdown autocmd MyVimrc FileType markdown call s:markdown_config() function! s:markdown_config() let g:markdown_fenced_languages = [ \ 'c', \ 'cpp', \ 'css', \ 'html', \ 'javascript', \ 'ruby', \ 'scss', \ 'vim', \ ] endfunction " binary files autocmd MyVimrc BufReadPost * if &binary | call s:binary_config() | endif function! s:binary_config() if neobundle#is_installed('vinarise.vim') Vinarise else silent %!xxd -g 1 setlocal ft=xxd autocmd MyVimrc BufWritePre * %!xxd -r autocmd MyVimrc BufWritePost * silent %!xxd -g 1 autocmd MyVimrc BufWritePost * setlocal nomodified endif endfunction " quickfix autocmd MyVimrc FileType qf nnoremap q :cclose " help autocmd MyVimrc FileType help nnoremap q :q " }}} " neobundle {{{ " install neobundle " https://github.com/rhysd/dotfiles/blob/5011f6fc25d754649aa6837c83408d2e680ea845/vimrc#L755-L765 if !isdirectory(expand('~/.vim/bundle')) echon "Installing neobundle.vim..." silent call mkdir(expand('~/.vim/bundle'), 'p') silent !git clone https://github.com/Shougo/neobundle.vim $HOME/.vim/bundle/neobundle.vim if v:shell_error echoerr "neobundle.vim installation has failed!" finish elseif echo "done." endif endif if has('vim_starting') set runtimepath+=~/.vim/bundle/neobundle.vim endif call neobundle#begin(expand('~/.vim/bundle/')) if neobundle#load_cache() " require NeoBundleFetch 'Shougo/neobundle.vim' NeoBundle 'Shougo/vimproc.vim', { \ 'build': { \ 'unix': 'make -f make_unix.mak', \ 'mac' : 'make -f make_mac.mak' \ } \ } NeoBundle 'airblade/vim-gitgutter' NeoBundle 'tpope/vim-fugitive' NeoBundle 'itchyny/lightline.vim' NeoBundle 'thinca/vim-quickrun' NeoBundle 'osyo-manga/vim-watchdogs', {'depends': ['thinca/vim-quickrun', 'osyo-manga/shabadou.vim']} NeoBundle 'Yggdroot/indentLine' NeoBundle 'haya14busa/incsearch.vim' NeoBundle 'jceb/vim-hier' NeoBundle 'rhysd/clever-f.vim' NeoBundle 't9md/vim-textmanip' NeoBundle 'tomtom/tcomment_vim' NeoBundle 'tpope/vim-surround' NeoBundle 'vim-jp/vimdoc-ja' NeoBundleLazy 'AndrewRadev/switch.vim' NeoBundleLazy 'Shougo/vimfiler.vim' NeoBundleLazy 'Shougo/vimshell.vim' NeoBundleLazy 'Shougo/vinarise.vim' NeoBundleLazy 'kannokanno/previm', {'depends': 'tyru/open-browser.vim'} NeoBundleLazy 'koron/nyancat-vim' NeoBundleLazy 'mattn/emmet-vim' NeoBundleLazy 'osyo-manga/vim-over' NeoBundleLazy 'Shougo/neocomplete.vim' NeoBundleLazy 'Shougo/neosnippet.vim', {'depends': 'Shougo/neocomplete.vim'} NeoBundleLazy 'eagletmt/neco-ghc' NeoBundleLazy 'osyo-manga/vim-marching' NeoBundleLazy 'rhysd/vim-clang-format' " operator NeoBundle 'kana/vim-operator-user' NeoBundle 'kana/vim-operator-replace' " colorscheme NeoBundle 'Tosainu/last256' NeoBundle 'chriskempson/vim-tomorrow-theme' NeoBundle 'w0ng/vim-hybrid' " unite NeoBundleLazy 'Shougo/unite.vim' NeoBundleLazy 'Shougo/neomru.vim', {'depends': 'Shougo/unite.vim'} NeoBundleLazy 'rhysd/unite-codic.vim', {'depends': ['Shougo/unite.vim', 'koron/codic-vim']} NeoBundleLazy 'ujihisa/unite-colorscheme',{'depends': 'Shougo/unite.vim'} " languages NeoBundle 'JavaScript-syntax' NeoBundle 'ap/vim-css-color' NeoBundle 'dag/vim2hs' NeoBundle 'hail2u/vim-css3-syntax' NeoBundle 'nginx.vim' NeoBundle 'othree/html5.vim' NeoBundle 'pangloss/vim-javascript' NeoBundle 'slim-template/vim-slim' NeoBundle 'sudar/vim-arduino-syntax' NeoBundle 'vim-jp/vim-cpp' NeoBundle 'vim-ruby/vim-ruby' NeoBundleSaveCache endif " vim-gitgutter {{{ if neobundle#tap('vim-gitgutter') let g:gitgutter_max_signs = 1000 let g:gitgutter_sign_added = '✚' let g:gitgutter_sign_modified = '➜' let g:gitgutter_sign_modified_removed = '➜' let g:gitgutter_sign_removed = '✘' call neobundle#untap() endif " }}} " lightline.vim {{{ if neobundle#tap('lightline.vim') let g:lightline = { \ 'colorscheme': 'wombat', \ 'active': { \ 'left': [ \ ['mode'], \ ['fugitive', 'readonly', 'filename', 'modified'], \ ], \ 'right': [ \ ['lineinfo'], \ ['percent'], \ ['fileformat', 'fileencoding', 'filetype'], \ ['gitgutter'], \ ] \ }, \ 'component_function': { \ 'filename': 'LightlineFilename', \ 'fugitive': 'LightlineFugitive', \ 'gitgutter': 'LightlineGitGutter', \ 'modified': 'LightlineModified', \ 'readonly': 'LightlineReadonly', \ }, \ 'separator': {'left': "\ue0b0", 'right': "\ue0b2"}, \ 'subseparator': {'left': "\ue0b1", 'right': "\ue0b3"}, \ 'tabline': {'left': [['tabs']], 'right': []}, \ } function! LightlineReadonly() return &ft !~? 'help' && &ro ? "\ue0a2" : '' endfunction function! LightlineFilename() return &ft == 'unite' ? unite#get_status_string() : \ &ft == 'vimfiler' ? vimfiler#get_status_string() : \ &ft == 'vimshell' ? vimshell#get_status_string() : \ expand('%:t') != '' ? expand('%:t') : '[No Name]' endfunction function! LightlineModified() return &ft =~ 'help' ? '' : &modified ? '+' : &modifiable ? '' : '-' endfunction function! LightlineFugitive() return strlen(fugitive#head()) ? "\ue0a0 " . fugitive#head() : '' endfunction function! LightlineGitGutter() if !exists('*GitGutterGetHunkSummary') \ || !get(g:, 'gitgutter_enabled', 0) \ || winwidth('.') <= 90 return '' endif let symbols = [ \ g:gitgutter_sign_added . ' ', \ g:gitgutter_sign_modified . ' ', \ g:gitgutter_sign_removed . ' ' \ ] let hunks = GitGutterGetHunkSummary() let ret = [] for i in [0, 1, 2] if hunks[i] > 0 call add(ret, symbols[i] . hunks[i]) endif endfor return join(ret, ' ') endfunction call neobundle#untap() endif " }}} " vim-quickrun {{{ if neobundle#tap('vim-quickrun') let g:quickrun_no_default_key_mappings = 1 let g:quickrun_config = get(g:, 'quickrun_config', {}) let g:quickrun_config._ = { \ 'outputter/buffer/split': ':botright', \ 'outputter/buffer/into': 1, \ 'outputter/buffer/close_on_empty': 1, \ 'outputter/error': 'quickfix', \ 'outputter/error/success': 'buffer', \ 'outputter': 'error', \ 'runner': 'vimproc', \ } let g:quickrun_config.cpp = { \ 'command': 'clang++', \ 'cmdopt': '-Wall -Wextra -std=c++14 -stdlib=libc++ -lc++abi -lboost_system -pthread', \ } let g:quickrun_config.make = { \ 'command': 'make', \ 'exec': '%c %o %a', \ 'cmdopt': '-j', \ 'outputter': 'quickfix', \ } let g:quickrun_config.markdown = { \ 'outputter': 'null', \ } " vim-watchdogs let g:quickrun_config['watchdogs_checker/clang++'] = { \ 'command': 'clang++', \ 'exec': '%c %o -Wall -Wextra -std=c++1y -stdlib=libc++ -fsyntax-only %s:p', \ } let g:quickrun_config['cpp/watchdogs_checker'] = { \ 'type': 'watchdogs_checker/clang++', \ } if executable('sass') let g:quickrun_config['watchdogs_checker/sass'] = { \ 'command': 'sass', \ 'exec': '%c %o --check --compass --trace --no-cache %s:p', \ 'errorformat': '%f:%l:%m\ (Sass::SyntaxError),%-G%.%#', \ } let g:quickrun_config['sass/watchdogs_checker'] = { \ 'type': 'watchdogs_checker/sass', \ } let g:quickrun_config['watchdogs_checker/scss'] = { \ 'command': 'sass', \ 'exec': '%c %o --check --compass --trace --no-cache %s:p', \ 'errorformat': '%f:%l:%m\ (Sass::SyntaxError),%-G%.%#', \ } let g:quickrun_config['scss/watchdogs_checker'] = { \ 'type': 'watchdogs_checker/scss', \ } endif nnoremap r :QuickRun nnoremap mb :QuickRun -type make nnoremap mc :QuickRun -type make -args clean nnoremap quickrun#is_running() ? quickrun#sweep_sessions() : "\" call neobundle#untap() endif " }}} " vim-watchdogs {{{ if neobundle#tap('vim-watchdogs') function! neobundle#tapped.hooks.on_source(bundle) let g:watchdogs_check_BufWritePost_enables = { \ 'c': 1, \ 'haskell': 1, \ 'javascript': 1, \ 'lua': 1, \ 'ruby': 1, \ 'sass': 1, \ 'scss': 1, \ } let g:watchdogs_check_BufWritePost_enable_on_wq = 0 call watchdogs#setup(g:quickrun_config) endfunction call neobundle#untap() endif " }}} " incsearch.vim {{{ if neobundle#tap('incsearch.vim') let g:incsearch#auto_nohlsearch = 1 map / (incsearch-forward) map ? (incsearch-backward) map n (incsearch-nohl-n) map N (incsearch-nohl-N) map * (incsearch-nohl-*) map # (incsearch-nohl-#) map g* (incsearch-nohl-g*) map g# (incsearch-nohl-g#) endif " }}} " clever-f.vim {{{ if neobundle#tap('clever-f.vim') let g:clever_f_across_no_line = 1 let g:clever_f_smart_case = 1 let g:clever_f_use_migemo = 1 call neobundle#untap() endif " }}} " vim-textmanip {{{ if neobundle#tap('vim-textmanip') xmap (textmanip-move-down) xmap (textmanip-move-up) xmap (textmanip-move-left) xmap (textmanip-move-right) call neobundle#untap() endif " }}} " switch.vim {{{ if neobundle#tap('switch.vim') call neobundle#config({ \ 'autoload': {'commands': ['Switch']} \ }) nnoremap sw :Switch call neobundle#untap() endif " }}} " vimfiler {{{ if neobundle#tap('vimfiler.vim') call neobundle#config({ \ 'depends': 'Shougo/unite.vim', \ 'autoload': { \ 'commands': [ \ {'name': 'VimFiler', 'complete' : 'customlist,vimfiler#complete'}, \ 'VimFilerExplorer', \ 'Edit', 'Read', 'Source', 'Write' \ ], \ 'mappings': ['(vimfiler_'], \ 'explorer': 1, \ } \ }) function! neobundle#tapped.hooks.on_source(bundle) let g:vimfiler_as_default_explorer = 1 let g:vimfiler_safe_mode_by_default = 0 " open in new tab let g:vimfiler_edit_action = 'tabopen' " ignore patern let g:vimfiler_ignore_pattern = '\(^\.git\|\.[ao]\|\.out\|\.bin\)$' endfunction " open Vimfiler nmap vf :VimFilerExplorer -winwidth=25 call neobundle#untap() endif " }}} " vimshell.vim {{{ if neobundle#tap('vimshell.vim') call neobundle#config({ \ 'autoload': { \ 'commands': ['VimShell', 'VimShellSendString', 'VimShellCurrentDir', 'VimShellInteractive'], \ }, \ }) function! neobundle#tapped.hooks.on_source(bundle) let g:vimshell_user_prompt = 'fnamemodify(getcwd(), ":~")' let g:vimshell_prompt = '> ' endfunction " open VimShell nnoremap vs :VimShell -split-command=vsplit call neobundle#untap() endif " }}} " vinarise.vim {{{ if neobundle#tap('vinarise.vim') call neobundle#config({ \ 'autoload': {'commands': ['Vinarise', 'VinarisePluginDump', 'VinarisePluginViewBitmapView']}, \ 'disabled': !has('python') && !has('python3'), \ }) call neobundle#untap() endif " }}} " previm {{{ if neobundle#tap('previm') call neobundle#config({ \ 'autoload': {'filetypes': 'markdown'} \ }) let g:previm_enable_realtime = 1 nnoremap p :PrevimOpen call neobundle#untap() endif " }}} " nyancat-vim {{{ if neobundle#tap('nyancat-vim') call neobundle#config({ \ 'autoload': {'commands': ['Nyancat', 'Nyancat2']} \ }) call neobundle#untap() endif " }}} " emmet-vim {{{ if neobundle#tap('emmet-vim') call neobundle#config({ \ 'autoload': {'filetypes': ['html', 'eruby', 'css', 'scss', 'slim']} \ }) function! neobundle#tapped.hooks.on_source(bundle) let g:user_emmet_settings = { \ 'indentation' : ' ' \ } imap (emmet-expand-abbr) endfunction call neobundle#untap() endif " }}} " vim-over {{{ if neobundle#tap('vim-over') call neobundle#config({ \ 'autoload': {'commands': ['OverCommandLine']} \ }) call neobundle#untap() endif " }}} " neocomplete.vim {{{ if neobundle#tap('neocomplete.vim') call neobundle#config({ \ 'autoload': {'insert': '1'}, \ 'disabled': !has('lua'), \ }) let g:neocomplete#enable_at_startup = 1 let g:neocomplete#enable_smart_case = 1 let g:neocomplete#enable_auto_delimiter = 1 let g:neocomplete#sources#syntax#min_keyword_length = 2 let g:neocomplete#lock_buffer_name_pattern = '\*ku\*' let g:neocomplete#sources#vim#complete_functions = { \ 'Unite': 'unite#complete_source', \ 'VimFiler': 'vimfiler#complete', \ 'VimShell': 'vimshell#complete', \ 'VimShellExecute': 'vimshell#vimshell_execute_complete', \ 'VimShellInteractive': 'vimshell#vimshell_execute_complete', \ 'VimShellTerminal': 'vimshell#vimshell_execute_complete', \ } if !exists('g:neocomplete#keyword_patterns') let g:neocomplete#keyword_patterns = {} endif let g:neocomplete#keyword_patterns['default'] = '\h\w*' " enable heavy omni completion let g:neocomplete#force_overwrite_completefunc = 1 if !exists('g:neocomplete#force_omni_input_patterns') let g:neocomplete#force_omni_input_patterns = {} endif let g:neocomplete#force_omni_input_patterns.cpp = \ '[^.[:digit:] *\t]\%(\.\|->\)\w*\|\h\w*::\w*' let g:neocomplete#force_omni_input_patterns.ruby = \ '[^. *\t]\.\w*\|\h\w*::' call neobundle#untap() endif " }}} " neosnippet.vim {{{ if neobundle#tap('neosnippet.vim') call neobundle#config({ \ 'autoload': { \ 'insert' : '1', \ 'filetypes': 'neosnippet' \ } \ }) let g:neosnippet#disable_runtime_snippets = { \ "_": 1, \ } let g:neosnippet#snippets_directory='~/.vim/snippets' " neocomplete and neosnippet keybinds imap !pumvisible() ? "\" : \ neosnippet#expandable() ? "\(neosnippet_expand)" : \ neocomplete#close_popup() imap pumvisible() ? "\" : \ neosnippet#jumpable() ? "\(neosnippet_jump)" : \ "\" smap neosnippet#jumpable() ? \ "\(neosnippet_jump)" \ : "\" inoremap pumvisible() ? "\" : "\" inoremap neocomplete#smart_close_popup()."\" inoremap neocomplete#smart_close_popup()."\" inoremap neocomplete#cancel_popup() " for snippet_complete marker if has('conceal') set conceallevel=2 concealcursor=i endif call neobundle#untap() endif " }}} " neco-ghc {{{ if neobundle#tap('neco-ghc') call neobundle#config({ \ 'autoload': {'filetypes': 'haskell'}, \ 'disable': !executable('ghc-mod'), \ }) call neobundle#untap() endif " }}} " vim-marching {{{ if neobundle#tap('vim-marching') call neobundle#config({ \ 'autoload': {'filetypes': 'cpp'}, \ 'disable': !executable('clang'), \ }) function! neobundle#tapped.hooks.on_source(bundle) let g:marching_wait_time = 1.0 let g:marching#clang_command#options = { \ 'cpp': '-std=gnu++14 -stdlib=libc++', \ } if neobundle#is_installed('neocomplete.vim') let g:marching_enable_neocomplete = 1 endif endfunction call neobundle#untap() endif " }}} " vim-clang-format {{{ if neobundle#tap('vim-clang-format') call neobundle#config({ \ 'autoload': { \ 'commands': ['ClangFormat', 'ClangFormatEchoFormattedCode'], \ 'filetypes': ['c', 'cpp'] \ }, \ 'disable': !executable('clang-format'), \ }) let g:clang_format#style_options = { \ 'AccessModifierOffset': -2, \ 'AllowShortFunctionsOnASingleLine': 'Empty', \ 'ColumnLimit': 128, \ 'SpacesBeforeTrailingComments': 1, \ 'Standard': 'Cpp11', \ } map cf (operator-clang-format) call neobundle#untap() endif " }}} " vim-operator-replace if neobundle#tap('vim-operator-replace') nmap R (operator-replace) endif " unite.vim {{{ if neobundle#tap('unite.vim') call neobundle#config({ \ 'autoload': { \ 'commands': [{ \ 'name': 'Unite', \ 'complete': 'customlist,unite#complete_source' \ }, \ 'UniteWithCursorWord', 'UniteWithInput' \ ] \ } \ }) function! neobundle#tapped.hooks.on_source(bundle) let g:unite_source_file_mru_limit = 200 let g:unite_force_overwrite_statusline = 0 let g:unite_source_history_yank_enable = 1 " always open new tab call unite#custom_default_action('file', 'tabopen') " show dotfiles call unite#custom#source('file,file_rec/git', 'matchers', 'matcher_default') autocmd MyVimrc FileType unite call s:unite_myconfig() function! s:unite_myconfig() imap (unite_delete_backward_path) endfunction endfunction " keybinds nnoremap [unite] nmap u [unite] nnoremap [unite]f :UniteWithBufferDir file -buffer-name=files nnoremap [unite]r :Unite file_rec/git -buffer-name=repository nnoremap [unite]n :Unite file/new -start-insert -buffer-name=newfile nnoremap [unite]s :Unite line -start-insert -buffer-name=search nnoremap [unite]b :Unite buffer -buffer-name=buffer nnoremap [unite]t :Unite tab -buffer-name=tab nnoremap [unite]y :Unite history/yank -buffer-name=yank nnoremap [unite]R :UniteResume call neobundle#untap() endif " }}} " neomru.vim {{{ if neobundle#tap('neomru.vim') call neobundle#config({ \ 'autoload': {'unite_sources': 'file_mru'} \ }) nnoremap [unite]h :Unite file_mru -buffer-name=history call neobundle#untap() endif " }}} " unite-codic.vim {{{ if neobundle#tap('unite-codic.vim') call neobundle#config({ \ 'autoload': {'unite_sources': ['codic']} \ }) nnoremap [unite]c :Unite codic -start-insert -buffer-name=codic call neobundle#untap() endif " }}} " unite-colorscheme {{{ if neobundle#tap('unite-colorscheme') call neobundle#config({ \ 'autoload': {'unite_sources': ['colorscheme']} \ }) call neobundle#untap() endif " }}} " vim-ruby {{{ if neobundle#tap('vim-ruby') let g:rubycomplete_buffer_loading = 1 let g:rubycomplete_classes_in_global = 1 let g:rubycomplete_use_bundler = 1 call neobundle#untap() endif " }}} call neobundle#end() filetype plugin indent on NeoBundleCheck if !has('vim_starting') call neobundle#call_hook('on_source') endif " }}} " colorscheme {{{ syntax enable if !has('gui_running') " color mode set t_Co=256 try colorscheme last256 " transparent background highlight Normal ctermbg=none catch colorscheme default endtry endif " }}}