Created
December 15, 2022 02:34
-
-
Save etorth/838ec3bedb6c8945e8883f24a9fbce35 to your computer and use it in GitHub Desktop.
vim script: get tabs
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! s:GetTabs() | |
" vim tab does not have name | |
" there is not a good way to detect if a diary is already open | |
redir => l:tabs_out | |
silent tabs | |
redir END | |
let l:tabs_out = split(l:tabs_out, '\n') | |
let l:tabs_len = len(l:tabs_out) | |
let l:tabs_map = {} | |
let l:i = 0 | |
let l:j = 0 | |
let l:tab_regex = '^Tab page \d\+$' | |
while l:i < l:tabs_len | |
if trim(l:tabs_out[l:i]) =~ l:tab_regex | |
let l:j = l:i + 1 | |
let l:tab_idx = str2nr(matchstr(l:tabs_out[l:i], '\d\+')) | |
while l:j < l:tabs_len && trim(l:tabs_out[l:j]) !~ l:tab_regex | |
if !has_key(l:tabs_map, l:tab_idx) | |
let l:tabs_map[l:tab_idx] = [] | |
endif | |
let l:tabs_map[l:tab_idx] += [trim(l:tabs_out[l:j][3:])] | |
let l:j += 1 | |
endwhile | |
endif | |
let l:i = l:j | |
endwhile | |
return l:tabs_map | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment