because i've always found the vi documentation a bear to navigate. i don't know what shiftwidth is even for. here's the help for it:
shiftwidth([{col}]) shiftwidth()
Returns the effective value of 'shiftwidth'. This is the
'shiftwidth' value unless it is zero, in which case it is the
'tabstop' value. This function was introduced with patch
7.3.694 in 2012, everybody should have it by now (however it
did not allow for the optional {col} argument until 8.1.542).
When there is one argument {col} this is used as column number
for which to return the 'shiftwidth' value. This matters for the
'vartabstop' feature. If the 'vartabstop' setting is enabled and
no {col} argument is given, column 1 will be assumed.
Can also be used as a |method|: >
GetColumn()->shiftwidth()
What does that even mean? And I've been using vi since 1988!!
shiftwidth has been in vi for a very long time. It's been in my exrc since I got into BSD in the 1990s, and judging by the earliest commit that's available online[0] it was added even before 1980.
tabstop is how far the cursor moves when you press tab.
shiftwidth is how far text moves when you shift it with >> or <<
Normally you'd set them both to the same value so that indenting blocks of code with >> or << shifts them by the same amount as the tabstop.
There's also another setting 'shiftround' (which I only learnt about today in another comment) which makes shifts done with << and >> round themselves to the nearest multiple of shiftwidth.
never occurred to me to use >>. probably because the three keystroke savings didn't register with me. but that's what I mean, once I learn the basics, the rest are just gravy that don't stick in my memory.
Using < and > for shifts becomes even more powerful when combined with a movement, e.g. indenting 20 lines of code at once: 20>> or indenting an entire {} block (including braces) >a{ or an entire block (not including braces) >i{
> i've always used 0i\t\t\t\t...\esc to shift.
Also consider I instead of 0i (it's not quite identical, but should serve the same purpose).
It saves way more than 'three keystrokes' redenting a block though - you must do that every line - I typically visual select then > (or <), doing the whole lot in one stroke (excluding whatever variable amount to select, v} or similar often).
I only ever end up actually manually shifting code when I'm pasting python code from somewhere and it doesn't come in with the right indentation.
If I'm working in any other language it's == (for a single line), or = after marking a region in visual mode, or magg=G'a to just re-indent the whole file.
I haven't used vim as a daily driver in ~14 years; it's weird how the muscle memory of things like magg=G'a or gqip stay in your fingertips.
shiftwidth([{col}]) shiftwidth() Returns the effective value of 'shiftwidth'. This is the 'shiftwidth' value unless it is zero, in which case it is the 'tabstop' value. This function was introduced with patch 7.3.694 in 2012, everybody should have it by now (however it did not allow for the optional {col} argument until 8.1.542).
What does that even mean? And I've been using vi since 1988!!