Search code examples
vimtabs

Swap two tabs with NERDTree


I'm using NERDTree for a while and I love it. I use CTRL+PgDn/PgUp to switch through tabs, as I do in the browser and many other apps.

The missing feature I'm lacking is being able to switch two tabs' places with CTRL+SHIFT+PgDn/PgUp, as most apps support. To know what I'm talking about, open many tabs in Chrome or Firefox, and press CTRL+SHIFT+PgDn.

How can I do this?


Solution

  • Using :tabmove

    You can move the current buffer with the following:

    nnoremap <c-s-pageup> :tabmove -1<cr>
    nnoremap <c-s-pagedown> :tabmove +1<cr>
    

    Note: This requires version 7.3.591+ of Vim if you don't have a new enough version you can do the following (I have not tested these):

    nnoremap <c-s-pageup> :tabmove <c-r>=tabpagenr()-1<cr><cr>
    nnoremap <c-s-pagedown> :tabmove <c-r>=tabpagenr()+1<cr><cr>
    

    You should also be aware that your mapping choice may not work in all terminals.

    Aside about tabs and buffers

    It also seems like you are doing a heavily tab centric workflow. I know it might sound weird but maybe use less tab panes and more buffers. Here are some nice posts about it:

    For more help see:

    :h :tabmove
    :h tabpagenr()
    :h c_ctrl-r_=