Re: superfluous initial empty buffer with 'viminfo'
- On 23. Jun 2012, at 16:46, Lucas Hoffmann wrote:
> I use "set viminfo='100,<50,s10,h,%" to keep my bufferlist. But when II have now found a solution myself and thought I'd let you know:
> 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
> return value
> 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?
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.
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php