sponsor Vim development Vim logo go to HTTPS page Vim Book Ad

IndentTab : Use tabs for indent at the beginning, spaces for alignment in the rest of a line

 script karma  Rating 4/4, Downloaded by 503    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
script type
This plugin allows you to use your normal tab settings ('tabstop',
'smarttabstop', 'expandtab') for the beginning of the line (up to the first
non-whitespace character), and have <Tab> expanded to the appropriate number
of spaces (i.e. like :set expandtab) anywhere else. This effectively
distinguishes "indenting" from "alignment"; the characters inserted by <Tab>
depend on the local context.

This plugin overrides the default behavior of the <Tab> and <BS> keys in
insert mode.

- ctab.vim (vimscript #231) by Michael Geddes exists since 2002. It also
  offers global and buffer-local mappings, but uses a slightly different
  approach, does not handle comment[prefixes], instead has some
  filetype-specific stuff. It also remaps <CR>, o and O, and additionally
  offers a :RetabIndent command.
- http://vim.wikia.com/wiki/Converting_tabs_to_spaces

The indent tab can be en-/disabled globally or only for a particular buffer.
    call IndentTab#Set( isTurnOn, isGlobal )
You probably want to define your own mappings / commands for that, or do this
for certain filetypes only.

<Tab>                   Uses normal tab settings at the beginning of the line
                        (before the first non-whitespace character), and
                        inserts spaces otherwise.
<BS>                    Uses normal tab settings to delete tabs at the
                        beginning of the line; elsewhere it also removes
                        "space-expanded" tabs as if 'softtabstop' were
                        The exact circumstances under which the normal tab
                        settings apply are configured by the
                        g:IndentTab_scopes setting.
install details
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
    vim IndentTab*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.005 or

For a permanent configuration, put the following commands into your vimrc:

Determine where the buffer's indent settings are applied. Elsewhere, spaces
are used for alignment. Comma-separated list of the following values:
    indent:         Initial whitespace at the beginning of a line.
    commentprefix:  Initial whitespace after a comment prefix, in case the line
                    begins with the comment prefix, not any indent.
    comment:        Inside comments, as determined by syntax highlighting.
    string:         Inside strings, as determined by syntax highlighting.
    let g:IndentTab_scopes = 'indent,commentprefix,string'

To determine whether the 'indenttab' setting is active in the current buffer,
you can call IndentTab#Info#IndentTab(), which yields a boolean value. This
can be used as a replacement for a hypothetical ":set indenttab?", e.g. in a
custom 'statusline'.

Plugins like SuperTab (vimscript #1643) overload the <Tab> key with
insert-mode completion and fall back to inserting a literal <Tab> character.
This is in conflict with this plugin's maps. To integrate, set
    let g:IndentTab_IsSuperTab = 1
This avoids that IndentTab overrides the <Tab> mapping. Inside SuperTab,
instead of returning a literal <Tab>, you need to use the function
IndentTab#SuperTabIntegration#GetExpr() instead.

Rating scripts is only available on the HTTPS page

script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
IndentTab-1.10.vmb.gz 1.10 2013-05-02 7.0 Ingo Karkat - The scope tests that use syntax highlighting can be wrong when there's no separating whitespace. To properly detect the scope, we need to first insert whitespace, then perform the scope tests that use syntax highlighting.
- FIX: In IndentTab#SuperTabIntegration#GetExpr(), prefer buffer-local setting over global one to correctly implement the precedence.
- Add dependency to ingo-library (vimscript #4433).
IndentTab-1.00.vmb.gz 1.00 2012-09-28 7.0 Ingo Karkat Initial upload
ip used for rating:

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.
SourceForge.net Logo