用vimscript切换标签? [英] switch tab with vimscript?

查看:23
本文介绍了用vimscript切换标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

  1. 检查是否存在名为 __Potion_Bytecode__ 的拆分
  2. 如果存在,切换到带有名称的分割
  3. 如果没有,新建一个名为 __Potion_Bytecode__

这是我现在正在做的代码:

Here is code I am now doing:

function! PotionShowBytecode()
    " Here I need to check if split exists
    "  open a new split and set it up
    vsplit __Potion_Bytecode__
    normal! ggdG
endfunction

推荐答案

lh-vim-lib,我有 lh#buffer#jump() 就是这样做的.它依赖于另一个函数找到缓冲区所在的窗口.

In lh-vim-lib, I have lh#buffer#jump() that does exactly that. It relies on another function to find a window where the buffer could be.

" Function: lh#buffer#find({filename}) {{{3
" If {filename} is opened in a window, jump to this window, otherwise return -1
function! lh#buffer#find(filename)
  let b = bufwinnr(a:filename) " find the window where the buffer is opened
  if b == -1 | return b | endif
  exe b.'wincmd w' " jump to the window found
  return b
endfunction

function! lh#buffer#jump(filename, cmd)
  let b = lh#buffer#find(a:filename)
  if b != -1 | return b | endif
  call lh#window#create_window_with(a:cmd . ' ' . a:filename)
  return winnr()
endfunction

它使用了另一个函数 解决极其烦人的 E36:

Which uses another function to work around the extremely annoying E36:

" Function: lh#window#create_window_with(cmd) {{{3
" Since a few versions, vim throws a lot of E36 errors around:
" everytime we try to split from a windows where its height equals &winheight
" (the minimum height)
function! lh#window#create_window_with(cmd) abort
  try
    exe a:cmd
  catch /E36:/
    " Try again after an increase of the current window height
    resize +1
    exe a:cmd
  endtry
endfunction

如果您想使用制表符,则必须改用制表符* 函数.

If you want to work with tabs, you'll have to use tab* functions instead.

这篇关于用vimscript切换标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