sponsor Vim development Vim logo Vim Book Ad

Tab Manager : Rearranges buffers into tabs

 script karma  Rating 15/10, Downloaded by 2913  Comments, bugs, improvements  Vim wiki

created by
Salman Halim
 
script type
utility
 
description
Sorts and rearranges all open buffers across tabs based on built-in or user-specified criteria.

Configuration: The variable g:TabManager_maxFilesInTab (defaults to 5) is used to determine how many buffers to open in each tab.

General usage:

All of these commands optionally take a number which determines how many buffers to open per tab (new tabs get created as necessary); 0 means to lump all
buffers of any given typeinto one tab.

For the following examples, assume these buffers are open (doesn't matter how many tabs they currently take):

/progs/com/test/Abcd.java
/progs/com/test/ProgramRunner.java
/progs/com/abc/Test.java
/vim/plugin/TabManager.vim

Rearrangetabsbyfirstletter: Quick alphabetization of buffers where all buffers with the same starting letter are put together. Only the file name is
considered, not the path. So, at the end, you get three tabs:

Tab 1: Abcd.java
Tab 2: ProgramRunner.java
Tab 3: TabManager.vim and Test.java

(The tabs are sorted as are the results within each tab.)

Rearrangetabsbyextension: Arranges by extension (.java or .vim, for example):

Tab 1: Abcd.java, ProgramRunner.java and Test.java
Tab 2: TabManager.vim

Rearrangetabsbypath: Arranges by absolute file path (not taking filename into consideration):

Tab 1: /progs/com/abc: Test.java
Tab 2: /progs/com/test: Abcd.java and ProgramRunner.java
Tab 3: /vim/plugin: TabManager.vim

Tiletabs: Quick way to alphabetize the list of buffers (case sensitive) into regularly-sized (by number of buffers) tabs. Doesn't make sense to use this with
0 (all buffers in one tab), unless that's the effect you want.

Rearrangetabs: The workhorse. All other other commands are defined through this. Takes the actual pattern criteria against which to match each buffer.

Version 1.1:

Added two new commands:

Rearrangetabsbytype: If it's a Java file, returns the last word that's not a part of the extension. For example, CopyAction.java returns Action and
CopyForm.java returns Form. This should probably be reworked to allow the setting of the extension upon which to filter or to not look at extensions at all.

Rearrangetabsbyroot: Groups files with similarly named roots together. For example, CopyAction.java, CopyForm.java and CopyResults.jsp will end up together
because they all have "Copy" as the root.

Version 1.2:

New variable: g:TabManager_fileTypeExtension (defaults to "java") to use when determining the Rearrangetabsbytype; can be passed to the command on the
command-line as an override.

Rearrangetabsbytype now takes an extension (other than the default "java" or g:TabManager_fileTypeExtension) to use when sorting the files. If only one
parameter is passed, it may be either a number or the extension. If both are specified, the number must be first.

Version 1.3:

Rearrangetabsbyfirstletter renamed to Rearrangetabsbyfirstletters: If called with no parameters, considers the first character of the file name, as before. If
called with one parameter, the specified number of characters is considered. For example, with no parameters, "Test.java" and "Touring.java" would be placed
together because both start with a T. With 2 as the parameter value, they would be separated ("Te" vs. "To").

If called with 2 parameters, the first parameter is the number of windows to place in one tab, as always (0 meaning to throw them all together).

Version 1.35:

Takes 'ignorecase' into consideration for matching extensions, first letters and complete file paths (but not for matching roots and "types").

Version 1.4:

Added new command:

Movetotab: moves the current file to the specified tab; understands absolute numbers (1 for the first tab, for example) as well as:

- n: next tab
- p: previous tab
- $: last tab

Version 1.45:

Added new command:

Copytotab: copies the current file to the specified tab (just like Movetotab except that the original tab also contains the file).

Version 1.5:

Added the ability to set custom "keys" to be used when rearranging files into tabs. For example, given the following list of files:

/progs/com/test/Abcd.java
/progs/com/test/ProgramRunner.java
/progs/com/abc/Test.java
/vim/plugin/TabManager.vim
/webFiles/root/test.html
/webFiles/root/css/styles.css

The default behaviour, when arranging by path, extension or first letters, is to always place test.html and styles.css in separate tabs. (Unless calling
Tiletabs, which just tiles all windows blindly.) However, if both these files have a manually set key of, say, "web", then any other criteria will be ignored
and these two files will always be placed together because they have the same key. This allows grouping some windows by functionality while continuing to
group others by whatever rearrange command is actually called.

Of course, different sets of windows may have different keys and they will all be grouped together accordingly.

All of the standard Rearrange* commands now take an optional bang (!)--for example, Rearrangetabsbyextension!--that will, for just this rearrangement, IGNORE
any local keys and treat all windows as if there were no keys.

If you have multiple windows where you're editing the same buffer, they will almost always end up together after any rearrangement (unless they are split
across tabs that become full). You can avoid this by setting different window-level local keys for the buffers.

