Last active
February 10, 2018 10:45
-
-
Save koturn/a6047753c327f489a752212099454896 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
if exists('*win_gotoid') | |
function! s:buf_open_existing(bname) abort " {{{ | |
let bnr = bufnr(a:bname) | |
if bnr == -1 | |
echoerr 'Buffer not found:' a:bname | |
return | |
endif | |
let wids = win_findbuf(bnr) | |
if empty(wids) | |
new | |
execute 'buffer' bnr | |
else | |
call win_gotoid(wids[0]) | |
endif | |
endfunction " }}} | |
else | |
function! s:buf_open_existing(bname) abort " {{{ | |
let bnr = bufnr(a:bname) | |
if bnr == -1 | |
echoerr 'Buffer not found:' a:bname | |
return | |
endif | |
let tindice = map(filter(map(range(1, tabpagenr('$')), '{"tindex": v:val, "blist": tabpagebuflist(v:val)}'), 'index(v:val.blist, bnr) != -1'), 'v:val.tindex') | |
if empty(tindice) | |
new | |
execute 'buffer' bnr | |
else | |
execute 'tabnext' tindice[0] | |
execute bufwinnr(bnr) 'wincmd w' | |
endif | |
endfunction " }}} | |
endif | |
command! -bar -nargs=1 -complete=buffer Buffer call s:buf_open_existing(<f-args>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment