Loading ...
Sorry, an error occurred while loading the content.

Re: Checking in vim script if the buffer is new

Expand Messages
  • Hari Krishna Dara
    ... Notice that this approach will fail if you open a buffer with a name, but it hasn t yet been written. It is still a new file (by your definition of not
    Message 1 of 5 , Oct 30, 2007
    • 0 Attachment
      On Tue, 30 Oct 2007 at 10:33am, Pavel Shevaev wrote:

      >
      > On 10/30/07, Tony Mechelynck <antoine.mechelynck@...> wrote:
      >
      >> - To check for a [No Name] buffer:
      >>
      >> if bufname('%') == ''
      >>
      >
      > Thank you very much, I used this for the following stuff:
      >
      > function! UpdateIfNotNew()
      > if bufname('%') != ''
      > update
      > endif
      > endfunction

      Notice that this approach will fail if you open a buffer with a name,
      but it hasn't yet been written. It is still a new file (by your
      definition of not associating with a file yet). Not sure if this
      information is readily avaialable, but it is possible to check
      the output of :file for the token "[New]" (language sensitive) or use
      more elaborate approach of turning on a flag with BufNew and clearing it
      up with BufWrite. I would also recommend to make sure 'buftype' is not
      set before calling 'update'.

      --
      HTH,
      Hari

      > " Hitting <Esc> will automatically update the buffer
      > map <silent> <Esc> <Esc>:call UpdateIfNotNew()<CR>
      > imap <silent> <Esc> <Esc>:call UpdateIfNotNew()<CR>
      >
      > I often find myself typing :w each time I hit <Esc> that's why I
      > decided to automate this procedure a little bit ;)
      >
      >

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.