1

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

Any help in how to do this? Thanks!

Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
Manuel Araoz
  • 15,962
  • 24
  • 71
  • 95
  • 1
    This question has *nothing* to do with NERDTree. – romainl Dec 16 '14 at 21:27
  • @romainl I think some of the NERDTree confusion comes from the fact that newer vimmers are not comfortable with `:e` or buffers so they use NERDTree to open files in tabs and use a heavy tab workflow. I find the best strategy for NERDTree folk is to suggest they go without the plugin for 1-2 weeks. Usually after that time the person is weened off of the plugin and their workflow improves. Maybe more `:e` and buffer commands lessons need to be in vimtutor. Or maybe it is simply a cargo cult mentality of "must have" plugins. – Peter Rincker Dec 16 '14 at 23:07
  • @PeterRincker I find it very uncomfortable to use `:e` to change files. I keep a tab with NERDTree which I use to navigae the project's structure, and open files from there, using a new tab for each file. Any resource where I can learn a more efficient method? – Manuel Araoz Dec 16 '14 at 23:16
  • @ManuelAráoz I have some links in my answer under "Aside about tabs". I also have a post [Files, Buffers, and Splits Oh My!](http://stackoverflow.com/a/23121220/438329) which talks about NerdTree. I find most people add `:set hidden` to their `vimrc` file and use a fuzzy finder like CtrlP/CommandT/Unite. As for exploring a projects structure I find `:e` with `` to be good enough and netrw (`:e.`) for deeper exploration (protip use `:Rex` to resume exploring). For general help I would recommend watching [Vimcasts](http://vimcasts.org/) in addition to vim's help, `:h`. – Peter Rincker Dec 16 '14 at 23:42

1 Answers1

6

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_=
Community
  • 1
  • 1
Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
  • Thanks. I didn't know about `:tabmove`. Unfortunately, I can't map `` to anything in my console. I'll see if I can unbind that hotkey in the Terminal settings. I'll give you the correct answer anyway because this solves my problem. – Manuel Araoz Dec 17 '14 at 02:07
  • 1
    The `:tabmove +/-1` was introduced in Vim 7.3.591. – Ingo Karkat Dec 17 '14 at 13:53