Added four new commands--the set and remove key commands can be combined with windo and tabdo to set or remove the same key for more than one window at a time:

Settabmanagerwindowkey <key>: Sets the window-level local key for the current window to <key>.

Settabmanagerbufferkey <key>: Sets the buffer-level local key for the current buffer to <key>.

Removetabmanagerkey: Removes the currently set key for the current window; will remove BOTH buffer and window level keys. (Doesn't take any arguments.)

Redorearrangetabs: Redoes the last tab rearrangement command (by extension, simple tiling, by first letters, etc.). Useful for incorporating new windows into
the currenty "scheme". If local keys have changed, the layout may end up being different. If new windows have been added, the layout may be different, also,
but that may be what you want. By default, it obeys local keys (even if the last command was called with a bang and did not). Accepts a bang (!) to ignore
local keys.

If you call this before you've run any actual rearrangement commands, you will most likely (deservedly) get an error.

Version 1.55:

Rearrangetabsbypath now also takes a second parameter which determines how many components from the path to consider. For example, given the following set of
files:

/progs/com/test/Abcd.java
/progs/com/test/ProgramRunner.java
/progs/com/abc/Test.java

The default behaviour would be to create two tabs, one with Abcd.java and ProgramRunner.java; and the other with Test.java. However, if called with a
parameter of 2, it will only consider the first two path components (/progs/com) and put all the files in the same tab. A value of 0 (the default) means to
check the entire path, as before. New command format:

Rearrangetabsbypath [number of files per tab] [number of path components to consider]
Or
Rearrangetabsbypath [number of path components to consider]


Version 1.6

Added a new command:

Rearrangetabsbypackage: Works just like Rearrangetabsbypath, except uses the package the files are in. Only useful for files that specify a package in this format:

package some.package.name;

(The semicolon is optional.) Files that don't have a package will fall back to the entire file path (no path component specification; the ENTIRE path will be considered.)

Takes either one or two arguments:

Rearrangetabsbypackage [number of files per tab] [number of path components to consider]
Or
Rearrangetabsbypackage [number of path components to consider]
 
install details
Drop into the plugin directory; creates a few commands, but no mappings.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
TabManager.vba 1.8 2011-05-07 7.0 Salman Halim No change in functionality. Just added a proper help file.
TabManager.vim 1.7 2011-05-05 7.0 Salman Halim No real change; has a dependency upon my GetVar autoload script which I had forgotten to mention before. Sorry if this caused problems.
TabManager.vim 1.6 2011-04-18 7.0 Salman Halim Added a new command: Rearrangetabsbypackage: Works just like Rearrangetabsbypath, except uses the package the files are in. Only useful for files that specify a package (falls back to the entire file path otherwise).
TabManager.vim 1.55 2011-04-16 7.0 Salman Halim Rearrangetabsbypath now also takes a second parameter which determines how many components from the path to consider.
TabManager.vim 1.5 2011-04-13 7.0 Salman Halim Added the ability to set custom "keys" to be used when rearranging files into tabs. For example, given the following list of files:

/progs/com/test/Abcd.java
/progs/com/test/ProgramRunner.java
/progs/com/abc/Test.java
/vim/plugin/TabManager.vim
/webFiles/root/test.html
/webFiles/root/css/styles.css

The default behaviour, when arranging by path, extension or first letters, is to always place test.html and styles.css in separate tabs. (Unless calling
Tiletabs, which just tiles all windows blindly.) However, if both these files have a manually set key of, say, "web", then any other criteria will be ignored
and these two files will always be placed together because they have the same key. This allows grouping some windows by functionality while continuing to
group others by whatever rearrange command is actually called.

Of course, different sets of windows may have different keys and they will all be grouped together accordingly.

All of the standard Rearrange* commands now take an optional bang (!)--for example, Rearrangetabsbyextension!--that will, for just this rearrangement, IGNORE
any local keys and treat all windows as if there were no keys.

If you have multiple windows where you're editing the same buffer, they will almost always end up together after any rearrangement (unless they are split
across tabs that become full). You can avoid this by setting different window-level local keys for the buffers.

