When I open a buffer (via :tabnew or any other way), if there
is no filename associated with the buffer, I’d like to insert
some default text (recently opened files).
au BufAdd * call My_dir(expand("<afile>"))
function! My_dir(fname)
python << EOF
import vim
blah = vim.eval('a:fname')
if str(blah) == 'None':
cb = vim.current.buffer
cb.append("yuck")
EOF
endfunction
The trouble is that, fname will be ‘None’ but current.buffer is
the previous buffer I was in! How do I get the buffer I just
opened so I can stick stuff in it??
The problem you’re having is that the
BufAddevent is fired before the window is created, and apparently before Vim’s current buffer is set to the newly created one.All you need to do is use the
BufWinEnterevent instead:I tried your function with this small change and it worked.