vim 识别窗口

发布于 2024-11-28 13:39:27 字数 313 浏览 4 评论 0原文

我有一个函数,它打开一个包含脚本结果的新窗口,

function! MyFunc()
    bo new
    se buftype=nofile
    silent! exec "r! sh MyScript.sh "
endfunction

我想识别这个特定窗口,以便我可以多次调用我的函数并每次使用相同的窗口,而不是打开一个新窗口。

类似的东西

if exists(myWindow) 
    use myWindow
else
    bo new
endif

I have a function which opens a new window containing the results of a script

function! MyFunc()
    bo new
    se buftype=nofile
    silent! exec "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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔书几行 2024-12-05 13:39:27

好吧,我认为这可能有用...但是...请小心行事,因为我不是 Vim 专家。

当您第一次创建窗口时,您可以将其保存在全局中:

bo new
set buftype=nofile
let g:my_run_buffer = bufnr("%")

随后您可以检查该缓冲区是否存在:

if bufexists(g:my_run_buffer)
    " Go to buffer
    set swb=usetab
    exec "sbuf " . g:my_run_buffer
else
    ... create it ...
endif

设置“swb=usetab”将意味着当sbuf切换到缓冲区时,它将转到当前打开的任何窗口/选项卡(如果已打开)。我不喜欢像这样全局设置 swb,只是为了一个 sbuf 调用。有人知道更好的方法吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文