Friday, December 13, 2013

Re: vim: toggle between tabs and toggle between buffers

De: "ping song" <songpingemail@gmail.com>:
> I tried these pseudo-codes, but these are just 1 time thing and won't
> 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

Do this:

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.

No comments:

Post a Comment