Created
February 10, 2018 09:43
-
-
Save koturn/fde4b4ce9d22fcdb88f08fe30c522130 to your computer and use it in GitHub Desktop.
既に開いているターミナルに移動するコマンドの定義
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " 参考: http://secret-garden.hatenablog.com/entry/2017/11/14/113127 | |
| " 既に開いているターミナルを開く(バッファに移動) | |
| " 開いているターミナルが無い場合は新規に起動 | |
| if has('terminal') | |
| function! s:complete_term_bufname(arglead, cmdline, cursorpos) abort " {{{ | |
| let arglead = tolower(a:arglead) | |
| return filter(map(term_list(), 'bufname(v:val)'), '!stridx(tolower(v:val), arglead)') | |
| endfunction " }}} | |
| function! s:term_open_existing(...) abort " {{{ | |
| if a:0 == 0 | |
| let bnrs = term_list() | |
| if empty(bnrs) | |
| terminal | |
| else | |
| let wids = win_findbuf(bnrs[0]) | |
| if empty(wids) | |
| terminal | |
| else | |
| call win_gotoid(wids[0]) | |
| endif | |
| endif | |
| else | |
| let bnr = bufnr(a:1) | |
| if bnr == -1 | |
| echoerr 'Buffer not found:' a:1 | |
| return | |
| endif | |
| let wids = win_findbuf(bnr) | |
| if empty(wids) | |
| execute term_getsize(bnr)[0] 'new' | |
| execute 'buffer' bnr | |
| else | |
| call win_gotoid(wids[0]) | |
| endif | |
| endif | |
| endfunction " }}} | |
| command! -bar -nargs=? -complete=customlist,s:complete_term_bufname Terminal call s:term_open_existing(<f-args>) | |
| endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment