superfluous initial empty buffer with 'viminfo'

38 views
Skip to first unread message

Lucas Hoffmann

unread,
Jun 23, 2012, 10:46:10 AM6/23/12
to v...@vim.org
Hello all,

I use "set viminfo='100,<50,s10,h,%" to keep my bufferlist. But when I restart Vim I still get an additional [No Name] buffer. I don't want this but found no way to tell Vim to not create it.

Question 1:
Is there any way to tell Vim not to create this initial empty [No Name] buffer if other buffers are loaded from the .viminfo file?

I also tried to remove the buffer with a function and autocommand (code below) which deletes the buffer just fine but introduces a new problem: The options 'ft' and 'syn' are not set for the next buffer (buffer 2) which is displayed after wiping the [No Name] buffer. That has the effect that this buffer appears w/o syntax highlighting until I :edit it. All other buffers behave correctly only buffer 2 has the options messed up.

function! LucCheckIfBufferIsNew(...)
" check if the buffer with number a:1 is new. That is to say, if it as
" no name and is empty. If a:1 is not supplied 1 is used.
" find the buffer nr to check
let number = a:0 ? a:1 : 1
" save current and alternative buffer
let current = bufnr('%')
let alternative = bufnr('#')
let value = 0
" check buffer name
if bufexists(number) && bufname(number) == ''
silent! execute 'buffer' number
let value = line('$') == 1 && getline(1) == '' ? 1 : 0
silent! execute 'buffer' alternative
silent! execute 'buffer' current
endif
return value
endfunction
autocmd VimEnter * if LucCheckIfBufferIsNew(1) | bwipeout 1 | endif

(the function is slightly more general than needed for this use case)

Question 2:
How can I delete the buffer and not mess up the options of the next displayed buffer?

Technical Info:
The [No Name] buffer in question appears in Vim 7.2 patchs 1-108 (Mac OS X Snowleopard built in vim), Vim 7.3 patchs 1-308 (Mac OS X Snowleopard MacVim version) in Vim 7.2 patches 1-445 (Debian) and Vim 7.3 patches 1-429 (Debian). It does not matter weather I use "--noplugins" or even "-u ./test" on the command line (where ./test just contains the line "set viminfo='100,<50,s10,h,%").

Thanks for your help
Lucas

Lucas Hoffmann

unread,
Jun 26, 2012, 8:11:47 AM6/26/12
to vim...@googlegroups.com
I have now found a solution myself and thought I'd let you know:
The function is unchanged but I simply reapply the appropriate autocommands
to the next buffer. That means I chanched above autocmd to read

autocmd VimEnter * if LucCheckIfBufferIsNew(1) | bwipeout 1 |
\ doautocmd BufRead,BufNewFile | endif

For my usecase I can say this is solved but if anyone of you knows a
nicer solution I'll still be happy to hear about it.

Lucas
Reply all
Reply to author
Forward
0 new messages