Tests for tab pages STARTTEST :so small.vim :lang C :" Simple test for opening and closing a tab page :tabnew :let nr = tabpagenr() :q :call append(line('$'), 'tab page ' . nr) :unlet nr :" :" Open three tab pages and use ":tabdo" :0tabnew :1tabnew :888tabnew :tabdo call append(line('$'), 'this is tab page ' . tabpagenr()) :tabclose! 2 :tabrewind :let line1 = getline('$') :undo :q :tablast :let line2 = getline('$') :q! :call append(line('$'), line1) :call append(line('$'), line2) :unlet line1 line2 :" :" Test for settabvar() and gettabvar() functions. Open a new tab page and :" set 3 variables to a number, string and a list. Verify that the variables :" are correctly set. :tabnew :tabfirst :call settabvar(2, 'val_num', 100) :call settabvar(2, 'val_str', 'SetTabVar test') :call settabvar(2, 'val_list', ['red', 'blue', 'green']) :" :let test_status = 'gettabvar: fail' :if gettabvar(2, 'val_num') == 100 && gettabvar(2, 'val_str') == 'SetTabVar test' && gettabvar(2, 'val_list') == ['red', 'blue', 'green'] : let test_status = 'gettabvar: pass' :endif :call append(line('$'), test_status) :" :tabnext 2 :let test_status = 'settabvar: fail' :if t:val_num == 100 && t:val_str == 'SetTabVar test' && t:val_list == ['red', 'blue', 'green'] : let test_status = 'settabvar: pass' :endif :tabclose :call append(line('$'), test_status) :" :if has('gui') || has('clientserver') :" Test for ":tab drop exist-file" to keep current window. :sp test1 :tab drop test1 :let test_status = 'tab drop 1: fail' :if tabpagenr('$') == 1 && winnr('$') == 2 && winnr() == 1 : let test_status = 'tab drop 1: pass' :endif :close :call append(line('$'), test_status) :" :" :" Test for ":tab drop new-file" to keep current window of tabpage 1. :split :tab drop newfile :let test_status = 'tab drop 2: fail' :if tabpagenr('$') == 2 && tabpagewinnr(1, '$') == 2 && tabpagewinnr(1) == 1 : let test_status = 'tab drop 2: pass' :endif :tabclose :q :call append(line('$'), test_status) :" :" :" Test for ":tab drop multi-opend-file" to keep current tabpage and window. :new test1 :tabnew :new test1 :tab drop test1 :let test_status = 'tab drop 3: fail' :if tabpagenr() == 2 && tabpagewinnr(2, '$') == 2 && tabpagewinnr(2) == 1 : let test_status = 'tab drop 3: pass' :endif :tabclose :q :call append(line('$'), test_status) :else :" :drop not supported :call append(line('$'), 'tab drop 1: pass') :call append(line('$'), 'tab drop 2: pass') :call append(line('$'), 'tab drop 3: pass') :endif :" :" :for i in range(9) | tabnew | endfor 1gt Go=tabpagenr()  :tabmove 5 i=tabpagenr()  :tabmove -2 i=tabpagenr()  :tabmove +4 i=tabpagenr()  :tabmove i=tabpagenr()  :tabmove -20 i=tabpagenr()  :tabmove +20 i=tabpagenr()  :3tabmove i=tabpagenr()  :7tabmove 5 i=tabpagenr()  :let a='No error caught.' :try :tabmove foo :catch E474 :let a='E474 caught.' :endtry i=a  :" :" Test autocommands :tabonly! :let g:r=[] :command -nargs=1 -bar C :call add(g:r, '=== ' . . ' ===')| :function Test() let hasau=has('autocmd') if hasau autocmd TabEnter * :call add(g:r, 'TabEnter') autocmd WinEnter * :call add(g:r, 'WinEnter') autocmd BufEnter * :call add(g:r, 'BufEnter') autocmd TabLeave * :call add(g:r, 'TabLeave') autocmd WinLeave * :call add(g:r, 'WinLeave') autocmd BufLeave * :call add(g:r, 'BufLeave') endif let t:a='a' C tab split if !hasau let g:r+=['WinLeave', 'TabLeave', 'WinEnter', 'TabEnter'] endif let t:a='b' C tabnew if !hasau let g:r+=['WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufLeave', 'BufEnter'] endif let t:a='c' call add(g:r, join(map(range(1, tabpagenr('$')), 'gettabvar(v:val, "a")'))) C call map(range(1, tabpagenr('$')), 'settabvar(v:val, ''a'', v:val*2)') call add(g:r, join(map(range(1, tabpagenr('$')), 'gettabvar(v:val, "a")'))) let w:a='a' C vsplit if !hasau let g:r+=['WinLeave', 'WinEnter'] endif let w:a='a' let tabn=tabpagenr() let winr=range(1, winnr('$')) C tabnext 1 if !hasau let g:r+=['BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'] endif call add(g:r, join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")'))) C call map(copy(winr), 'settabwinvar('.tabn.', v:val, ''a'', v:val*2)') call add(g:r, join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")'))) if hasau augroup TabDestructive autocmd TabEnter * :C tabnext 2 | C tabclose 3 augroup END C tabnext 3 let g:r+=[tabpagenr().'/'.tabpagenr('$')] autocmd! TabDestructive TabEnter C tabnew C tabnext 1 autocmd TabDestructive TabEnter * nested :C tabnext 2 | C tabclose 3 C tabnext 3 let g:r+=[tabpagenr().'/'.tabpagenr('$')] else let g:r+=["=== tabnext 3 ===","BufLeave","WinLeave","TabLeave","WinEnter","TabEnter","=== tabnext 2 ===","=== tabclose 3 ===","2/2","=== tabnew ===","WinLeave","TabLeave","WinEnter","TabEnter","BufLeave","BufEnter","=== tabnext 1 ===","BufLeave","WinLeave","TabLeave","WinEnter","TabEnter","BufEnter","=== tabnext 3 ===","BufLeave","WinLeave","TabLeave","WinEnter","TabEnter","=== tabnext 2 ===","BufLeave","WinLeave","TabLeave","WinEnter","TabEnter","=== tabnext 2 ===","=== tabclose 3 ===","BufEnter","=== tabclose 3 ===","2/2",] endif endfunction :call Test() :$ put =g:r :" :" :/^Results/,$w! test.out :qa! ENDTEST Results: