{"id":399,"date":"2025-09-05T22:43:55","date_gmt":"2025-09-05T20:43:55","guid":{"rendered":"https:\/\/gieorgijewski.pl\/blog\/?p=399"},"modified":"2025-09-06T00:51:45","modified_gmt":"2025-09-05T22:51:45","slug":"vim-tabs-vs-spaces","status":"publish","type":"post","link":"https:\/\/gieorgijewski.pl\/blog\/en\/vim-tabs-vs-spaces\/","title":{"rendered":"Vim: tabs vs. spaces"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"393\" src=\"https:\/\/gieorgijewski.pl\/blog\/wp-content\/uploads\/2025\/09\/574ba840dd08955c2e8b4575.webp\" alt=\"Sillicon Valley\" class=\"wp-image-400\" srcset=\"https:\/\/gieorgijewski.pl\/blog\/wp-content\/uploads\/2025\/09\/574ba840dd08955c2e8b4575.webp 700w, https:\/\/gieorgijewski.pl\/blog\/wp-content\/uploads\/2025\/09\/574ba840dd08955c2e8b4575-300x168.webp 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/figure>\n\n\n\n<p>The problem seemed not so important to me until I started analysing how I should set up my <strong>vim<\/strong> to work with files from really large open source project.<\/p>\n\n\n\n<p>When I cooperate in professional projects with others, I have seperate coding environments, lastly with &#8222;expanding&#8221; to four  spaces.<\/p>\n\n\n\n<p>When I work alone, I use two spaces width for indentation, pressing tab is expanded automatically to spaces.<\/p>\n\n\n\n<p>Coincidentally my first OS project I contributed to had the same setting as my own. I&#8217;m referring to  <a href=\"https:\/\/exercism.org\">exercism.org<\/a><\/p>\n\n\n\n<p>How to configure it in Vim?<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bat\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> set tabstop =2\n set softtabstop =2\n set shiftwidth =2\n set expandtab\n set autoindent<\/pre>\n\n\n\n<p>Above are my typical lines in the <code>~\/.vimrc<\/code> file.<br><code><a href=\"https:\/\/vimdoc.sourceforge.net\/htmldoc\/options.html#'tabstop'\">tabstop<\/a><\/code> option denotes how many spaces single tab character represents in the text.<br>It seems easy to interpret but don&#8217;t be misled. I also had gotten such impression by quickly skimming the documentation. If you wish, click the link under the option&#8217;s name now and read its description <strong>thoroughly<\/strong>.<br><code><a href=\"https:\/\/vimdoc.sourceforge.net\/htmldoc\/options.html#'softtabstop'\">softtabstop<\/a><\/code> option is set to 0 by default and then only <strong>tabstop<\/strong> counts.<br>However, not knowing precisely how it worked, I set it as tabstop because it worked for indentation and that&#8217;s all I wanted.<br>Third option working together with the previous ones and important for indentation is <code><a href=\"https:\/\/vimdoc.sourceforge.net\/htmldoc\/options.html#'expandtab'\">expandtab<\/a><\/code>.<br>It&#8217;s of on\/off type, unset by <code>set noexpandtab<\/code>. When on, it causes every tab press to insert spaces instead. How many spaces? As many as <code>tabstop<\/code> value, unless <code>softtabstop<\/code> is not zero than as many as <code>softtabstop<\/code>.<\/p>\n\n\n\n<p>Exactly. These options cooperate for common result and I didn&#8217;t even mention <code>shiftwidth<\/code> and <code>*indent<\/code> options yet!<\/p>\n\n\n\n<p>Summarizing this part. Configuration above is defensive and stems from the need of indent of two spaces per level. It also complicates the cooperation with other developers who use different settings, particularly with tabs involved.<\/p>\n\n\n\n<p>In the next post I&#8217;ll try experiment with such configurations and I would gladly read comments on that, as I&#8217;m curious how others choose their settings.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Where I uncover my shallow understanding of Vim configuration and I encourage reader for joint adventure in intricacies of tabulation and indentation.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56],"tags":[],"class_list":["post-399","post","type-post","status-publish","format-standard","hentry","category-tools"],"_links":{"self":[{"href":"https:\/\/gieorgijewski.pl\/blog\/wp-json\/wp\/v2\/posts\/399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gieorgijewski.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gieorgijewski.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gieorgijewski.pl\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gieorgijewski.pl\/blog\/wp-json\/wp\/v2\/comments?post=399"}],"version-history":[{"count":14,"href":"https:\/\/gieorgijewski.pl\/blog\/wp-json\/wp\/v2\/posts\/399\/revisions"}],"predecessor-version":[{"id":427,"href":"https:\/\/gieorgijewski.pl\/blog\/wp-json\/wp\/v2\/posts\/399\/revisions\/427"}],"wp:attachment":[{"href":"https:\/\/gieorgijewski.pl\/blog\/wp-json\/wp\/v2\/media?parent=399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gieorgijewski.pl\/blog\/wp-json\/wp\/v2\/categories?post=399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gieorgijewski.pl\/blog\/wp-json\/wp\/v2\/tags?post=399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}