thanks Paul, your code is nearly perfect!
after some test this is the one that done all works well -- just use standard gt, gT, or Ngt to do all work with regardless of tab and buffer
function! s:nswitch (n)
if tabpagenr("$") > 1
if a:n > 0
exe "tabnext" a:n
else
exe "tabnext"
endif
else
if a:n > 0
exe "buffer" a:n
else
exe "bn"
endif
endif
endfunction
noremap <silent> gt :<C-U>call <SID>nswitch(v:count)<CR>
for completeness, similarly use ,l to toggle 2 tabs (if there exists multiple tabs) or 2 buffers (if there is one tab)
function! s:switch()
if tabpagenr("$") > 1
exe "tabnext" g:lasttab
else
b #
endif
endfunction
noremap <silent> ,l :call <SID>switch()<enter>
plus, to make the buffer looks even more like a tab, I installed bailey ling's vim-airline plugin:
now there is no diffs between tabs/buffers operations :)
just another (non)related question:
is there a way to display multiple rows of tabs?
tab is visually much better than buffers, and that's quite useful when handing multiple files -- especially the time when you need multiple files displayed in front of you so you can quickly jump back and forth when you look at the names ...
but some google research shows "there is no way to display multiple rows of tabs unless modifying the VIM source code" -- means VIM don't support this, right?
regards
ping
On Fri, Dec 13, 2013 at 4:39 AM, Paul Isambert <zappathustra@free.fr> wrote:
De: "ping song" <songpingemail@gmail.com>:
> I tried these pseudo-codes, but these are just 1 time thing and won'tDo this:
> change over time...couldn't figure out a good way.
>
>
> ;if more than one tab, don't hack
>
> if tabpagenr("$") > 1
> unmap gt
> unmap gT
> ;otherwise , if there is one tab, use gt,gT,Ngt to switch between
> buffers
> else
>
> if v:count == 0
> map gt :bn<cr>
> map gT :bp<cr>
> else
> map gt :<C-U>exec "b" . v:count<cr>
> endif
> endif
function! s:nswitch (n)
if tabpagenr("$") >= a:n
exe "tabnext" a:n
else
exe "buffer" a:n
endif
endfunction
noremap <silent> gt :<C-U>call <SID>nswitch(v:count)<CR>
Now Ngt goes to tab N if it exists, to buffer N otherwise.
Best,
Paul
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment