vim identify window
I have a function which opens a new window containing the results of a script
function! MyFunc()
bo new
se buftype=nofile
silent! exec开发者_StackOverflow "r! sh MyScript.sh "
endfunction
I'd like to identify this specific window so that I can call my function multiple times and use the same window each time rather than opening a new window.
something like
if exists(myWindow)
use myWindow
else
bo new
endif
Ok I think this might work... but... tread carefully because I am no Vim expert.
When you create the window the first time you can save it in a global:
bo new
set buftype=nofile
let g:my_run_buffer = bufnr("%")
and subsequently you can check to see if that buffer exists:
if bufexists(g:my_run_buffer)
" Go to buffer
set swb=usetab
exec "sbuf " . g:my_run_buffer
else
... create it ...
endif
Setting "swb=usetab" will mean that when sbuf
switches to the buffer, it will go to whatever window/tab it is currently open in, if it is open. I don't like setting swb globally like that, just for one sbuf call. Anyone know a better way?
精彩评论