" Insert & Comandline Mode "{{{ let mapleader = "\" " カレントディレクトリ設定 command! -nargs=0 CdCurrent cd %:p:h nnoremap ,d :CdCurrent nnoremap } nnoremap { " nnoremap :keepjumps normal! } " nnoremap :keepjumps normal! { vnoremap } vnoremap { nnoremap j gj nnoremap k gk nnoremap gj j nnoremap gk k nnoremap gf gF nnoremap gF gf vnoremap H 10h vnoremap J 5gj vnoremap K 5gk vmap K 5gk vnoremap L 10l inoremap / inoremap ?/ inoremap → inoremap → xnoremap a" 2i" xnoremap a' 2i' xnoremap a` 2i` onoremap a" 2i" onoremap a' 2i' onoremap a` 2i` " move window nnoremap w " 単語移動 if has("mac") nnoremap :call jasegment#MoveN(g:jasegment#model, 'jasegment#MoveB', v:count1, 0, 0, 0) nnoremap :call jasegment#MoveN(g:jasegment#model, 'jasegment#MoveW', v:count1, 0, 0, 0) inoremap inoremap else nnoremap :call jasegment#MoveN(g:jasegment#model, 'jasegment#MoveB', v:count1, 0, 0, 0) nnoremap :call jasegment#MoveN(g:jasegment#model, 'jasegment#MoveW', v:count1, 0, 0, 0) vnoremap :call jasegment#MoveN(g:jasegment#model, 'jasegment#MoveB', v:count1, 0, 0, 0) vnoremap :call jasegment#MoveN(g:jasegment#model, 'jasegment#MoveW', v:count1, 0, 0, 0) inoremap inoremap cnoremap cnoremap endif " " backward nnoremap D :call jasegment#select_function_wrapper(g:jasegment#model, 'jasegment#select_i','o', v:count1)xh function! s:DeleteJapaneseWords() let l:moji = s:prev_cursor_char(0) if l:moji =~ "[。、?!]" return 1 endif let l:moji = s:prev_cursor_char(1) if l:moji =~ "[。、!?]" return 1 endif endfunction au Filetype vim inoremap au Filetype shd,changelog,txt, inoremap DeleteJapaneseWords() ? "\\\" : "\\" function! s:prev_cursor_char(n) let chars = split(getline('.')[0 : col('.')-1], '\zs') let len = len(chars) if a:n >= len return '' else return chars[len(chars) - a:n - 1] endif endfunction nnoremap :nohlsearch ""---------------------------------------------------- " mark nnoremap ,W mW nnoremap ,w `W " leader nnoremap ‚ : nnoremap : : nmap ; nmap : vmap ; vmap : vmap : : nnoremap w :w! " gfでいい感じに開く autocmd FileType html setlocal includeexpr=substitute(v:fname,'^\\/','','') | setlocal path+=;/ "" --------------------------------------------------- " ctags {{{1 " if g:IsWsl() " autocmd FileType php :set tags=/home/takets/php.tags " autocmd BufEnter *.php :set tags=/home/takets/php.tags " autocmd FileType javascript :set tags=/home/takets/jstags " autocmd BufEnter *.js :set tags=/home/takets/jstags " " for linux setting " noremap ,tp :!/home/linuxbrew/.linuxbrew/bin/ctags -r --php-kinds=+cdfint-a --fields=+laims --languages=php -f /home/takets/php.tags /home/takets/source/spider/sp2-php " noremap ,tj :!/home/linuxbrew/.linuxbrew/bin/ctags -r --exclude=\*core.js --exclude=\*.min.js --exclude=\*.debug.js --exclude=node_modules --fields=+laims --languages=javascript -f /home/kf/jstags /home/kf/app/ " " " tagsジャンプの時に複数ある時は一覧表示 " nnoremap g " endif " " if g:IsLinux() " autocmd FileType php :set tags=/home/kf/php.tags " autocmd BufEnter *.php :set tags=/home/kf/php.tags " autocmd FileType javascript :set tags=/home/kf/jstags " autocmd BufEnter *.js :set tags=/home/kf/jstags " " for linux setting " noremap ,tp :!/usr/bin/ctags -R --php-kinds=+cdfint -a --fields=+laims --languages=php -f /home/kf/php.tags /home/kf/app/php " noremap ,tj :!/usr/bin/ctags -R --exclude=\*core.js --exclude=\*.min.js --exclude=\*.debug.js --exclude=node_modules --fields=+laims --languages=javascript -f /home/kf/jstags /home/kf/app/web/js " " " tagsジャンプの時に複数ある時は一覧表示 " nnoremap g " endif " }}}1 " エンコーディング指定オープン {{{1 command! -bang -complete=file -nargs=? Utf8 edit ++enc=utf-8 ++bad=keep command! -bang -complete=file -nargs=? Sjis edit ++enc=cp932 ++bad=keep command! -bang -complete=file -nargs=? Euc edit ++enc=eucjp ++bad=keep command! -bang -complete=file -nargs=? WUtf8 write ++enc=utf-8 ++bad=keep command! -bang -complete=file -nargs=? WSjis write ++enc=cp932 ++bad=keep command! -bang -complete=file -nargs=? WEuc write ++enc=eucjp ++bad=keep " }}}1 " で編集中の Vim script をソース {{{1 if !exists('*s:source_script') " ~/.vimrc をソースすると関数実行中に関数の上書きを行うことになりエラーとなるため " 'function!' による強制上書きではなく if によるガードを行っている function s:source_script(path) abort let path = expand(a:path) if !filereadable(path) return endif execute 'source' fnameescape(path) echomsg printf( \ '"%s" has sourced (%s)', \ simplify(fnamemodify(path, ':~:.')), \ strftime('%c'), \) endfunction endif nnoremap :call source_script('%') " }}}1 " カレントファイルのフルパスをクリプボぅ! {{{ command! CopyCurrentFilepath :let @* = expand("%:p") " }}} " Grep and Open current buffer command! -nargs=1 GrepNow vimgrep % | cwindow " Command line buffer."{{{1 nnoremap (command-line-enter) q: xnoremap (command-line-enter) q: nnoremap (command-line-norange) q: " コマンドラインウィンドウの幅 set cmdwinheight=20 "}}}1 " vを二回で行末まで選択 vnoremap v $h " 現在のバッファを分割して表示 nnoremap BH :vsp :exe("tjump ".expand('')) nnoremap BV :split :exe("tjump ".expand('')) " 画面分割トグル {{{1 let g:toggle_window_size = 0 function! ToggleWindowSize() if g:toggle_window_size == 1 exec "normal \=" let g:toggle_window_size = 0 else :resize :vertical resize let g:toggle_window_size = 1 endif endfunction nnoremap :call ToggleWindowSize() " }}}1 " cn->なんか入力-> . で繰り返し置換できるようになる {{{1 let g:mc = "y/\\V\=escape(@\", '/')\\" nnoremap cn *``cgn nnoremap cN *``cgN vnoremap cn g:mc . "``cgn" vnoremap cN g:mc . "``cgN" " }}}1 " vim type {{{1 " mac gvim {{{2 if g:IsMacGvim() || g:IsMacNeovim() || g:IsWsl() function! s:OpenTentask() if fnamemodify(expand('%'), ':t') == "01_ver01.txt.shd" execute ":VoomQuitAll" endif if expand("%") != "tenTask.txt" && bufnr('tenTask.txt') == -1 execute ":e ~/repos/changelog/tenTask.txt" endif if bufnr('tenTask.txt') != -1 execute ":buffer repos/changelog/tenTask.txt" execute ":e %" endif " 現在のバッファの総行数を取得 let l:total_lines = line('$') " 最後から30行前に移動する行数を計算 let l:start_line = l:total_lines > 30 ? l:total_lines - 29 : 1 " 指定された範囲のテキストを取得 let l:lines = getline(l:start_line, '$') " l:linesを文字列に連結 let l:lines = join(l:lines, " ") echomsg l:lines " 現在のタイムスタンプを取得 let current_timestamp = localtime() " 昨日のタイムスタンプを計算(1日 = 86400秒) let yesterday_timestamp = current_timestamp - 86400 " 昨日の日付をYYYY-MM-DD形式で取得 let yesterday_date = strftime('%Y-%m-%d', yesterday_timestamp) let today_date = strftime('%Y-%m-%d', current_timestamp) " l:linesにyesterday_dateが含まれていて、today_dateが含まれていない場合 let l:found = 0 " if l:lines =~ yesterday_date && l:lines !~ today_date if l:lines !~ today_date let l:found = 1 endif if l:found == 1 call append("$", ['', '--------------------------------------- '.strftime('%Y-%m-%d')]) call append("$", ['----- '.strftime('%Y-%m-%d %H:%M:%S'), '・']) exe "normal! GA" else call append("$", ['----- '.strftime('%Y-%m-%d %H:%M:%S'), '・']) exe "normal! GA" endif endfunction command! OpenTentask call OpenTentask() nnoremap ,t :OpenTentaskGA function! s:OpenOnlyTentask() if fnamemodify(expand('%'), ':t') == "01_ver01.txt.shd" execute ":VoomQuitAll" endif " execute "tabn 2" if expand("%") != "tenTask.txt" && bufnr('tenTask.txt') == -1 execute ":e ~/repos/changelog/tenTask.txt" endif if bufnr('tenTask.txt') != -1 execute ":buffer repos/changelog/tenTask.txt" execute ":e %" endif exe "normal! G" redraw endfunction command! OpenOnlyTentask call OpenOnlyTentask() nnoremap ,T :OpenOnlyTentask " function! s:OpenPraygroundFile() " if fnamemodify(expand('%'), ':t') != "01_ver01.txt.shd" " execute ":e ~/words/prayground/text/01_ver01.txt.shd" " endif " exe 'Voom' " exe 'wincmd l' " redraw " endfunction " command! OpenPraygroundFile call OpenPraygroundFile() " nnoremap ,o :OpenPraygroundFile function! s:OpenChangelog() if fnamemodify(expand('%'), ':t') == "01_ver01.txt.shd" execute ":VoomQuitAll" endif " execute "tabn 3" if expand("%") != "changelogmemo" && bufnr('changelogmemo') == -1 execute ":e ~/repos/changelog/changelogmemo" endif if bufnr('changelogmemo') != -1 execute ":buffer changelog/changelogmemo" endif endfunction " TODO: use noremap! " imap " imap " imap " imap " imap ^ " imap $ cnoremap cnoremap cnoremap cnoremap inoremap / inoremap ?/ cnoremap / inoremap → nnoremap 0i nnoremap 0x nnoremap H 10h nnoremap J 5gj nnoremap K 5gk nmap K 5gk nnoremap L 10l "}}} " Change current directory. " nnoremap ,cd :call cd_buffer_dir() function! s:cd_buffer_dir() let filetype = getbufvar(bufnr('%'), '&filetype') if filetype ==# 'vimfiler' let dir = getbufvar(bufnr('%'), 'vimfiler').current_dir elseif filetype ==# 'vimshell' let dir = getbufvar(bufnr('%'), 'vimshell').save_dir else let dir = isdirectory(bufname('%')) ? \ bufname('%') : fnamemodify(bufname('%'), ':p:h') endif execute 'lcd' fnameescape(dir) endfunction let g:tabpagebuffer#command#bdelete_keeptabpage = 1 inoremap :wa " inoremap j getline('.')[col('.') - 2] ==# 'j' ? "\\" : 'j' " imap i■=strftime("%Y/%m/%d (%a) %H:%M") " nmap i■=strftime("%Y-%m-%d %H:%M:%S") command! OpenChangelog call OpenChangelog() nnoremap ,c :OpenChangelog:set showtabline=2 nnoremap ,l :OpenChangelogoi=neosnippet#expand('cpw') nnoremap ,L :buffer changelogmemooa=neosnippet#expand('cpwd') nnoremap ,Cp :OpenChangelogoi=neosnippet#expand('cpp') " setting reload nnoremap ,rr :source ~/.vimrc:source ~/.gvimrc nnoremap ,RR :Restart " 単語削除 {{{1 function! s:RemoveContextWord() if s:prev_cursor_char(0) =~ "[a-zA-z]" return "\" endif if s:prev_cursor_char(0) =~ "[。、]" return "\" endif if s:prev_cursor_char(1) =~ "[ァ-ヴ一-龠][ァ-ヴ一-龠]" return "\\\" else return "\\" endif return "\\\" endfunction function! s:prev_cursor_char(n) let chars = split(getline('.')[0 : col('.')-1], '\zs') let len = len(chars) if a:n >= len return '' else return chars[len(chars) - a:n - 1] endif endfunction " }}}1 command! RemoveContextWord call s:RemoveContextWord() inoremap RemoveContextWord() nnoremap :nohlsearch endif " }}}2 if g:IsWindowsGvim() set backupdir=$HOME/time_backup nnoremap ,rr :source c:/takeda/tools/vim/vimrc:source c:/takeda/tools/vim/gvimrc nnoremap ,RR :Restart function! s:OpenChangelog() if expand("%") != "changelogmemo" execute ":e c:/takeda/repos/changelog/changelogmemo" endif endfunction command! OpenChangelog call OpenChangelog() nnoremap ,c :OpenChangelog function! s:OpenTentask() if expand("%") != "tenTask.txt" && bufnr('tenTask.txt') == -1 execute ":e c:/takeda/repos/changelog/tenTask.txt" endif call append("$", ['----- '.strftime('%Y-%m-%d %H:%M:%S'), '・']) exe "normal! GkA" redraw endfunction command! OpenTentask call OpenTentask() nnoremap ,c :OpenChangelog nnoremap ,l :buffer changelogmemooa=neosnippet#expand('cpw') nnoremap ,L :buffer changelogmemooa=neosnippet#expand('cpwd') function! s:OpenTentask() if expand("%") != "tenTask.txt" && bufnr('tenTask.txt') == -1 execute ":e c:/takeda/repos/changelog/tentask.txt" endif if bufnr('tenTask.txt') != -1 execute ":buffer c:/takeda/repos/changelog/tentask.txt" endif call append("$", ['----- '.strftime('%Y-%m-%d %H:%M:%S'), '・']) exe "normal! GkA" endfunction command! OpenTentask call OpenTentask() nnoremap ,t :OpenTentaskGA function! s:OpenOnlyTentask() if expand("%") != "tenTask.txt" && bufnr('tenTask.txt') == -1 execute ":e c:/takeda/repos/changelog/tentask.txt" endif if bufnr('tenTask.txt') != -1 execute ":buffer c:/takeda/repos/changelog/tentask.txt" endif exe "normal! Gz+" redraw endfunction command! OpenOnlyTentask call OpenOnlyTentask() nnoremap ,T :OpenOnlyTentask " TODO: use noremap! " imap " imap " imap " imap " imap " imap $ cnoremap cnoremap cnoremap cnoremap inoremap / inoremap ?/ cnoremap / inoremap → " nnoremap 0i " nnoremap 0x nnoremap H 10h nnoremap J 5gj nnoremap K 5gk nmap K 5gk nnoremap L 10l endif " Fast switching to the alternate file " に割り当てると、後にkkkとすると、コマンドが暴発する謎が発生する nnoremap ,a :buffer# nnoremap :buffer# inoremap :SwitchPreviousBuffer nnoremap :SwitchPreviousBuffer function! s:SwitchPreviousBuffer() buffer# endfunction command! SwitchPreviousBuffer call SwitchPreviousBuffer()