paritybit.ca

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 9cf1f5319f0caa38c59f9001627de324316189ce
parent f6ff6398391d0aaec233bc52ffd9f8c45d496da8
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Tue,  2 Jun 2020 23:08:29 -0400

Publish new blog post

Diffstat:
Mpages/blog.md | 1+
Mpages/blog/dnd-xp-system.md | 5+++++
Apages/blog/toggling-between-indentation-styles-in-vim.md | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpages/home.md | 4++--
Mpublic/feeds/sitewide-feed.xml | 34++++++++++++++++++++++++++++++++++
Mpublic/sitemap.xml | 1+
6 files changed, 124 insertions(+), 2 deletions(-)

diff --git a/pages/blog.md b/pages/blog.md @@ -20,6 +20,7 @@ href="https://social.paritybit.ca/@jbauer">Mastodon</a>. ### 2020 <ul> + <li>2020-06-02 <a href="blog/toggling-between-indentation-styles-in-vim">Toggling Between Indentation Styles in Vim</a></li> <li>2020-06-02 <a href="blog/dnd-xp-system">My Custom XP System for DnD</a></li> </ul> #### May diff --git a/pages/blog/dnd-xp-system.md b/pages/blog/dnd-xp-system.md @@ -119,3 +119,8 @@ in combat to catch up to other party members by performing non-combat tasks. Give it a shot and let me know what you think. I'll be tweaking this scheme based on how it works out in campaigns I play and what other people say. + +_This is my thirty-fifth post for the +[#100DaysToOffload](https://social.paritybit.ca/tags/100DaysToOffload) +challenge. You can learn more about this challenge over at +[https://100daystooffload.com](https://100daystooffload.com)._ diff --git a/pages/blog/toggling-between-indentation-styles-in-vim.md b/pages/blog/toggling-between-indentation-styles-in-vim.md @@ -0,0 +1,81 @@ +## Toggling Between Indentation Styles in Vim + +[//]: # "I've encountered both spaces and tabs used for indentation in my programming career so I wrote a custom VimScript function to toggle between indenting with tabs and spaces." + +[//]: # "main.min.css" + +[//]: # + +<div class="byline"> +<b>Written By:</b> Jake Bauer | + <b>Posted:</b> 2020-06-02 | + <b>Last Updated:</b> 2020-06-02 +</div> + +Indentation style, much like which editor is superior, is a topic that is +constantly bickered about on the Internet to no end. Usually programmers are +either on the side of indenting with spaces (and typically with 4 spaces), or +indenting with tabs. Relatively few are in the camp of indenting with both +spaces and tabs, though this is still common in certain programming circles. + +I typically use 4 spaces of indentation because that's what I learned to use +from using Python as my first language. It wasn't until a couple years later +when I encountered Makefile's strict reliance on tab characters and the argument +of spaces versus tabs for indentation. I didn't see any really convincing +arguments to switch from using spaces, my peers were using spaces, and spaces +also helped me to line things up in languages like Scheme so I saw no real +reason to change. + +I have, however, recently encountered quite a few projects which use tabs and +have noticed many system configuration files using tabs instead of spaces for +indentation. When contributing to other projects, it's essential to match the +style of the pre-existing code and when editing those system configuration files +I wanted to be consistent with the existing style so I needed a quick way to +toggle between indentation styles. + +Since I use Vim (Neovim, actually), basically any possible indentation +configuration is supported. It's also easy to set up a keybind to toggle between +indentation styles by writing a function into my `vimrc`. I came up with the +following VimScript to switch between indentation styles: + +```vim +" Toggle between 4 spaces and pure tab indentation styles +func! ToggleIndentStyle() + if &expandtab == 1 + set noexpandtab + set softtabstop& + set shiftwidth& + echom "Switched to: Indent with tabs." + else + set expandtab + set softtabstop=4 + set shiftwidth=4 + echom "Switched to: Indent with 4 spaces." + endif +endfu +noremap <C-_> :call ToggleIndentStyle()<CR> +``` + +Indenting with tabs is the default in Vim, so all I need to do to switch to +indenting with tabs is to unset my settings for `softtabstop` and `shiftwidth` +as well as unset `expandtab` so that Vim won't expand my Tab keypresses into +space characters. To switch back to spaces, I revert to my normal settings. + +I chose the `Ctrl`+`_` keybinding because it was free and the underscore is +reminiscent of a "space" character so it would be easy to remember. + +Honestly, I do not strongly lean one way or the other in the indentation camp. +For some languages, such as Common Lisp, using spaces for indentation also +allows consistent alignment without mixing spaces and tabs. For other languages, +either spaces or tabs are required by the language's style guides like Python or +Go respectively. For most languages, though, it makes no difference. + +I have heard murmurings of tabs being better for accessibility, but I've never +seen this claim backed up with hard evidence (I have seen anecdotal evidence for +both spaces being good for accessibility _and_ tabs). If you have compelling +arguments for one style over another, I'd like to hear them. + +_This is my thirty-sixth post for the +[#100DaysToOffload](https://social.paritybit.ca/tags/100DaysToOffload) +challenge. You can learn more about this challenge over at +[https://100daystooffload.com](https://100daystooffload.com)._ diff --git a/pages/home.md b/pages/home.md @@ -20,6 +20,8 @@ extent)! Access through `gopher://paritybit.ca` or `gemini://paritybit.ca`. src="/img/feed-icon.png" width="15" height="15" alt="Click for RSS Feed"/> </a> </div> +2020-06-02 <a class="feed-item" href="blog/toggling-between-indentation-styles-in-vim">Toggling Between Indentation Styles in Vim</a> + 2020-06-02 <a class="feed-item" href="blog/dnd-xp-system">My Custom XP System for DnD</a> 2020-05-31 <a class="feed-item" href="blog/it-doesnt-have-to-be-perfect">It Doesn't Have to Be Perfect</a> @@ -37,8 +39,6 @@ extent)! Access through `gopher://paritybit.ca` or `gemini://paritybit.ca`. 2020-05-25 <a class="feed-item" href="blog/paying-for-software">Paying for Software</a> 2020-05-23 <a class="feed-item" href="blog/two-of-the-most-valuable-lessons-ive-learned">Two of the Most Valuable Lessons I've Learned</a> - - ### What is a Parity Bit? It is a bit (in the 1's and 0's sense) used in checking for errors in digital diff --git a/public/feeds/sitewide-feed.xml b/public/feeds/sitewide-feed.xml @@ -7,6 +7,40 @@ <description>The feed that covers all notable additions, updates, announcements, and other changes for the entire paritybit.ca website.</description> <item> + <title>Toggling Between Indentation Styles in Vim</title> + <link>https://www.paritybit.ca/blog/toggling-between-indentation-styles-in-vim</link> + <guid>https://www.paritybit.ca/blog/toggling-between-indentation-styles-in-vim</guid> + <pubDate>Tue, 02 Jun 2020 23:08:03 -0400</pubDate> +<description><![CDATA[<h2 id="toggling-between-indentation-styles-in-vim">Toggling Between Indentation Styles in Vim</h2> +<div class="byline"> +<p><b>Written By:</b> Jake Bauer | <b>Posted:</b> 2020-06-02 | <b>Last Updated:</b> 2020-06-02</p> +</div> +<p>Indentation style, much like which editor is superior, is a topic that is constantly bickered about on the Internet to no end. Usually programmers are either on the side of indenting with spaces (and typically with 4 spaces), or indenting with tabs. Relatively few are in the camp of indenting with both spaces and tabs, though this is still common in certain programming circles.</p> +<p>I typically use 4 spaces of indentation because that’s what I learned to use from using Python as my first language. It wasn’t until a couple years later when I encountered Makefile’s strict reliance on tab characters and the argument of spaces versus tabs for indentation. I didn’t see any really convincing arguments to switch from using spaces, my peers were using spaces, and spaces also helped me to line things up in languages like Scheme so I saw no real reason to change.</p> +<p>I have, however, recently encountered quite a few projects which use tabs and have noticed many system configuration files using tabs instead of spaces for indentation. When contributing to other projects, it’s essential to match the style of the pre-existing code and when editing those system configuration files I wanted to be consistent with the existing style so I needed a quick way to toggle between indentation styles.</p> +<p>Since I use Vim (Neovim, actually), basically any possible indentation configuration is supported. It’s also easy to set up a keybind to toggle between indentation styles by writing a function into my <code>vimrc</code>. I came up with the following VimScript to switch between indentation styles:</p> +<pre class="vim"><code>&quot; Toggle between 4 spaces and pure tab indentation styles +func! ToggleIndentStyle() + if &amp;expandtab == 1 + set noexpandtab + set softtabstop&amp; + set shiftwidth&amp; + echom &quot;Switched to: Indent with tabs.&quot; + else + set expandtab + set softtabstop=4 + set shiftwidth=4 + echom &quot;Switched to: Indent with 4 spaces.&quot; + endif +endfu +noremap &lt;C-_&gt; :call ToggleIndentStyle()&lt;CR&gt;</code></pre> +<p>Indenting with tabs is the default in Vim, so all I need to do to switch to indenting with tabs is to unset my settings for <code>softtabstop</code> and <code>shiftwidth</code> as well as unset <code>expandtab</code> so that Vim won’t expand my Tab keypresses into space characters. To switch back to spaces, I revert to my normal settings.</p> +<p>I chose the <code>Ctrl</code>+<code>_</code> keybinding because it was free and the underscore is reminiscent of a “space” character so it would be easy to remember.</p> +<p>Honestly, I do not strongly lean one way or the other in the indentation camp. For some languages, such as Common Lisp, using spaces for indentation also allows consistent alignment without mixing spaces and tabs. For other languages, either spaces or tabs are required by the language’s style guides like Python or Go respectively. For most languages, though, it makes no difference.</p> +<p>I have heard murmurings of tabs being better for accessibility, but I’ve never seen this claim backed up with hard evidence (I have seen anecdotal evidence for both spaces being good for accessibility <em>and</em> tabs). If you have compelling arguments for one style over another, I’d like to hear them.</p> +<p><em>This is my thirty-sixth post for the <a href="https://social.paritybit.ca/tags/100DaysToOffload">#100DaysToOffload</a> challenge. You can learn more about this challenge over at <a href="https://100daystooffload.com" class="uri">https://100daystooffload.com</a>.</em></p>]]></description> +</item> +<item> <title>My Custom XP System for DnD</title> <link>https://www.paritybit.ca/blog/dnd-xp-system</link> <guid>https://www.paritybit.ca/blog/dnd-xp-system</guid> diff --git a/public/sitemap.xml b/public/sitemap.xml @@ -3,6 +3,7 @@ <url><loc>https://www.paritybit.ca</loc></url> <url><loc>https://www.paritybit.ca/home</loc></url> <url><loc>https://www.paritybit.ca/blog</loc></url> + <url><loc>https://www.paritybit.ca/blog/toggling-between-indentation-styles-in-vim</loc></url> <url><loc>https://www.paritybit.ca/blog/dnd-xp-system</loc></url> <url><loc>https://www.paritybit.ca/blog/it-doesnt-have-to-be-perfect</loc></url> <url><loc>https://www.paritybit.ca/blog/book-review-the-mediocre-programmer</loc></url>