2015-05-24 59 views
0

我正在嘗試進行一個綁定,<Leader>t,以切換特定分割進出自己的選項卡。這兩個命令是詢問vim在當前選項卡中有多少分割

" Open current split in a new tab 
map <Leader>T <C-w>T 
" Close current buffer (and thus the new tab) 
map <Leader>t <C-w>c 

我該如何合併它們?像

map <Leader>t numberOfSplitsInCurrentTab > 1 ? <C-w>T : <C-w>c 

回答

1

回答我自己的問題,讓別人學習。

function! ToggleSingleSplit() 
    if len(tabpagebuflist()) > 1 
     :tabedit % 
    else 
     :close 
    endif 
endfunction 

map <Leader>t :call ToggleSingleSplit()<CR> 

有可能做到這一點更簡潔的方式,但讀起來很好,很容易編輯人喜歡我是誰Vimscript中少精通。

而對於好奇,這裏是我所使用的資源:

+1

我認爲這是一個很好的方法。另外,如果你有關於vim的另一個問題,你可能有興趣將它發佈在[vi.stackexchange](http://vi.stackexchange.com/)上,它專用於vi和vim主題;) – statox

+0

哈哈謝謝...將有。肯定會有的。 –

相關問題