" vim:fdm=marker:fmr=§§,■■ " autocmd まわり。 " §§1 表示設定 augroup vimrc " temporal attention の設定初期化 autocmd BufLeave,FocusLost,InsertEnter * setlocal nocursorline autocmd BufLeave,FocusLost,InsertEnter * setlocal nocursorcolumn autocmd BufLeave,FocusLost,InsertEnter * setlocal norelativenumber augroup END " 全角スペース強調 " https://qiita.com/tmsanrinsha/items/d6c11f2b7788eb24c776 augroup vimrc autocmd ColorScheme * highlight link UnicodeSpaces Error autocmd VimEnter,WinEnter * highlight link UnicodeSpaces Error autocmd VimEnter,WinEnter * match UnicodeSpaces \ /\%u180E\|\%u2000\|\%u2001\|\%u2002\|\%u2003\|\%u2004\|\%u2005\|\%u2006\|\%u2007\|\%u2008\|\%u2009\|\%u200A\|\%u2028\|\%u2029\|\%u202F\|\%u205F\|\%u3000/ augroup END " window/buffer augroup vimrc autocmd VimResized * call resizeFloatingWindow() autocmd VimResized * exe "normal \=" augroup END function s:resizeFloatingWindow() if exists('*ResizeDefxFloatingWindow') call ResizeDefxFloatingWindow() endif if exists('*ResizeDeniteFloatingWindow') call ResizeDeniteFloatingWindow() endif endfunction " §§1 .vimrc.local augroup vimrc autocmd VimEnter * 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 " §§1 editor の機能 autocmd vimrc InsertLeave * set nopaste " Automatically create missing directories " thanks to lambdalisue autocmd vimrc BufWritePre * call s:auto_mkdir(expand(':p:h'), v:cmdbang) function! s:auto_mkdir(dir, force) abort if empty(a:dir) || a:dir =~# '^\w\+://' || isdirectory(a:dir) || a:dir =~# '^suda:' return endif if !a:force echohl Question call inputsave() try let result = input( \ printf('"%s" does not exist. Create? [y/N]', a:dir), \ '', \) if empty(result) echohl WarningMsg echo 'Canceled' return endif finally call inputrestore() echohl None endtry endif call mkdir(a:dir, 'p') endfunction " 無名レジスタへの yank 操作のときのみ, + レジスタに内容を移す(delete のときはしない) augroup vimrc if exists('##TextYankPost') autocmd TextYankPost * call copyUnnamedToPlus(v:event) endif augroup END function! s:copyUnnamedToPlus(event) if a:event.operator ==# 'y' && a:event.regname ==# '' let @+ = @" endif endfunction augroup vimrc " マクロ用のレジスタを消去 autocmd VimEnter * let @q = '' augroup END " §§1 Quickfix augroup vimrc autocmd QuickfixCmdPost [^l]* cwin autocmd QuickfixCmdPost l* lwin augroup END " §§1 Command-line window " let &cedit = "\" cnoremap " 特定の文字を入力したら自動でコマンドラインウィンドウに切り替わるようにする " → abbrev が効かなくなるので一旦保留 " cnoremap getcmdtype() ==# ":" ? "\\" : "\" " cnoremap \ (getcmdtype() ==# "/" getcmdtype() ==# "?") ? "\\" : '\' augroup vimrc autocmd CmdwinEnter * setlocal nonumber autocmd CmdwinEnter * setlocal norelativenumber autocmd CmdwinEnter * setlocal signcolumn=no autocmd CmdwinEnter * setlocal foldcolumn=0 autocmd CmdwinEnter * nnoremap autocmd CmdwinEnter * nnoremap autocmd CmdwinEnter * nnoremap autocmd CmdwinEnter * nnoremap autocmd CmdwinEnter * nnoremap :q autocmd CmdwinEnter * nnoremap " autocmd CmdwinEnter : keeppatterns g/^qa\?!\?$/d _ " autocmd CmdwinEnter : keeppatterns g/^wq\?a\?!\?$/d _ " autocmd CmdwinEnter : keeppatterns g/^e$/d _ " autocmd CmdwinEnter * $ " autocmd CmdwinEnter * startinsert! augroup END " Instant Visual Highlight " Thanks to woodyZootopia " https://github.com/woodyZootopia/nvim/blob/81047bbf893570cd0d832ef3ec076f278087dc6b/autocmd.vim#L44-L71 augroup vimrc autocmd WinLeave * call free_visual_match() autocmd CursorMoved,CursorHold * call visual_match() augroup END vnoremap call free_visual_match() function! s:visual_match() call s:free_visual_match() if index(['v', ''], mode()) != -1 && line('v') == line('.') let len_of_char_of_v = strlen(matchstr(getline('v'), '.', col('v')-1)) let len_of_char_of_dot = strlen(matchstr(getline('.'), '.', col('.')-1)) let first = min([col('v') - 1, col('.') - 1]) let last = max([col('v') - 2 + len_of_char_of_v, col('.') - 2 + len_of_char_of_dot]) let w:visual_match_id = matchadd('VisualBlue', '\C\V' .. escape(getline('.')[first:last], '\')) endif endfunction function! s:free_visual_match() if exists("w:visual_match_id") call matchdelete(w:visual_match_id) unlet w:visual_match_id endif endfunction