I would like to know if there is a command I can run in vim to tell whether a particular window that has focus is actually a Scratch buffer or an empty buffer (such as when creating a new buffer that I haven't saved to a file yet).
The background for why I want to do this:
I have a special context sensitive function bound to my Tab key in Vim, and I'd like to further improve it by allowing it to skip the scratch buffers but not the unsaved new file buffers. I know that
@% can get me the file that backs the buffer, but this is empty in both cases.
My current code looks like this:
function! NextWindowOrTabOrBuffer() " prefer to cycle thru only the set of windows if more than one window if (winnr('$') == 1 && tabpagenr('$') == 1) " only situation where we cycle to next buffer bnext endif " Rest of logic is just as sound (and simple) as it ever was if (winnr() == winnr('$')) tabnext 1wincmd w "first window else wincmd w "next window endif endfunc function! PrevWindowOrTabOrBuffer() if (winnr('$') == 1 && tabpagenr('$') == 1) " only situation where we cycle to next buffer bprev endif if (winnr() == 1) tabprev let winnr = winnr('$') exec winnr . 'wincmd w' else wincmd W endif endfunc " I actually like the mash tab to cycle windows behavior so let's keep it simple "nnoremap <Tab> :wincmd w<CR> "nnoremap <S-Tab> :wincmd W<CR> " Nevermind, I actually really need this on a small screen... nnoremap <Tab> :call NextWindowOrTabOrBuffer()<CR> nnoremap <S-Tab> :call PrevWindowOrTabOrBuffer()<CR>