sponsor Vim development Vim logo Vim Book Ad

flagship.vim : Configurable and extensible tab line and status line

 script karma  Rating 32/14, Downloaded by 1677  Comments, bugs, improvements  Vim wiki

created by
Tim Pope
 
script type
utility
 
description
Flagship provides a Vim status line and tab line that are both easily
customizable by the user and extensible by other plugins.

## Extension

Adding a flag from a plugin is a simple matter of calling `Hoist()` with a
scope and function name from a `User Flags` autocommand.  Here's an example
from [fugitive.vim](https://github.com/tpope/vim-fugitive):

    autocmd User Flags call Hoist("buffer", "fugitive#statusline")

You can also do this in your vimrc, for example if a plugin provides a
statusline flag function but does not natively integrate with Flagship.  If
the function isn't defined (e.g., you temporarily disable or permanently
remove the plugin), it will be skipped.  Here's a couple of mine:

    autocmd User Flags call Hoist("window", "SyntasticStatuslineFlag")
    autocmd User Flags call Hoist("global", "%{&ignorecase; ? '[IC]' : ''}")

## Customization

The extension API is great for adding flags, but what if you want to change
the core content?  For the status line, Vim already provides a perfectly
adequate `'statusline'` option, and Flagship will use it in constructing its
own.  Customizing your status line is exactly the same with and without
Flagship.

The tab line is another story.  The usual technique (see
`:help setting-tabline`) involves creating a function that cycles through each
tab and assembles a giant format string.  Furthermore, while you can use the
same status line "%" items, they're expanded in the context of the active
window only, rendering most of them worthless for any tab but the current.
Rather than embrace this abomination, Flagship hides it, instead exposing
a `g:tablabel` option which can be assigned to customize the format of a
single tab.  Additionally, you can set `g:tabprefix` to define content to be
inserted before the first tab (assuming you disabled the GUI tab line as
instructed above).

The default tab label is nearly impossible to precisely reconstruct, and I
never really found it useful, so I've taken it a different direction.  Here's
how it would look if you set `g:tablabel` yourself, using a few of the many
helpers available:

    let g:tablabel =
          \ "%N%{flagship#tabmodified()} %{flagship#tabcwds('shorten',',')}"

Here's a breakdown of what's included:

* The tab number, so you never have to hesitate on `gt` invocation.
* One `+` per modified window.  Vim's default shows the status of the tab's
  current window only, which can be misleading.
* A compact representation of the working directories of each window.  For
  determining what project a tab is on, I find this far more useful than the
  filename.

Additionally, I've chosen to prefix the tab line with the Vim GUI server name
(see `:help v:servername`) if available, or the current host name if SSHed.
This only takes a few characters, and I find it to be greatly helpful in
reducing confusion when running multiple instances of Vim.  (Assign
`g:tabprefix` if you don't like it.)
 
install details
Extract in ~/.vim (~\vimfiles on Windows).

While not strictly required, I highly recommend the following options:

    set laststatus=2
    set showtabline=2
    set guioptions-=e

The first two force the status line and tab line to always display, and the
third disables the GUI tab line in favor of the plain text version, enabling
global flags and the tab prefix explained below.
 

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
flagship.zip 1.1 2015-08-15 7.0 Tim Pope Fix duplicate flag filtering.
Don't override showtabline if explicitly set.
flagship.zip 1.0 2015-06-14 7.0 Tim Pope Initial upload
ip used for rating: 207.241.235.164

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