Added four new commands--the set and remove key commands can be combined with windo and tabdo to set or remove the same key for more than one window at a time:

Settabmanagerwindowkey <key>: Sets the window-level local key for the current window to <key>.

Settabmanagerbufferkey <key>: Sets the buffer-level local key for the current buffer to <key>.

Removetabmanagerkey: Removes the currently set key for the current window; will remove BOTH buffer and window level keys. (Doesn't take any arguments.)

Redorearrangetabs: Redoes the last tab rearrangement command (by extension, simple tiling, by first letters, etc.). Useful for incorporating new windows into
the currenty "scheme". If local keys have changed, the layout may end up being different. If new windows have been added, the layout may be different, also,
but that may be what you want. By default, it obeys local keys (even if the last command was called with a bang and did not). Accepts a bang (!) to ignore
local keys.

If you call this before you've run any actual rearrangement commands, you will most likely (deservedly) get an error.
TabManager.vim 1.45 2011-04-07 7.0 Salman Halim Added new command:

Copytotab: copies the current file to the specified tab (just like Movetotab except that the original tab also contains the file).
TabManager.vim 1.4 2011-04-07 7.0 Salman Halim Added new command:

Movetotab: moves the current file to the specified tab; understands absolute numbers (1 for the first tab, for example) as well as:

- n: next tab
- p: previous tab
- $: last tab
TabManager.vim 1.37 2011-04-05 7.0 Salman Halim Fixed a problem where newly created tabs always had an empty window at the bottom. (Executes an :e the first time in a new tab instead of an :sp.)
TabManager.vim 1.36 2011-04-05 7.0 Salman Halim Fixed typo; thank you, Christophe.
TabManager.vim 1.35 2011-04-04 7.0 Salman Halim Version 1.35:

Takes 'ignorecase' into consideration for matching extensions, first letters and complete file paths (but not for matching roots and "types").
TabManager.vim 1.3 2011-04-04 7.0 Salman Halim Version 1.3:

Rearrangetabsbyfirstletter renamed to Rearrangetabsbyfirstletters: If called with no parameters, considers the first character of the file name, as before. If
called with one parameter, the specified number of characters is considered. For example, with no parameters, "Test.java" and "Touring.java" would be placed
together because both start with a T. With 2 as the parameter value, they would be separated ("Te" vs. "To").

If called with 2 parameters, the first parameter is the number of windows to place in one tab, as always (0 meaning to throw them all together).
TabManager.vim 1.25 2011-04-04 7.0 Salman Halim Removed debug statements left in by mistake and fixed a conversion error.
TabManager.vim 1.2 2011-04-04 7.0 Salman Halim Version 1.2:

New variable: g:TabManager_fileTypeExtension (defaults to "java") to use when determining the Rearrangetabsbytype; can be passed to the command on the
command-line as an override.

Rearrangetabsbytype now takes an extension (other than the default "java" or g:TabManager_fileTypeExtension) to use when sorting the files.
TabManager.vim 1.1 2011-04-03 7.0 Salman Halim Added two new commands:

Rearrangetabsbytype: If it's a Java file, returns the last word that's not a part of the extension. For example, CopyAction.java returns Action and
CopyForm.java returns Form. This should probably be reworked to allow the setting of the extension upon which to filter or to not look at extensions at all.

Rearrangetabsbyroot: Groups files with similarly named roots together. For example, CopyAction.java, CopyForm.java and CopyResults.jsp will end up together
because they all have "Copy" as the root.
TabManager.vim 1.0 2011-04-03 7.0 Salman Halim Initial upload
ip used for rating: 3.128.198.21

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github