set encoding=utf-8 scriptencoding utf-8 " 基本 {{{ let s:is_windows = has('win32') || has('win64') let s:is_mac = has('mac') || has('macunix') let s:has_vim_starting = has('vim_starting') let s:has_gui_running = has('gui_running') let s:has_kaoriya = has('kaoriya') let s:base_columns = 120 let g:mapleader = ',' " 自動コマンド augroup MyAutoCmd autocmd! augroup END command! -nargs=* Autocmd autocmd MyAutoCmd command! -nargs=* AutocmdFT autocmd MyAutoCmd FileType " スタートアップ時間表示 if s:has_vim_starting let s:startuptime = reltime() Autocmd VimEnter * let s:startuptime = reltime(s:startuptime) \| echomsg 'startuptime:' reltimestr(s:startuptime) endif " SID function! s:get_sid() return matchstr(expand(''), '\d\+_\zeget_sid$') endfunction let s:sid = s:get_sid() delfunction s:get_sid " メニューを読み込まない let g:did_install_default_menus = 1 " キー nnoremap [App] nmap ; [App] " $MYVIMRC調整 function! s:setup_myvimrc() let dropbox_vimrc = expand('~/Dropbox/dotfiles/.vimrc') if filereadable(dropbox_vimrc) let $MYVIMRC = dropbox_vimrc endif endfunction nnoremap :call setup_myvimrc():edit $MYVIMRC nnoremap :call setup_myvimrc():source $MYVIMRC:IndentLinesReset nnoremap :NeoBundleUpdate:NeoBundleClearCache:NeoBundleUpdatesLog nnoremap :NeoBundleInstall:NeoBundleClearCache:NeoBundleUpdatesLog " 遅延初期化 augroup LazyInitialize autocmd! autocmd VimEnter,FocusLost,CursorHold,CursorHoldI * call s:lazy_initialize() augroup END let s:lazy_initialize = 2*1 function! s:lazy_initialize() let s:lazy_initialize -= 1 if s:lazy_initialize > 0 return endif if s:is_mac let $LUA_DLL = $VIM . '/../../Frameworks/libluajit-5.1.2.dylib' endif " 実行ファイル位置を$PATHに含める if s:is_windows let $PATH .= ';' . $VIM elseif s:is_mac let $PATH .= ':' . $VIM . '/../../MacOS' endif if exists('+cryptmethod') set cryptmethod=blowfish2 endif set iskeyword=@,48-57,_,128-167,224-235 if s:is_windows && !executable('MSBuild') let $PATH .= ';C:/Windows/Microsoft.NET/Framework/v4.0.30319' endif " ローカル設定 let s:vimrc_local = expand('~/.vimrc_local') if filereadable(s:vimrc_local) execute 'source' s:vimrc_local endif Autocmd BufWinEnter,ColorScheme .vimrc highlight def link myVimAutocmd vimAutoCmd Autocmd BufWinEnter,ColorScheme .vimrc syntax match vimAutoCmd /\<\(Autocmd\|AutocmdFT\)\>/ augroup LazyInitialize autocmd! augroup END endfunction " }}} " guioptions {{{ " メニューを読み込まない set guioptions+=M " ツールバー削除 set guioptions-=T " メニューバー削除 set guioptions-=m " スクロールバー削除 set guioptions-=r set guioptions-=l set guioptions-=R set guioptions-=L " テキストベースタブ set guioptions-=e " }}} " プラグイン {{{ if s:has_vim_starting set runtimepath+=~/.vim/bundle/neobundle.vim/ let g:neobundle#install_max_processes = 8 let g:neobundle#install_process_timeout = 10*60 endif call neobundle#begin('~/.vim/bundle/') if neobundle#load_cache() NeoBundleFetch 'Shougo/neobundle.vim' call neobundle#load_toml('~/.vim/plugins/plugins.toml') call neobundle#load_toml('~/.vim/plugins/plugins.lazy.toml', {'lazy' : 1}) if s:is_windows call neobundle#load_toml('~/.vim/plugins/plugins.win.toml') call neobundle#load_toml('~/.vim/plugins/plugins.lazy.win.toml', {'lazy' : 1}) endif NeoBundleSaveCache endif " ライブラリ {{{ " vim-shell let g:shell_mappings_enabled = 0 " vim-submode if neobundle#tap('vim-submode') function! neobundle#hooks.on_source(bundle) let g:submode_timeout = 0 let g:submode_keep_leaving_key = 1 call submode#enter_with('buffer', 'n', 's', 'gbj', ':bn') call submode#enter_with('buffer', 'n', 's', 'gbk', ':bp') call submode#map( 'buffer', 'n', 's', 'j', ':bn') call submode#map( 'buffer', 'n', 's', 'k', ':bp') call submode#enter_with('git_hunk', 'n', 's', 'ghj', ':GitGutterNextHunkzvzz') call submode#enter_with('git_hunk', 'n', 's', 'ghk', ':GitGutterPrevHunkzvzz') call submode#map( 'git_hunk', 'n', 's', 'j', ':GitGutterNextHunkzvzz') call submode#map( 'git_hunk', 'n', 's', 'k', ':GitGutterPrevHunkzvzz') call submode#enter_with('winsize', 'n', 's', 'gwh', '8>') call submode#enter_with('winsize', 'n', 's', 'gwl', '8<') call submode#enter_with('winsize', 'n', 's', 'gwj', '4-') call submode#enter_with('winsize', 'n', 's', 'gwk', '4+') call submode#map( 'winsize', 'n', 's', 'h', '8>') call submode#map( 'winsize', 'n', 's', 'l', '8<') call submode#map( 'winsize', 'n', 's', 'j', '4-') call submode#map( 'winsize', 'n', 's', 'k', '4+') endfunction endif " }}} " 表示 {{{ " foldCC.vim let g:foldCCtext_enable_autofdc_adjuster = 1 let g:foldCCtext_tail = \ 'printf("[ %4d lines Lv%-2d]", v:foldend - v:foldstart + 1, v:foldlevel)' set foldtext=FoldCCtext() " syntastic Autocmd BufWritePost *.{go,rb,py} call s:update_lightline() " lightline.vim let g:lightline#colorscheme#yoi#palette = { \ 'inactive': { \ 'left': [['#585858', '#262626', 240, 235], \ ['#585858', '#121212', 240, 233]], \ 'right': [['#262626', '#606060', 235, 241], \ ['#585858', '#262626', 240, 235], \ ['#585858', '#121212', 240, 233]] \ }, \ 'insert': { \ 'branch': [['#FFFFFF', '#0087AF', 231, 31]], \ 'left': [['#005F5F', '#FFFFFF', 23, 231], \ ['#87DFFF', '#005F87', 117, 24]], \ 'middle': [['#87DFFF', '#005F87', 117, 24]], \ 'right': [['#005F5F', '#87DFFF', 23, 117], \ ['#87DFFF', '#0087AF', 117, 31], \ ['#87DFFF', '#005F87', 117, 24]] \ }, \ 'normal': { \ 'branch': [['#FFFFFF', '#585858', 231, 240]], \ 'error': [['#BCBCBC', '#FF0000', 250, 196]], \ 'left': [['#195E00', '#07AF00', 22, 34], \ ['#8A8A8A', '#303030', 245, 236]], \ 'middle': [['#8A8A8A', '#303030', 245, 236]], \ 'right': [['#606060', '#D0D0D0', 241, 252], \ ['#BCBCBC', '#585858', 250, 240], \ ['#9E9E9E', '#303030', 247, 236]], \ 'warning': [['#262626', '#B58900', 235, 136]] \ }, \ 'replace': { \ 'left': [['#FFFFFF', '#DF0000', 231, 160], \ ['#FFFFFF', '#585858', 231, 240]], \ 'middle': [['#8A8A8A', '#303030', 245, 236]], \ 'right': [['#606060', '#D0D0D0', 241, 252], \ ['#BCBCBC', '#585858', 250, 240], \ ['#9E9E9E', '#303030', 247, 236]] \ }, \ 'tabline': { \ 'left': [['#BCBCBC', '#585858', 250, 240]], \ 'middle': [['#303030', '#9E9E9E', 236, 247]], \ 'right': [['#BCBCBC', '#4E4E4E', 250, 239]], \ 'tabsel': [['#BCBCBC', '#262626', 250, 235]] \ }, \ 'visual': { \ 'branch': [['#FFFFFF', '#AF0053', 231, 125]], \ 'left': [['#AB2362', '#FFFFFF', 125, 231], \ ['#FF84BA', '#870036', 211, 89]], \ 'middle': [['#FF84BA', '#870036', 211, 89]], \ 'right': [['#75003D', '#FF87BB', 89, 211], \ ['#FE86BB', '#AF0053', 211, 125], \ ['#FF84BA', '#870036', 211, 89]] \ } \ } let g:lightline = { \ 'colorscheme': 'yoi', \ 'active': { \ 'left': [ \ ['mode', 'paste'], \ ['branch', 'gitgutter', 'filename', 'anzu', 'submode'] \ ], \ 'right': [ \ ['syntastic', 'lineinfo'], \ ['percent'] \ ] \ }, \ 'component': {'percent': '⭡%3p%%'}, \ 'component_function': { \ 'fileformat': s:sid . 'lightline_fileformat', \ 'filetype': s:sid . 'lightline_filetype', \ 'fileencoding': s:sid . 'lightline_fileencoding', \ 'modified': s:sid . 'lightline_modified', \ 'readonly': s:sid . 'lightline_readonly', \ 'filename': s:sid . 'lightline_filename', \ 'mode': s:sid . 'lightline_mode', \ 'lineinfo': s:sid . 'lightline_lineinfo', \ 'anzu': 'anzu#search_status', \ 'submode': 'submode#current' \ }, \ 'component_expand': { \ 'syntastic': 'SyntasticStatuslineFlag', \ 'branch': s:sid . 'lightline_current_branch', \ 'gitgutter': s:sid . 'lightline_git_summary' \ }, \ 'component_type': { \ 'syntastic': 'error', \ 'branch': 'branch', \ 'gitgutter': 'branch' \ }, \ 'separator': { 'left': '⮀', 'right': '⮂'}, \ 'subseparator': {'left': '⮁', 'right': '⮃'}, \ 'tabline': { \ 'left': [['tabs']], \ 'right': [['filetype', 'fileformat', 'fileencoding']] \ }, \ 'tabline_separator': { 'left': '⮀', 'right': '⮂'}, \ 'tabline_subseparator': {'left': '⮁', 'right': '⮃'}, \ 'mode_map': { \ 'n': 'N', \ 'i': 'I', \ 'R': 'R', \ 'v': 'V', \ 'V': 'VL', \ 'c': 'C', \ "\": 'VB', \ 's': 'S', \ 'S': 'SL', \ "\": 'SB', \ '?': ' ' \ } \ } function! s:lightline_mode() return &filetype ==# 'unite' ? 'Unite' : \ &filetype ==# 'vimfiler' ? 'VimFiler' : \ &filetype ==# 'vimshell' ? 'VimShell' : \ &filetype ==# 'quickrun' ? 'Quickrun' : \ &filetype =~# 'lingr' ? 'Lingr' : \ &filetype ==# 'agit' ? 'Agit' : \ winwidth(0) > 50 ? lightline#mode() : '' endfunction function! s:lightline_modified() if s:is_lightline_no_disp_group() return '' endif return &modified ? '+' : &modifiable ? '' : '-' endfunction function! s:lightline_readonly() if s:is_lightline_no_disp_filetype() return '' endif return &readonly ? '⭤' : '' endfunction function! s:lightline_filename() try return (empty(s:lightline_readonly()) ? '' : s:lightline_readonly() . ' ') . \ (&filetype ==# 'unite' ? unite#get_status_string() : \ &filetype ==# 'vimfiler' ? vimfiler#get_status_string() : \ &filetype ==# 'vimshell' ? vimshell#get_status_string() : \ &filetype ==# 'lingr-messages' ? lingr#status() : \ &filetype =~# 'lingr' ? '' : \ &filetype ==# 'quickrun' ? '' : \ empty(expand('%:t')) ? '[No Name]' : expand('%:t')) . \ (empty(s:lightline_modified()) ? '' : ' ' . s:lightline_modified()) catch return '' endtry endfunction function! s:lightline_current_branch() if s:is_lightline_no_disp_filetype() return '' endif if !s:is_in_git_branch() return '' endif if &filetype !=# 'vimfiler' try let branch = fugitive#head() return empty(branch) ? '' : '⭠ ' . branch catch return '' endtry endif return '' endfunction function! s:lightline_fileformat() if s:is_lightline_no_disp_group() return '' endif return &fileformat endfunction function! s:lightline_filetype() if s:is_lightline_no_disp_group() return '' endif return empty(&filetype) ? 'no filetype' : &filetype endfunction function! s:lightline_fileencoding() if s:is_lightline_no_disp_group() return '' endif return empty(&fileencoding) ? &encoding : &fileencoding endfunction function! s:lightline_git_summary() if s:is_lightline_no_disp_group() return '' endif if !s:is_in_git_branch() return '' endif try let summary = gitgutter#hunk#summary() return printf('%s%d %s%d %s%d', \ g:gitgutter_sign_added, summary[0], \ g:gitgutter_sign_modified, summary[1], \ g:gitgutter_sign_removed, summary[2]) catch return '' endtry endfunction function! s:lightline_lineinfo() if winwidth(0) <= 50 return '' endif return printf('%4d/%d : %-3d', line('.'), line('$'), col('.')) endfunction function! s:is_lightline_no_disp_filetype() return &filetype =~# 'vimfiler\|unite\|vimshell\|quickrun\|lingr\|agit' endfunction function! s:is_lightline_no_disp_group() if winwidth(0) <= 50 return 1 endif if s:is_lightline_no_disp_filetype() return 1 endif return 0 endfunction Autocmd CursorHold,CursorHoldI * call s:update_lightline() function! s:update_lightline() try call lightline#update() catch endtry endfunction " }}} " 編集 {{{ " vim-endwise " http://cohama.hateblo.jp/entry/20121017/1350482411 let g:endwise_no_mappings = 1 AutocmdFT lua,ruby,vim imap DiscretionaryEnd " vim-easy-align " todo:直接埋め込むと正しく動作しないことがある nmap 0easyalign (EasyAlign) vmap 0easyalign (EasyAlign) nmap a= vii0easyalign= nmap a: vii0easyalign: nmap a, vii0easyalign*, nmap a vii0easyalign* nmap a\| vii0easyalign*\| xmap a= 0easyalign= xmap a: 0easyalign: xmap a, 0easyalign*, xmap a 0easyalign* xmap a\| 0easyalign*\| " yankround.vim let g:yankround_use_region_hl = 1 function! s:yankround_pre(count1) return (col('.') >= col('$') ? '$' : '') . ":\set virtualedit=block\" . a:count1 endfunction nmap p yankround_pre(v:count1) . '(yankround-p)' xmap p yankround_pre(v:count1) . '(yankround-p)' nmap P yankround_pre(v:count1) . '(yankround-P)' nmap gp yankround_pre(v:count1) . '(yankround-gp)' xmap gp yankround_pre(v:count1) . '(yankround-gp)' nmap gP yankround_pre(v:count1) . '(yankround-gP)' nmap (yankround-prev) nmap (yankround-next) " vim-smartinput if neobundle#tap('vim-smartinput') function! neobundle#hooks.on_source(bundle) call smartinput#clear_rules() call smartinput#define_default_rules() endfunction endif " increment-activator let g:increment_activator_filetype_candidates = { \ '_': [['width', 'height']], \ 'cs': [['private', 'protected', 'public', 'internal']], \ 'cpp': [['private', 'protected', 'public']] \ } " vim-over let g:over_command_line_key_mappings = {"\": "\"} nnoremap s :OverCommandLine%s/ vnoremap s :OverCommandLines/ nnoremap gs :OverCommandLine%s///g vnoremap gs :OverCommandLines///g augroup InitializeOver autocmd! autocmd VimEnter,FocusLost,CursorHold,CursorHoldI * call s:initialize_over() augroup END let s:initialize_over_delay = 2*1 function! s:initialize_over() let s:initialize_over_delay -= 1 if s:initialize_over_delay > 0 return endif call over#load() augroup InitializeOver autocmd! augroup END endfunction " }}} " 補完 {{{ " neocomplete.vim if neobundle#tap('neocomplete.vim') function! neobundle#hooks.on_source(bundle) let g:neocomplete#enable_at_startup = 1 let g:neocomplete#enable_ignore_case = 1 let g:neocomplete#enable_smart_case = 1 let g:neocomplete#enable_auto_delimiter = 1 let g:neocomplete#enable_fuzzy_completion = 0 let g:neocomplete#enable_refresh_always = 1 let g:neocomplete#enable_prefetch = 1 let g:neocomplete#auto_completion_start_length = 3 let g:neocomplete#manual_completion_start_length = 0 let g:neocomplete#sources#syntax#min_keyword_length = 3 let g:neocomplete#min_keyword_length = 3 let g:neocomplete#force_overwrite_completefunc = 1 let g:neocomplete#skip_auto_completion_time = '0.2' let g:neocomplete#sources#dictionary#dictionaries = { \ 'default': '', \ 'vimshell': '~/.vimshell_hist' \ } let g:neocomplete#sources#vim#complete_functions = { \ 'Unite': 'unite#complete_source', \ 'VimShellExecute': 'vimshell#vimshell_execute_complete', \ 'VimShellInteractive': 'vimshell#vimshell_execute_complete', \ 'VimShellTerminal': 'vimshell#vimshell_execute_complete', \ 'VimShell': 'vimshell#complete', \ 'VimFiler': 'vimfiler#complete' \ } " 日本語は収集しない let g:neocomplete#keyword_patterns = { \ '_': '\h\w*' \ } let g:neocomplete#sources#omni#input_patterns = { \ 'c': '\%(\.\|->\)\h\w*', \ 'disable_cpp': '\h\w*\%(\.\|->\)\h\w*\|\h\w*::', \ 'cs': '[a-zA-Z0-9.]\{2\}', \ 'typescript': '\h\w*\|[^. \t]\.\w*', \ 'ruby': '[^. *\t]\.\w*\|\h\w*::' \ } let g:neocomplete#force_omni_input_patterns = { \ 'c': '[^.[:digit:] *\t]\%(\.\|->\)\w*', \ 'disable_cpp': '[^.[:digit:] *\t]\%(\.\|->\)\w*\|\h\w*::\w*', \ 'objc': '[^.[:digit:] *\t]\%(\.\|->\)\w*', \ 'objcpp': '[^.[:digit:] *\t]\%(\.\|->\)\w*\|\h\w*::\w*', \ 'cs': '[^.[:digit:] *\t]\%(\.\)\w*\|\h\w*::\w*' \ } let g:neocomplete#delimiter_patterns = { \ 'c': ['.', '->'], \ 'disable_cpp': [' ::', '.'], \ 'cs': ['.'], \ 'vim': ['#', '.'] \ } let g:neocomplete#sources#file_include#exts = { \ 'c': ['', 'h'], \ 'cpp': ['', 'h', 'hpp', 'hxx'], \ 'cs': ['', 'Designer.cs'] \ } call neocomplete#custom#source('file', 'rank', 10) endfunction augroup InitializeNeocomplete autocmd! autocmd VimEnter,FocusLost,CursorHold,CursorHoldI * call s:initialize_neocomplete() augroup END let s:initialize_neocomplete_delay = 2*2 function! s:initialize_neocomplete() let s:initialize_neocomplete_delay -= 1 if s:initialize_neocomplete_delay > 0 return endif call neocomplete#initialize() augroup InitializeNeocomplete autocmd! augroup END endfunction endif " neosnippet.vim if neobundle#tap('neosnippet.vim') imap neosnippet#expandable_or_jumpable() ? '(neosnippet_expand_or_jump)' \ : '' smap neosnippet#expandable_or_jumpable() ? '(neosnippet_expand_or_jump)' \ : '' function! neobundle#hooks.on_source(bundle) let g:neosnippet#enable_snipmate_compatibility = 1 let g:neosnippet#disable_runtime_snippets = {'_': 1} let g:neosnippet#snippets_directory = '~/.vim/snippets' let snippets_local = expand('~/.vim/snippets.local') if isdirectory(snippets_local) let g:neosnippet#snippets_directory .= ',' . snippets_local endif call neocomplete#custom#source('neosnippet', 'rank', 1000) endfunction endif " }}} " ファイル {{{ " vim-altr if neobundle#tap('vim-altr') nmap ga (altr-forward) nmap gA (altr-back) function! neobundle#hooks.on_source(bundle) function! s:altr_define(...) for parent in ['', '/*', '/*/*', '/*/*/*'] call altr#define(map(copy(a:000), 'printf(v:val, "' . parent . '")')) endfor endfunction " MVVM AutocmdFT cs,xml call altr#define( '%Model.cs', \ '%Vm.cs', \ '%.xaml', \ '%.xaml.cs') AutocmdFT cs,xml call s:altr_define('Models%s/%%Model.cs', \ 'ViewModels%s/%%Vm.cs', \ 'Views%s/%%.xaml', \ 'Views%s/%%.xaml.cs') AutocmdFT cs,xml call altr#define( '%Model.cs', \ '%ViewModel.cs', \ '%.xaml', \ '%.xaml.cs') AutocmdFT cs,xml call s:altr_define('Models%s/%%Model.cs', \ 'ViewModels%s/%%ViewModel.cs', \ 'Views%s/%%.xaml', \ 'Views%s/%%.xaml.cs') " xaml AutocmdFT cs,xml call altr#define( '%.xaml', \ '%.xaml.cs') AutocmdFT cs,xml call altr#define( '%.cs', \ '%.*.cs') " C++ AutocmdFT cpp call altr#define( '%.cpp', \ '%.*.cpp', \ '%.h') AutocmdFT cpp call s:altr_define( 'src%s/%%.cpp', \ 'include%s/%%.h') endfunction endif " }}} " 検索 {{{ " matchit.zip if neobundle#tap('matchit.zip') function! neobundle#hooks.on_post_source(bundle) silent! execute 'doautocmd Filetype' &filetype endfunction endif " incsearch.vim if neobundle#tap('incsearch.vim') function! neobundle#hooks.on_source(bundle) let g:incsearch#auto_nohlsearch = 1 let g:incsearch#emacs_like_keymap = 1 let g:incsearch#magic = '\v' endfunction Autocmd VimEnter * IncSearchNoreMap Autocmd VimEnter * IncSearchNoreMap Autocmd VimEnter * IncSearchNoreMap (incsearch-scroll-f) Autocmd VimEnter * IncSearchNoreMap (incsearch-scroll-b) endif " vim-anzu " 一定時間キー入力がないとき、ウインドウを移動したとき、タブを移動したときに " 検索ヒット数の表示を消去する Autocmd CursorHold,CursorHoldI * call s:update_display_anzu() Autocmd WinLeave,TabLeave * call s:clear_display_anzu() let s:anzu_display_count = 0 function! s:begin_display_anzu() let s:anzu_display_count = 2000 / &updatetime call s:refresh_screen() endfunction function! s:update_display_anzu() if s:anzu_display_count >= 0 let s:anzu_display_count -= 1 call s:continue_cursor_hold() else call s:clear_display_anzu() endif endfunction function! s:clear_display_anzu() try call anzu#clear_search_status() catch endtry endfunction " clever-f.vim if neobundle#tap('clever-f.vim') nmap f (clever-f-f) xmap f (clever-f-f) omap f (clever-f-f) nmap F (clever-f-F) xmap F (clever-f-F) omap F (clever-f-F) function! neobundle#hooks.on_source(bundle) let g:clever_f_not_overwrites_standard_mappings = 1 let g:clever_f_ignore_case = 1 let g:clever_f_smart_case = 1 let g:clever_f_across_no_line = 1 let g:clever_f_use_migemo = 1 let g:clever_f_chars_match_any_signs = ';' let g:clever_f_mark_char_color = 'Clever_f_mark_char' highlight default Clever_f_mark_char ctermfg=Green ctermbg=NONE cterm=underline \ guifg=Green guibg=NONE gui=underline endfunction endif " }}} " ファイルタイプ {{{ " vim-markdown let g:markdown_fenced_languages = [ \ 'c', 'cpp', 'cs', 'go', \ 'ruby', 'lua', 'python', \ 'vim', \ 'toml', \ 'xml', 'json' \ ] " vim-autoft let g:autoft_config = [ \ {'filetype': 'cs', 'pattern': '^\s*using' }, \ {'filetype': 'cpp', 'pattern': '^\s*#\s*\%(include\|define\)\>'}, \ {'filetype': 'xml', 'pattern': '<[0-9a-zA-Z]\+' } \ ] " }}} " テキストオブジェクト {{{ xmap aa (textobj-parameter-a) xmap ia (textobj-parameter-i) omap aa (textobj-parameter-a) omap ia (textobj-parameter-i) xmap a. (textobj-wiw-a) xmap i. (textobj-wiw-i) omap a. (textobj-wiw-a) omap i. (textobj-wiw-i) " }}} " オペレータ {{{ nmap R (operator-replace) xmap R (operator-replace) nmap t (operator-tcomment) xmap t (operator-tcomment) nmap _ (operator-camelize-toggle) xmap _ (operator-camelize-toggle) map S (operator-surround-append) nmap Sd (operator-surround-delete)ab nmap Sr (operator-surround-replace)ab nmap r (operator-rengbang) xmap r (operator-rengbang) nmap j (operator-jump-toggle) xmap j (operator-jump-toggle) " vim-operator-surround let g:operator#surround#blocks = { \ '-': [ \ { \ 'block': ["{\", "\}"], \ 'motionwise': ['line' ], \ 'keys': ['{', '}' ] \ } \ ] \ } " }}} " アプリ {{{ " lingr-vim noremap [App]1 :call toggle_lingr() let g:lingr_vim_say_buffer_height = 15 AutocmdFT lingr-rooms,lingr-members,lingr-messages \ nnoremap q :call toggle_lingr() AutocmdFT lingr-rooms,lingr-members,lingr-messages \ nmap ss (lingr-messages-show-say-buffer) AutocmdFT lingr-rooms,lingr-members,lingr-messages setlocal nolist AutocmdFT lingr-rooms,lingr-members setlocal nonumber function! s:toggle_lingr() if bufnr('lingr-messages') == -1 tabnew LingrLaunch wincmd l else LingrExit endif endfunction " vimshell.vim noremap [App]s :VimShellPop let g:vimshell_popup_height = 40 let g:vimshell_prompt_pattern = '^\%(\f\|\\.\)\+> ' let g:vimshell_prompt_expr = \ 'escape(substitute(fnamemodify(getcwd(), ":~").">", "\\", "/", "g"), "\\[]()?! ")." "' " vimfiler.vim if neobundle#tap('vimfiler.vim') noremap [App]f :VimFilerBufferDir function! neobundle#hooks.on_source(bundle) AutocmdFT vimfiler nmap \ vimfiler#smart_cursor_map('(vimfiler_cd_file)', \ '(vimfiler_edit_file)') AutocmdFT vimfiler nmap \ vimfiler#smart_cursor_map('(vimfiler_exit)', \ '(vimfiler_exit)') AutocmdFT vimfiler nnoremap J :Unite bookmark AutocmdFT vimfiler nnoremap / :Unite file -horizontal let g:vimfiler_as_default_explorer = 1 let g:vimfiler_force_overwrite_statusline = 0 let g:vimfiler_ignore_pattern = [] let g:vimfiler_tree_leaf_icon = ' ' let g:vimfiler_readonly_file_icon = '⭤' let g:unite_kind_file_use_trashbox = 1 call vimfiler#custom#profile('default', 'context', {'auto_cd': 1}) endfunction endif " memolist.vim noremap [App]mn :MemoNew noremap [App]ml :MemoList noremap [App]mg :MemoGrep let g:memolist_unite = 1 let g:memolist_memo_suffix = 'md' let g:memolist_unite_source = 'memolist' let g:memolist_path = '~/Dropbox/memo' " wandbox-vim if neobundle#tap('wandbox-vim') function! neobundle#hooks.on_source(bundle) " wandbox.vim で quickfix を開かないようにする let g:wandbox#open_quickfix_window = 0 let g:wandbox#default_compiler = {'cpp': 'clang-head'} endfunction endif " vim-quickrun noremap [App]r :QuickRun let g:quickrun_config = { \ '_': { \ 'hook/close_unite_quickfix/enable_hook_loaded': 1, \ 'hook/unite_quickfix/enable_failure': 1, \ 'hook/close_quickfix/enable_exit': 1, \ 'hook/close_buffer/enable_failure': 1, \ 'hook/close_buffer/enable_empty_data': 1, \ 'outputter': 'multi:buffer:quickfix', \ 'runner': 'vimproc', \ 'runner/vimproc/updatetime': 40 \ }, \ 'cpp/wandbox': { \ 'runner': 'wandbox', \ 'runner/wandbox/compiler': 'clang-head', \ 'runner/wandbox/options': 'warning,c++1y,boost-1.55' \ }, \ 'lua': { \ 'type': 'lua/vim' \ } \ } " vim-icondrag if s:is_windows if neobundle#tap('vim-icondrag') function! neobundle#hooks.on_source(bundle) call icondrag#enable() endfunction endif endif " open-browser.vim let g:openbrowser_no_default_menus = 1 " }}} " Unite {{{ " unite.vim if neobundle#tap('unite.vim') nnoremap [Unite] xnoremap [Unite] nmap [Unite] xmap [Unite] nnoremap [Unite]cg :Unite -no-split -buffer-name=grep grep nnoremap [Unite]gg :Unite -no-split -buffer-name=grep grep:. nnoremap [Unite]ccg :Unite -no-split -buffer-name=grep grep:.. nnoremap [Unite]cccg :Unite -no-split -buffer-name=grep grep:../.. nnoremap [Unite]pg :Unite -no-split -buffer-name=grep grep:! nnoremap [Unite]f :Unite -buffer-name=buffer buffer nnoremap [Unite]j :Unite -buffer-name=bookmark bookmark nnoremap [Unite]l :Unite -no-split -buffer-name=line line nnoremap [Unite]o :Unite -vertical -buffer-name=outline outline nnoremap [Unite]q :Unite -no-quit -buffer-name=quickfix quickfix nnoremap [Unite]m :Unite -no-split -buffer-name=neomru/file neomru/file nnoremap [Unite]v :call execute_if_on_git_branch( \ 'Unite -no-split -buffer-name=giti giti') nnoremap [Unite]b :call execute_if_on_git_branch( \ 'Unite -no-split -buffer-name=giti/branch_all giti/branch_all') nnoremap [Unite]rr :UniteResume nnoremap [Unite]rg :UniteResume grep nnoremap [Unite]rf :UniteResume buffer nnoremap [Unite]rj :UniteResume bookmark nnoremap [Unite]rl :UniteResume line nnoremap [Unite]ro :UniteResume outline nnoremap [Unite]rq :UniteResume quickfix nnoremap [Unite]rm :UniteResume neomru/file nnoremap [Unite]rv :UniteResume giti nnoremap [Unite]rb :UniteResume giti/branch_all if s:is_windows nnoremap [Unite]e :Unite -no-split -buffer-name=everything everything nnoremap [Unite]re :UniteResume everything endif function! neobundle#hooks.on_source(bundle) let g:unite_force_overwrite_statusline = 0 let g:unite_source_alias_aliases = {'memolist': {'source': 'file'}} if executable('pt') let g:unite_source_grep_command = 'pt' let g:unite_source_grep_default_opts = '--nogroup --nocolor -S' let g:unite_source_grep_recursive_opt = '' let g:unite_source_grep_encoding = 'utf-8' let g:unite_source_grep_max_candidates = 1000 let g:unite_source_rec_async_command = 'pt --nocolor --nogroup -g .' endif call unite#custom#profile('default', 'context', { \ 'direction': 'rightbelow', \ 'hide_icon': 0, \ 'ignorecase': 1, \ 'prompt': '>>', \ 'prompt_direction': 'top', \ 'smartcase': 1, \ 'start_insert': 1, \ 'vertical': 0, \ 'winwidth': 60 \ }) call unite#custom_default_action('source/bookmark/directory', 'vimfiler') call unite#custom_default_action('directory', 'vimfiler') call unite#custom_default_action('neomru/directory', 'vimfiler') call unite#custom#source('memolist', 'sorters', ['sorter_ftime', 'sorter_reverse']) call unite#custom#source('everything', 'max_candidates', 500) AutocmdFT unite nnoremap unite#do_action('replace') AutocmdFT unite inoremap unite#do_action('replace') AutocmdFT unite nmap (unite_toggle_auto_preview) AutocmdFT unite imap (unite_toggle_auto_preview) AutocmdFT unite nmap (unite_exit) endfunction endif " neomru.vim if neobundle#tap('neomru.vim') function! neobundle#hooks.on_source(bundle) let g:neomru#update_interval = 1 let g:neomru#file_mru_ignore_pattern = 'fugitiveblame' endfunction endif " vim-unite-giti Autocmd User UniteGitiGitExecuted call s:update_fugitive() " unite-everything if s:is_windows let g:unite_source_everything_full_path_search = 1 endif " }}} " C# {{{ " omnisharp-vim let g:omnicomplete_fetch_full_documentation = 1 let g:Omnisharp_stop_server = 0 let g:OmniSharp_typeLookupInPreview = 0 " }}} " C++ {{{ " vim-clang-format if s:is_windows let g:clang_format#command = 'C:/Development/LLVM/bin/clang-format.exe' endif let g:clang_format#style_options = { \ 'AccessModifierOffset': -4, \ 'AllowShortIfStatementsOnASingleLine': 'false', \ 'AlwaysBreakBeforeMultilineStrings': 'false', \ 'BreakBeforeBraces': 'Allman', \ 'BreakConstructorInitializersBeforeComma': 'true', \ 'ColumnLimit': 0, \ 'ConstructorInitializerAllOnOneLineOrOnePerLine': 'false', \ 'IndentCaseLabels': 'true', \ 'IndentWidth': 4, \ 'UseTab': 'Never' \ } " }}} " Go {{{ " gocode if s:is_windows " todo: macだと補完候補が出てこなくなる let g:gocomplete#system_function = 'vimproc#system' endif " vim-godef let g:godef_split = 0 let g:godef_same_file_in_same_window = 1 let g:godef_system_function = 'vimproc#system' " }}} " Git {{{ " vim-gitgutter let g:gitgutter_map_keys = 0 let g:gitgutter_eager = 0 " let g:gitgutter_diff_args = '-w' let g:gitgutter_diff_args = '' " todo:シンタックスハイライトが無効にになってしまうことがある。 " 無効でもなってしまうことがある let g:gitgutter_sign_column_always = 1 Autocmd FocusGained,FocusLost * GitGutter " agit.vim if s:is_windows let g:agit_enable_auto_show_commit = 0 endif " vim-fugitive Autocmd FocusGained,FocusLost * call s:update_fugitive() function! s:update_fugitive() try call fugitive#detect(expand(':p')) call lightline#update() catch endtry endfunction " }}} call neobundle#end() filetype plugin indent on " }}} " ファイルタイプごとの設定 {{{ Autocmd BufEnter,WinEnter,BufWinEnter * call s:update_all() Autocmd BufWritePost * call s:update_numberwidth() Autocmd BufNewFile,BufRead *.xaml setlocal filetype=xml Autocmd BufNewFile,BufRead *.json setlocal filetype=json Autocmd BufNewFile,BufRead *.{fx,fxc,fxh,hlsl,hlsli} setlocal filetype=hlsl Autocmd BufNewFile,BufRead *.{fsh,vsh} setlocal filetype=glsl Autocmd BufNewFile,BufRead *.{md,mkd,markdown} setlocal filetype=markdown AutocmdFT ruby setlocal foldmethod=syntax AutocmdFT ruby setlocal tabstop=2 AutocmdFT ruby setlocal shiftwidth=2 AutocmdFT ruby setlocal softtabstop=2 AutocmdFT vim setlocal foldmethod=marker AutocmdFT vim setlocal foldlevel=0 AutocmdFT vim setlocal foldcolumn=5 AutocmdFT vim setlocal tabstop=2 AutocmdFT vim setlocal shiftwidth=2 AutocmdFT vim setlocal softtabstop=2 AutocmdFT xml,html setlocal foldmethod=syntax AutocmdFT xml,html setlocal foldlevel=99 AutocmdFT xml,html setlocal foldcolumn=5 AutocmdFT xml,html inoremap AutocmdFT xml,html let g:xml_syntax_folding = 1 AutocmdFT go setlocal foldmethod=syntax AutocmdFT go setlocal shiftwidth=4 AutocmdFT go setlocal noexpandtab AutocmdFT go setlocal tabstop=4 AutocmdFT go nnoremap K :Godoc \ zz \ :call refresh_screen() AutocmdFT go nnoremap :call GodefUnderCursor() \ zz \ :call refresh_screen() AutocmdFT c,cpp setlocal foldmethod=syntax AutocmdFT c,cpp nnoremap [App]r :QuickRun cpp/wandbox AutocmdFT c,cpp nnoremap :UniteWithCursorWord \ -immediately -buffer-name=tag tag AutocmdFT cs setlocal omnifunc=OmniSharp#Complete AutocmdFT cs setlocal foldmethod=syntax AutocmdFT cs nnoremap :call OmniSharp#GotoDefinition() \ zz \ :call refresh_screen() AutocmdFT typescript setlocal omnifunc=TSScompleteFunc AutocmdFT json setlocal shiftwidth=2 AutocmdFT neosnippet setlocal noexpandtab AutocmdFT godoc nnoremap q :close AutocmdFT help nnoremap q :close AutocmdFT markdown nnoremap [App]v :PrevimOpen function! s:update_all() setlocal formatoptions-=r setlocal formatoptions-=o setlocal textwidth=0 call s:update_numberwidth() " ファイルの場所をカレントにする if &filetype !=# 'vimfiler' silent! execute 'lcd' fnameescape(expand('%:p:h')) endif endfunction function! s:update_numberwidth() " 行番号表示幅を設定する " http://d.hatena.ne.jp/osyo-manga/20140303/1393854617 let w = len(line('$')) + 2 if w < 5 let w = 5 endif let &l:numberwidth = w endfunction " 場所ごとに設定を用意する {{{ " http://vim-jp.org/vim-users-jp/2009/12/27/Hack-112.html Autocmd BufNewFile,BufReadPost * let s:files = \ findfile('.vimrc.local', escape(expand(':p:h'), ' ') . ';', -1) \| for s:i in reverse(filter(s:files, 'filereadable(v:val)')) \| source `=s:i` \| endfor " }}} " }}} " キー無効 {{{ " Vimを閉じない nnoremap ZQ " Exモード nnoremap Q " ミス操作で削除してしまうため nnoremap dh nnoremap dj nnoremap dk nnoremap dl " よくミスるため vnoremap u onoremap u inoremap " }}} " 編集 {{{ set browsedir=buffer " バッファで開いているファイルのディレクトリ set clipboard=unnamedplus,unnamed " クリップボードを使う set modeline set virtualedit=block set autoread set whichwrap=b,s,h,l,<,>,[,] " カーソルを行頭、行末で止まらないようにする set mouse=a " 全モードでマウスを有効化 set hidden " 変更中のファイルでも、保存しないで他のファイルを表示 set timeoutlen=2000 set nrformats-=octal set nrformats+=alpha set completeopt=longest,menuone set backspace=indent,eol,start set noswapfile set nobackup set formatoptions+=j set tags=tags,./tags,../tags,../../tags,../../../tags,../../../../tags,../../../../../tags " 文字コード自動判断 if has('guess_encode') set fileencodings=guess,iso-2022-jp,cp932,euc-jp,ucs-bom else set fileencodings=iso-2022-jp,cp932,euc-jp,ucs-bom endif " ^Mを取り除く command! RemoveCr call s:execute_keep_view('silent! %substitute/\r$//g | nohlsearch') " 行末のスペースを取り除く command! RemoveEolSpace call s:execute_keep_view('silent! %substitute/ \+$//g | nohlsearch') " 整形 command! Format call s:execute_keep_view('call s:format()') function! s:format() if &filetype ==# 'cs' OmniSharpCodeFormat elseif &filetype ==# 'c' ClangFormat elseif &filetype ==# 'cpp' ClangFormat elseif &filetype ==# 'go' call s:filter_current('goimports %s', 0) elseif &filetype ==# 'javascript' && executable('js-beautify') call s:filter_current('js-beautify %s', 0) elseif &filetype ==# 'xml' let $XMLLINT_INDENT = ' ' if !s:filter_current('xmllint --format --encode ' . &encoding . ' %s', 1) execute 'silent! %substitute/>\s*\r gv vnoremap gv nmap V vnoremap :call copy_add_comment() " http://qiita.com/akira-hamada/items/2417d0bcb563475deddb をもとに調整 function! s:copy_add_comment() range " 選択中の行をヤンクする normal! ""gvy " コメントアウトする call tcomment#Comment(line("'<"), line("'>"), 'i', '', '') " 元の位置に戻る execute 'normal!' (line("'>") - line("'<") + 1) . 'j' " ヤンクした物をペーストする normal! P endfunction " }}} " インプットメソッド {{{ " macvim kaoriya gvim で submode が正しく動作しなくなるため if !(s:is_mac && s:has_gui_running) set noimdisable endif set imsearch=0 set iminsert=0 if exists('+imdisableactivate') set imdisableactivate endif " }}} " タブ・インデント {{{ set autoindent set cindent set tabstop=4 " ファイル内の が対応する空白の数 set softtabstop=4 " の挿入や の使用等の編集操作をするときに が対応する空白の数 set shiftwidth=4 " インデントの各段階に使われる空白の数 set expandtab " Insertモードで を挿入するとき、代わりに適切な数の空白を使う set list set listchars=tab:\⭟\ ,eol:↲,extends:»,precedes:«,nbsp:% set breakindent vnoremap < >gv " }}} " 検索 {{{ set incsearch set ignorecase set smartcase set hlsearch " 日本語インクリメンタルサーチ if s:has_kaoriya set migemo set migemodict=$VIMRUNTIME/dict/migemo-dict endif " http://haya14busa.com/enrich-your-search-experience-with-incsearch-vim/ map / (incsearch-forward) map ? (incsearch-backward) map n (incsearch-nohl-n) map N (incsearch-nohl-N) nmap n (incsearch-nohl) \ (anzu-n) \ zvzz \ :call begin_display_anzu() nmap N (incsearch-nohl) \ (anzu-N) \ zvzz \ :call begin_display_anzu() map * (incsearch-nohl0)(asterisk-z*) map g* (incsearch-nohl0)(asterisk-gz*) map # (incsearch-nohl0)(asterisk-z#) map g# (incsearch-nohl0)(asterisk-gz#) " }}} " 表示 {{{ syntax enable " 構文ごとに色分けをする set number set textwidth=0 " 一行に長い文章を書いていても自動折り返しをしない set showcmd " コマンドをステータス行に表示 set noshowmatch " 括弧の対応をハイライト set wrap set noshowmode set shortmess+=I " 起動時のメッセージを表示しない set lazyredraw set wildmenu set wildmode=list:full set showfulltag set wildoptions=tagfile set fillchars=vert:\ " 縦分割の境界線 set synmaxcol=500 " ハイライトする文字数を制限する set updatetime=250 set previewheight=24 set cmdheight=4 set laststatus=2 set showtabline=2 set diffopt=vertical,filler set noequalalways set cursorline set display=lastline set conceallevel=2 set concealcursor=i set colorcolumn=100 if s:has_gui_running set lines=100 execute 'set columns=' . s:base_columns endif Autocmd VimEnter * set t_vb= Autocmd VimEnter * set visualbell Autocmd VimEnter * set errorbells nnoremap gf :call smart_gf('n') vnoremap gf :call smart_gf('v') function! s:smart_gf(mode) try let line = getline('.') let repos_name = matchstr(line, 'repository\s\+=\s\+''\zs.\{-}\ze''') if !empty(repos_name) " NeoBundle execute 'OpenBrowser https://github.com/' . repos_name elseif !empty(openbrowser#get_url_on_cursor()) " URL call openbrowser#_keymapping_smart_search(a:mode) else " 標準のgf normal! gf endif catch " 検索 call openbrowser#_keymapping_search(a:mode) endtry endfunction " カーソル下の単語を移動するたびにハイライトする {{{ " http://d.hatena.ne.jp/osyo-manga/20140121/1390309901 Autocmd CursorHold * call s:hl_cword() Autocmd CursorMoved,BufLeave,WinLeave,InsertEnter * call s:hl_clear() Autocmd ColorScheme * highlight CursorWord guifg=Red function! s:hl_clear() if exists('b:highlight_cursor_word_id') && exists('b:highlight_cursor_word') silent! call matchdelete(b:highlight_cursor_word_id) unlet b:highlight_cursor_word_id unlet b:highlight_cursor_word endif endfunction function! s:hl_cword() let word = expand('') if empty(word) return endif if get(b:, 'highlight_cursor_word', '') ==# word return endif call s:hl_clear() if !empty(filter(split(word, '\zs'), 'strlen(v:val) > 1')) return endif let pattern = printf('\<%s\>', expand('')) silent! let b:highlight_cursor_word_id = matchadd('CursorWord', pattern) let b:highlight_cursor_word = word endfunction " }}} " カラースキーマ {{{ colorscheme molokai Autocmd BufWinEnter,ColorScheme * call s:set_color() function! s:set_color() " ^M を非表示 syntax match HideCtrlM containedin=ALL /\r$/ conceal " 日本語入力時カーソル色を変更する highlight CursorIM guifg=NONE guibg=Red if !&readonly " 全角スペースとタブ文字の可視化 syntax match InvisibleJISX0208Space ' ' display containedin=ALL syntax match InvisibleTab '\t' display containedin=ALL highlight InvisibleJISX0208Space guibg=#112233 highlight InvisibleTab guibg=#121212 endif endfunction " }}} " 半透明化 {{{ if s:has_gui_running if s:is_mac Autocmd GuiEnter,FocusGained * set transparency=3 " アクティブ時の透過率 Autocmd FocusLost * set transparency=48 " 非アクティブ時の透過率 endif endif " }}} " フォント {{{ if s:has_gui_running set guifont=Ricty\ Regular\ for\ Powerline:h12 endif if s:is_windows && s:has_kaoriya set ambiwidth=auto else set ambiwidth=double endif " }}} " 'cursorline' を必要な時にだけ有効にする {{{ " http://d.hatena.ne.jp/thinca/20090530/1243615055 Autocmd CursorMoved,CursorMovedI * call s:auto_cursorline('CursorMoved') Autocmd CursorHold,CursorHoldI * call s:auto_cursorline('CursorHold') Autocmd WinEnter * call s:auto_cursorline('WinEnter') Autocmd WinLeave * call s:auto_cursorline('WinLeave') let s:cursorline_lock = 0 function! s:auto_cursorline(event) if s:is_unite_running() return endif if a:event ==# 'WinEnter' setlocal cursorline let s:cursorline_lock = 2 elseif a:event ==# 'WinLeave' setlocal nocursorline elseif a:event ==# 'CursorMoved' if s:cursorline_lock if 1 < s:cursorline_lock let s:cursorline_lock = 1 else setlocal nocursorline let s:cursorline_lock = 0 endif endif elseif a:event ==# 'CursorHold' setlocal cursorline let s:cursorline_lock = 1 endif endfunction function! s:force_show_cursorline() if s:is_unite_running() return endif setlocal cursorline let s:cursorline_lock = 1 endfunction " }}} " }}} " 折り畳み {{{ set foldcolumn=0 set foldlevel=99 nnoremap zo zR nnoremap zc zM nnoremap zh foldlevel(line('.')) > 0 ? 'zc' : '' nnoremap zl foldclosed(line('.')) != -1 ? 'zo' : '' " 折り畳み外であれば何もしない nnoremap zO foldclosed(line('.')) != -1 ? 'zO' : '' " }}} " モード移行 {{{ if !(s:is_mac && s:has_gui_running) inoremap nnoremap vnoremap cnoremap else inoremap :set noimdisable:set imdisable nnoremap :set noimdisable:set imdisable vnoremap :set noimdisable:set imdisable cnoremap :set noimdisable:set imdisable endif " }}} " コマンドラインモード {{{ cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap " }}} " カーソル移動 {{{ nnoremap k :call up_cursor(v:count1) nnoremap j :call down_cursor(v:count1) nnoremap h :call left_cursor(v:count1) nnoremap l :call right_cursor(v:count1) vnoremap k gk vnoremap j gj nnoremap 0 g0 nnoremap g0 0 nnoremap $ :set virtualedit=blockg$:set virtualedit=all nnoremap g$ :set virtualedit=block$:set virtualedit=all nnoremap j nnoremap k vnoremap j vnoremap k nnoremap gg ggzvzz:call refresh_screen() nnoremap G Gzvzz:call refresh_screen() nnoremap zz:call refresh_screen() nnoremap zz:call refresh_screen() nnoremap ^:set virtualedit=all nnoremap $:set virtualedit=all vnoremap ^ vnoremap $ nmap (jumpbrace) xmap (jumpbrace) nmap (operator-jump-toggle)ai xmap (operator-jump-toggle)ai nnoremap m ` function! s:up_cursor(repeat) call s:enable_virtual_cursor() execute 'normal!' a:repeat . 'gk' endfunction function! s:down_cursor(repeat) call s:enable_virtual_cursor() execute 'normal!' a:repeat . 'gj' endfunction function! s:left_cursor(repeat) call s:disable_virtual_cursor() execute 'normal!' a:repeat . 'h' endfunction function! s:right_cursor(repeat) call s:disable_virtual_cursor() execute 'normal!' a:repeat . 'l' if foldclosed(line('.')) != -1 normal! zv endif endfunction function! s:enable_virtual_cursor() set virtualedit=all endfunction function! s:disable_virtual_cursor() set virtualedit=block endfunction Autocmd InsertEnter * call s:disable_virtual_cursor() " }}} " ウィンドウ操作 {{{ set splitbelow " 縦分割したら新しいウィンドウは下に set splitright " 横分割したら新しいウィンドウは右に nnoremap c :close " }}} " アプリウィンドウ操作 {{{ nnoremap [Window] nmap w [Window] if s:has_gui_running noremap [Window]e :call toggle_v_split_wide() noremap [Window]f :call full_window() noremap [Window]H :ResizeWin noremap [Window]J :ResizeWin noremap [Window]K :ResizeWin noremap [Window]L :ResizeWin noremap [Window]h :MoveWin noremap [Window]j :MoveWin noremap [Window]k :MoveWin noremap [Window]l :MoveWin " アプリケーションウィンドウを最大高さにする {{{ function! s:full_window() execute 'winpos' getwinposx() '0' set lines=9999 endfunction " }}} " 縦分割する {{{ let s:depth_vsp = 1 let s:opend_left_vsp = 0 let s:opend_top_vsp = 0 function! s:toggle_v_split_wide() if s:depth_vsp <= 1 call s:open_v_split_wide() else call s:close_v_split_wide() endif endfunction function! s:open_v_split_wide() if s:depth_vsp == 1 let s:opend_left_vsp = getwinposx() let s:opend_top_vsp = getwinposy() endif let s:depth_vsp += 1 let &columns = s:base_columns * s:depth_vsp execute 'botright vertical' s:base_columns 'split' endf function! s:close_v_split_wide() let s:depth_vsp -= 1 let &columns = s:base_columns * s:depth_vsp only if s:depth_vsp == 1 execute 'winpos' s:opend_left_vsp s:opend_top_vsp end endf " }}} endif " }}} " タブ操作 {{{ nnoremap [Tab] nmap t [Tab] nnoremap [Tab]c :tabnew nnoremap [Tab]x :tabclose " }}} " バッファ操作 {{{ nnoremap x :call delete_current_buffer() " ウィンドウをとじないで現在のバッファを削除 {{{ function! s:delete_current_buffer() let confirm_msg = '未保存です。閉じますか?' let current_win = winnr() let current_buf = winbufnr(current_win) let is_current_buf_modified = getbufvar(current_buf, '&modified') let buf_list = filter(range(1, bufnr('$')), 'buflisted(v:val)') if len(buf_list) == 1 if !is_current_buf_modified bdelete elseif confirm(confirm_msg, "&Yes\n&No", 1, 'Question') == 1 bdelete! endif return endif if is_current_buf_modified if confirm(confirm_msg, "&Yes\n&No", 1, 'Question') != 1 return endif endif let next_buf_index = match(buf_list, current_buf) + 1 if next_buf_index == len(buf_list) let next_buf_index = 0 endif let next_buf = buf_list[next_buf_index] while 1 let winnr = bufwinnr(current_buf) if winnr == -1 break endif execute winnr . 'wincmd w' execute 'buffer' next_buf endwhile execute 'bdelete' current_buf execute current_win . 'wincmd w' endfunction " }}} " }}} " Git {{{ nnoremap [Git] nmap g [Git] nnoremap [Git]b :call execute_if_on_git_branch('Gblame w') nnoremap [Git]a :call execute_if_on_git_branch('Gwrite') nnoremap [Git]c :call execute_if_on_git_branch('Gcommit') nnoremap [Git]f :call execute_if_on_git_branch('GitiFetch') nnoremap [Git]d :call execute_if_on_git_branch('Gdiff') nnoremap [Git]s :call execute_if_on_git_branch('Gstatus') nnoremap [Git]ps :call execute_if_on_git_branch('Gpush') nnoremap [Git]pl :call execute_if_on_git_branch('Gpull') nnoremap [Git]g :call execute_if_on_git_branch('Agit') nnoremap [Git]h :call execute_if_on_git_branch('GitGutterPreviewHunk') " }}} " ヘルプ {{{ set helplang=ja,en set keywordprg= if s:has_kaoriya set runtimepath+=$VIM/plugins/vimdoc-ja endif " }}} " 汎用関数 {{{ " CursorHold を継続させる{{{ function! s:continue_cursor_hold() " http://d.hatena.ne.jp/osyo-manga/20121102/1351836801 call feedkeys(mode() ==# 'i' ? "\\" : "g\", 'n') endfunction " }}} " 画面リフレッシュ{{{ function! s:refresh_screen() call s:force_show_cursorline() endfunction " }}} " コマンド実行後の表示状態を維持する {{{ function! s:execute_keep_view(expr) let wininfo = winsaveview() execute a:expr call winrestview(wininfo) endfunction " }}} " Unite 実行中か {{{ function! s:is_unite_running() return &filetype ==# 'unite' endfunction " }}} " Gitブランチ上にいるか {{{ function! s:is_in_git_branch() try return !empty(fugitive#head()) catch return 0 endtry endfunction " }}} " Gitブランチ上であれば実行 {{{ function! s:execute_if_on_git_branch(line) if !s:is_in_git_branch() echomsg 'not on git branch:' a:line return endif execute a:line endfunction " }}} " フィルタリング処理を行う {{{ function! s:filter_current(cmd, is_silent) let retval = 255 try let tempfile = tempname() call writefile(getline(1, '$'), tempfile) let formatted = vimproc#system(printf(a:cmd, substitute(tempfile, '\', '/', 'g'))) let retval = vimproc#get_last_status() if retval == 0 call setreg('g', formatted, 'v') silent keepjumps normal! ggVG"gp else if !a:is_silent echomsg 'filter_current: Error' endif endif finally call delete(tempfile) endtry return retval == 0 endfunction " }}} " }}} " vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab