Created
July 31, 2022 04:26
-
-
Save miminashi/d96765ca3bb8193a55cb37b57275b002 to your computer and use it in GitHub Desktop.
vimのウィンドウとタブをまとめて巡回するvimスクリプト(C-n で進む, C-p で戻る)
This file contains 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
function! TabWinNext() abort | |
let l:max_tab_number = tabpagenr('$') | |
let l:current_tab_number = tabpagenr() | |
let l:max_window_number = winnr('$') | |
let l:current_window_number = winnr() | |
if l:current_window_number < l:max_window_number | |
let l:next_window_id = win_getid(l:current_window_number + 1) | |
call win_gotoid(l:next_window_id) | |
elseif l:current_tab_number < l:max_tab_number | |
let l:next_window_id = win_getid(1, l:current_tab_number + 1) | |
call win_gotoid(l:next_window_id) | |
else | |
let l:next_window_id = win_getid(1, 1) | |
call win_gotoid(l:next_window_id) | |
endif | |
endfunction | |
function! TabWinPrev() abort | |
let l:min_tab_number = 1 | |
let l:max_tab_number = tabpagenr('$') | |
let l:current_tab_number = tabpagenr() | |
let l:min_window_number = 1 | |
let l:current_window_number = winnr() | |
if l:current_window_number > l:min_window_number | |
let l:prev_window_id = win_getid(l:current_window_number - 1) | |
call win_gotoid(l:prev_window_id) | |
elseif l:current_tab_number > l:min_tab_number | |
let l:prev_window_id = gettabinfo(l:current_tab_number - 1)[0]['windows'][-1] | |
call win_gotoid(l:prev_window_id) | |
else | |
let l:prev_window_id = gettabinfo(l:max_tab_number)[0]['windows'][-1] | |
call win_gotoid(l:prev_window_id) | |
endif | |
endfunction | |
nnoremap <C-n> :call TabWinNext()<CR> | |
nnoremap <C-p> :call TabWinPrev()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment