Note that there are some explanatory texts on larger screens.

plurals
  1. POTab Vs Space preferences in Vim
    text
    copied!<p>Vim is very accommodating when it comes to tab Vs. space preferences. As I understand it, the <code>tabstop</code> setting indicates the width of a tab character. The <code>shiftwidth</code> setting specifies how many columns to increment/decrement when using the <kbd>&lt;&lt;</kbd> and <kbd>>></kbd> commands, whereas the <code>softtabstop</code> setting influences the amount of whitespace to be inserted when you press the <kbd>Tab</kbd> key in insert mode. If <code>expandtab</code> is on, the tab key inserts <code>softtabstop</code> number of space characters. Whereas with <code>expandtab</code> switched off, pressing the <kbd>Tab</kbd> key inserts a the smallest possible number of tab+space characters that matches <code>softtabstop</code>. (Please correct me if I'm wrong.)</p> <p>This final point makes me wonder: is there a practical case where you wouldn't want <code>shiftwidth == tabstop &amp;&amp; tabstop == softtabstop</code>? I can't think of one. As far as I am concerned, it would be most convenient if I could set all 3 of these to the same value, in one single assignment. e.g. calling:</p> <pre><code>:set stab=4 </code></pre> <p>which would be equivalent to running:</p> <pre><code>:set tabstop=4 softtabstop=4 shiftwidth=4 </code></pre> <p>Can anyone suggest how this could be done?</p> <hr> <h2><em>UPDATE</em></h2> <p><strong>Thanks for the replies so far from <em>too much php</em>, <em>hobbs</em> and <em>kaiser.se</em>. Rather than reply to each individually, I'm updating the question here.</strong></p> <h2>Softtabstop with expandtab switched off</h2> <p>I said above that with expandtab switched off, pressing the Tab key inserts a the smallest possible number of tab+space characters that matches <code>softtabstop</code>. I stand by that, but I think I need to explain what I meant. I shall attempt to do so by way of a few examples. To follow along, run <code>:set list</code> so that you can see tab characters.</p> <p><code>tabstop=4 softtabstop=2 shiftwidth=4 noexpandtab</code></p> <p>In insert mode, pressing the tab key inserts 2 space characters. Press the tab key a second time, and instead of inserting two more space characters (for a total of 4 space characters) it replaces the previous 2 spaces with a single tab character. Tabstop is set to 4, so a single tab character has the same width as 4 spaces. </p> <p><code>tabstop=4 softtabstop=6 shiftwidth=4 noexpandtab</code></p> <p>In insert mode, pressing the tab key inserts 1 tab character plus 2 spaces. The tab character has a width of 4, so the total width is 6, and this is achieved using 3 characters. Pressing the tab key a second time inserts two tab characters, and removes the two spaces that were inserted previously. The total width is 12, and this is achieved using 3 characters.</p> <p>In both of these examples, Vim inserts the minimum possible number of tab+space characters that matches softtabstop. </p> <p>If I am working with expandtab switched off, I can't see myself wanting the extra granular control that can be achieved by setting softtabstop to a different value from tabstop. It would still be useful for me to be able to set <code>tabstop</code>, <code>softtabstop</code> and <code>shiftwidth</code> to the same value with a single command.</p> <h2>Does expandtab make softtabstop redundant?</h2> <p><code>tabstop=4 softtabstop=0 shiftwidth=4 expandtab</code></p> <p>In insert mode, pressing the tab key inserts 4 spaces. Pressing the delete key deletes a single space - so you have to backspace 4 times if you hit the tab key by accident.</p> <p><code>tabstop=4 softtabstop=4 shiftwidth=4 expandtab</code></p> <p>In insert mode, pressing the tab key inserts 4 spaces. Pressing the backspace key deletes 4 spaces.</p> <p>If I am working with <code>expandtab</code> switched on, I would prefer the delete key to remove the same amount of whitespace as the tab key inserts. So in this case, too, I feel that it would be useful to be able to assign the same value to <code>tabstop</code>, <code>softtabstop</code> and <code>shiftwidth</code> simultaneously.</p> <h2>A shortcut would still be useful</h2> <p>It's great that Vim provides so much flexibility, but I can't see myself needing it. I just want to be able to choose the width of a tab, and whether it is a 'hard' tab (using a tab character) or a 'soft' tab (made up of spaces). Toggling between hard and soft tabs is easy enough (<code>:set expandtab!</code>), but I wish it was more straightforward to set the width of tab, without having to fiddle with 3 different parameters. </p> <p>So my proposed suggestion for something like <code>:set stab=4</code> still sounds good to me.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload