<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Taisei</title>
    <description>The latest articles on DEV Community by Taisei (@taisei_ide).</description>
    <link>https://dev.to/taisei_ide</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F707449%2Fbf7fb3af-6933-47ff-8cc2-47e2c32af03d.jpg</url>
      <title>DEV Community: Taisei</title>
      <link>https://dev.to/taisei_ide</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/taisei_ide"/>
    <language>en</language>
    <item>
      <title>Code Formatting in Nim [nim pretty］</title>
      <dc:creator>Taisei</dc:creator>
      <pubDate>Wed, 16 Nov 2022 16:33:36 +0000</pubDate>
      <link>https://dev.to/taisei_ide/code-formatting-in-nim-4g7f</link>
      <guid>https://dev.to/taisei_ide/code-formatting-in-nim-4g7f</guid>
      <description>&lt;p&gt;This is my first post on dev. By the way, do you guys know Nim? It's an elegant language, compiles to C, and has a Python-like syntax. So it's very fast and easy to write. I've been using it for work recently. I was looking for a code formatting tool for it and finally found one called Nim pretty.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use Nim pretty
&lt;/h2&gt;

&lt;p&gt;You can use it easily. Here's a sample code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const     hello   =      "Hello"
echo   "Say, ",                      hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's terrible syntax, right? Here's a way to format it. &lt;br&gt;
You can run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nimpretty --indent:2 sample.nim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The sample code can be formatted as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const hello = "Hello"
echo "Say, ", hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The terrible code was formatted with an indent as 2.&lt;br&gt;
It became quite readable but you don't want to run the command for each file, right?&lt;/p&gt;

&lt;p&gt;Here's a better way. You can run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find . -name "*.nim" -exec nimpretty --indent:2 {} +
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All Nim files in a directory can be formatted. It's a combination of a Nim pretty command and shell script.&lt;/p&gt;

&lt;p&gt;You can create a task in a &lt;code&gt;nimble file&lt;/code&gt; as below if you don't want to type or copy the command every time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version       = "0.0.1"
author        = "Sample"
description   = "Sample code"
license       = "Sample"

task pretty, "Formats all nim files":
  exec "find . -name '*.nim' -exec nimpretty --indent:2 {} +"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you can run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nimble pretty
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then all Nim files can be formatted even if they are in different directories.&lt;/p&gt;

&lt;p&gt;That's all. Any tips about Nim would be appreciated.&lt;br&gt;
Thank you!!&lt;/p&gt;

</description>
      <category>beginners</category>
    </item>
  </channel>
</rss>
