How to 'tab backwards' (remove a tab or tab spaces) in Vim?
VimVim Problem Overview
Is there a fast way to tab backward without pressing backspace (however many number of spaces for which I've set my tab space)?
Vim Solutions
Solution 1 - Vim
If you're in insert mode:
- Ctrl+d - shift left
- Ctrl+t - shift right
If you're in normal mode:
- Shift+<< - shift current line left
- Shift+>> - shift current line right
If you're in visual mode and have 1 or more lines selected:
<
- shift selection left>
- shift selection right
If you mean just to move backwards a word in normal mode, you can use b
to go backwards a word.
Solution 2 - Vim
set softtabstop=4 expandtab
and you will be able to add up to four spaces when you press tab and remove up to four spaces by pressing <BS>
once.
Solution 3 - Vim
tl;dr: set tabstop=4 softtabstop=-1 shiftwidth=0 expandtab
short form: set ts=4 sts=-1 sw=0 et
Explanation
If you set softtabstop
(or sts
) to -1
it will automatically behave the
same as tabstop
(ts
), which will save you some hassle if you change tabbing a lot. Setting shiftwidth
(sw
) to 0
should effectively make
that the same as tabstop
as well.
In Detail
shiftwidth
sw
> Number of spaces to use for each step of (auto)indent. Used for cindent
, >>, <<, etc.
When zero the tabstop
value will be used.
tabstop
ts
> Number of spaces that a softtabstop
option.
softtabstop
sts
> Number of spaces that a Tab counts for while performing editing
> operations, like inserting a Tab or using BS. It
> feels like Tabs are being inserted, while in fact a mix of spaces
> and tabs
is setting at its
> standard value, while being able to edit like it is set to sts
. When
> sts
is negative, the value of shiftwidth
is used. This will save you
> some hassle if you change tabstops a lot. When expandtab
is not set, the
> number of spaces is minimized by using Tabs.
expandtab
et
> In Insert mode: Use the appropriate number of spaces to insert a autoindent
is on. To insert a real tab when expandtab
is on,
> use Ctrl-V Tab. See also
> :retab
Solution 4 - Vim
in normal mode, <<
will tab the current line back one, in visual mode, <
will make all selected lines tab back once