title: Reusing existing buffer in vim
body: <p>I am trying to learn how to write vim-plugin and thought easiest way to write a compilation function by my own to get something started with vim-plugin and ended up following:</p>
  
  <pre><code>function! PreprocessingCode(commands)
      " Get the bytecode.
      try
          let bytecode = system(a:commands . " -E -o " . bufname("%") . " 2&gt;&amp;1")
      catch
          echo v:exception
      endtry
  
      " Check that buffer already exist
      if bufwinnr('__Bytecode__') &gt; 0
         "Code to replace the buffer.
         setlocal filetype=objectcode
         setlocal buftype=nofile
         call append(0, split(bytecode, '\v\n'))
      else
          " Open a new split and set it up.
          vsplit __Bytecode__
          normal! ggdG
          setlocal filetype=objectcode
          setlocal buftype=nofile
  
          " Insert the bytecode.
          call append(0, split(bytecode, '\v\n'))
       endif
  endfunction
  
  nnoremap &lt;buffer&gt; &lt;localleader&gt;b :call PreprocessingCode("g++")&lt;cr&gt;
  </code></pre>
  
  <p>The main issue is I want to use the <code>__Bytecode__</code> buffer. So that if a buffer is already opened then function should reuse the existing buffer so that if I press b multiple time it should not open multiple stack of windows via vsplit.</p>
  
  <p>Struck here. Don't know how to achieve the desired result? 
  Any thoughts guys? 
  Thanks.</p>