<?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: Moin Hussain Moti</title>
    <description>The latest articles on DEV Community by Moin Hussain Moti (@moinmoti).</description>
    <link>https://dev.to/moinmoti</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%2F251084%2Fe187dbac-fc8f-4d90-a9af-10d187c8c850.jpg</url>
      <title>DEV Community: Moin Hussain Moti</title>
      <link>https://dev.to/moinmoti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moinmoti"/>
    <language>en</language>
    <item>
      <title>Nim on Neovim</title>
      <dc:creator>Moin Hussain Moti</dc:creator>
      <pubDate>Wed, 12 Feb 2020 16:44:36 +0000</pubDate>
      <link>https://dev.to/moinmoti/nim-on-neovim-24d3</link>
      <guid>https://dev.to/moinmoti/nim-on-neovim-24d3</guid>
      <description>&lt;p&gt;Hello folks… This post is aimed at setting up the Nim programming environment on Linux + Neovim (Vim).&lt;/p&gt;

&lt;p&gt;For those of you unaware of this Python-like easy, C-like fast and me-like awesome programming language (see what I did there 😎), here is the geeky one-liner description of Nim…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Nim is a statically typed compiled systems programming language.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;It's alright if you don't get the description, I just wrote it for the sake of completeness&lt;/em&gt; 🙃&lt;/p&gt;

&lt;p&gt;While I would love to heap praise on Nim and talk about all its features and advantages over traditional counterparts, it makes little sense to reinvent the whole wheel. Hence, for those of you still on crossroads about diving in Nim, I suggest the following article to save yourself from the dilemma.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://towardsdatascience.com/could-nim-replace-python-547145afcfd5" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q-B7yVkJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/56/56/2%2AW_eqMnrJ8bsRz-qJZmRnhA.jpeg" alt="Emmett Boudreau"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://towardsdatascience.com/could-nim-replace-python-547145afcfd5" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Could Nim Replace Python?. Why this fledgeling computer language… | by Emmett Boudreau | Towards Data Science&lt;/h2&gt;
      &lt;h3&gt;Emmett Boudreau ・ &lt;time&gt;Feb 8, 2020&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ze5yh_2q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        towardsdatascience.com
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;BTW, I am assuming you guys know the basics of Neovim because boy-o-boy it's not just an editor, its the Jedi way of life in the cyber world (&lt;em&gt;and while you're at it, &lt;a href="https://www.change.org/p/apple-make-baby-yoda-an-emoji"&gt;petition to get baby-yoda emoji&lt;/a&gt;&lt;/em&gt;) 🤘.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--97remxxe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--NIE-92PW--/c_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880/https://i.imgflip.com/1teh21.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--97remxxe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--NIE-92PW--/c_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880/https://i.imgflip.com/1teh21.jpg" alt="One does not simply learn vim"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Nim
&lt;/h2&gt;

&lt;p&gt;We will use &lt;a href="https://github.com/dom96/choosenim#choosenim"&gt;choosenim&lt;/a&gt; for installing (and later on maintaining) our desired version of Nim. For my mates from javascript brethren, &lt;em&gt;choosenim&lt;/em&gt; is similar to &lt;em&gt;nvm&lt;/em&gt; in its usage. It allows you to easily switch between different versions of Nim (latest, stable, or otherwise).&lt;/p&gt;

&lt;p&gt;Execute the command below in your terminal to install both choosenim and Nim.&lt;br&gt;
&lt;code&gt;curl https://nim-lang.org/choosenim/init.sh -sSf | sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Follow the on-screen instructions to edit the PATH variable in your &lt;em&gt;.bashrc&lt;/em&gt; or &lt;em&gt;.profile&lt;/em&gt; accordingly. Most probably it will be to add the following line of code:&lt;br&gt;
&lt;code&gt;export PATH=$HOME/.nimble/bin/$PATH&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Make sure to source your &lt;em&gt;.bashrc&lt;/em&gt; (&lt;code&gt;source ~/.bashrc&lt;/code&gt;) if you edit it there or re-login to your Linux machine if you edit in &lt;em&gt;.profile&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This will install the following binaries in &lt;code&gt;~/.nimble/bin&lt;/code&gt;: &lt;em&gt;choosenim, nim, nimble, nimgrep, nimpretty, nimsuggest&lt;/em&gt; and &lt;em&gt;testament&lt;/em&gt;.&lt;br&gt;
(&lt;em&gt;Relax!! You will have sufficient idea about most of these binaries by the time you reach the end, and you won't immediately need the ones you don't&lt;/em&gt; 😛)&lt;/p&gt;

&lt;p&gt;To be sure, execute this command to use the stable version of Nim&lt;br&gt;
&lt;code&gt;choosenim stable&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Unless you are in a &lt;a href="https://www.wordnik.com/words/kamikaze"&gt;kamikaze&lt;/a&gt; mood, always use the stable version.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up Neovim for Nim
&lt;/h2&gt;

&lt;p&gt;Alright!!! Now let's start setting it up on Neovim (&lt;em&gt;more like a super-saiyan version of Vim&lt;/em&gt; 😈)&lt;/p&gt;
&lt;h3&gt;
  
  
  Add filetype plugin
&lt;/h3&gt;

&lt;p&gt;Nim is a relatively new language, and therefore no filetype support comes shipped in by-default with Neovim. Filetype support is essential to use various language-specific features in Neovim (like syntax highlighting, linting, code-formatting, etc.). Hence, we will use an external plugin to add Nim filetype support.&lt;/p&gt;

&lt;p&gt;We will use &lt;a href="https://vimawesome.com/plugin/nim-nvim"&gt;nim-nvim&lt;/a&gt; (If you disagree with me, find your own plugin at &lt;a href="https://vimawesome.com"&gt;https://vimawesome.com&lt;/a&gt; 😒). This plugin uses the &lt;em&gt;nimsuggest&lt;/em&gt; binary to provide syntax highlighting for Nim.&lt;/p&gt;

&lt;p&gt;I use &lt;a href="https://github.com/junegunn/vim-plug"&gt;vim-plug&lt;/a&gt; to manage my vim-plugins, and therefore, will provide instructions on how to add this plugin using the same. If you use some other plugin manager, then please refer to the plugin page of &lt;a href="https://vimawesome.com/plugin/nim-nvim"&gt;nim-nvim&lt;/a&gt; (linked above and here again) to see different options.&lt;/p&gt;

&lt;p&gt;Add the following to your list of plugins in init.vim (or .vimrc):&lt;br&gt;
&lt;code&gt;Plug 'alaviss/nim.nvim'&lt;/code&gt;&lt;br&gt;
and then call the following two commands from your Neovim console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:source %
:PlugUpdate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Add linting support
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Linting is the C-3PO of the programming world…&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a gist, linting is a process of checking the code for potential programmatic errors.&lt;/p&gt;

&lt;p&gt;There are various plugins in Neovim that helps in performing linting of the code. I prefer using  &lt;a href="https://github.com/dense-analysis/ale"&gt;ALE&lt;/a&gt; (Asynchronous Lint Engine). Going into the details of ALE is beyond the scope of this article (&lt;em&gt;also, I am quite lazy&lt;/em&gt; 😪), but the following post is pretty good for those interested in knowing more about linting with ALE.&lt;br&gt;
&lt;a href="https://dmerej.info/blog/post/lets-have-a-pint-of-vim-ale"&gt;Let's have a pint of (vim) ale! * Dimitri Merejkowsky&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However (&lt;em&gt;since I am a good guy&lt;/em&gt; 😇), I will provide the tidbits required to get going with ALE for the purpose of Nim.&lt;/p&gt;

&lt;p&gt;Add the following to your list of plugins in &lt;em&gt;init.vim&lt;/em&gt; (or &lt;em&gt;.vimrc&lt;/em&gt;):&lt;br&gt;
&lt;code&gt;Plug 'dense-analysis/ale'&lt;/code&gt;&lt;br&gt;
and then perform the same two calls in Neovim console as in the previous case.&lt;/p&gt;

&lt;p&gt;Among other things, most prominently, ALE acts as a Language Server Protocol (LSP) Client.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;LSP is like the "one ring to rule them all" from The Lord of the Rings, but for the purpose of linting.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Give a 3 min. read to this article to know slightly more about it.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/@wvd.51461/introduction-to-language-server-protocol-lsp-644a61dcd4be" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g5uqpE0p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/56/56/1%2Aof-QkH80huuikhHyZ2pLvw.jpeg" alt="Wathsara Wishwantha Daluwatta"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/@wvd.51461/introduction-to-language-server-protocol-lsp-644a61dcd4be" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Introduction to Language Server Protocol (LSP) | by Wathsara Wishwantha Daluwatta | Medium&lt;/h2&gt;
      &lt;h3&gt;Wathsara Wishwantha Daluwatta ・ &lt;time&gt;Oct 16, 2019&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ze5yh_2q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;Now then, we have an LSP client in ALE, but we still require a Nim LSP server. We will quickly install the &lt;em&gt;nimlsp&lt;/em&gt; package for that. &lt;em&gt;nimlsp&lt;/em&gt; handles the server-side processing (&lt;em&gt;don't ask me how, this post is already too long!! 😓, have some faith and follow the steps and, things will work just fine…&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;To install &lt;em&gt;nimlsp&lt;/em&gt;, execute the following command in your terminal.&lt;br&gt;
&lt;code&gt;nimble install nimlsp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So &lt;em&gt;nimble&lt;/em&gt; is the package manager for Nim similar to &lt;em&gt;npm&lt;/em&gt; for Node. And we already got the &lt;em&gt;nimble&lt;/em&gt; binary (&lt;em&gt;see above&lt;/em&gt;) with the installation of Nim.&lt;/p&gt;

&lt;p&gt;The last piece of the puzzle is to instruct ALE on how to use &lt;em&gt;nimlsp&lt;/em&gt;. Paste the following ALE configuration code in your &lt;em&gt;init.vim&lt;/em&gt; (or &lt;em&gt;.vimrc&lt;/em&gt;) for the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:ale_linters&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="se"&gt;\&lt;/span&gt;   &lt;span class="s1"&gt;'nim'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'nimlsp'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'nimcheck'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:ale_fixers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="se"&gt;\&lt;/span&gt;   &lt;span class="s1"&gt;'*'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'remove_trailing_lines'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'trim_whitespace'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="se"&gt;\&lt;/span&gt;   &lt;span class="s1"&gt;'nim'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'nimpretty'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:ale_linters_explicit&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:ale_set_loclist&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:ale_set_quickfix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:ale_lint_on_text_changed&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'never'&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:ale_lint_on_insert_leave&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:ale_fix_on_save&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:ale_sign_error&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'✖✖'&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:ale_sign_warning&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'⚠⚠'&lt;/span&gt;
&lt;span class="nb"&gt;highlight&lt;/span&gt; ALEErrorSign guifg&lt;span class="p"&gt;=&lt;/span&gt;Red
&lt;span class="nb"&gt;highlight&lt;/span&gt; ALEWarningSign guifg&lt;span class="p"&gt;=&lt;/span&gt;Yellow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can further tweak the configuration as per your requirement. As you can see I have specified &lt;em&gt;nimlsp&lt;/em&gt; and &lt;em&gt;nimcheck&lt;/em&gt; as linting options and &lt;em&gt;nimpretty&lt;/em&gt; as fixing options. ALE uses &lt;em&gt;nimpretty&lt;/em&gt; (already provided in Nim installation) for code-formatting.&lt;/p&gt;

&lt;p&gt;ALRIGHT!!! You are all set 👍&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;I checked the following piece of Nim code in Neovim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nim"&gt;&lt;code&gt;&lt;span class="n"&gt;echo&lt;/span&gt; &lt;span class="s"&gt;"What's your favorite icecream flavor?"&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;flavor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;readLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;echo&lt;/span&gt; &lt;span class="s"&gt;"Your's "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flavor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;", mine's vanilla!&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can you notice the error in the above code snippet? 🤔 🤔 🤔&lt;/p&gt;

&lt;p&gt;Don't worry, Neovim will do it for you 😉&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o1ebe9oL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pck11y4fbthoo6wzjuqo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o1ebe9oL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pck11y4fbthoo6wzjuqo.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code was missing closing " which Neovim correctly pointed out. Add it and then execute (compile and run) the code using the following Nim command:&lt;br&gt;
&lt;code&gt;nim c -r favorite.nim&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The output will look something like this,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kPyUyF5A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i74ta6o78zhpy98bluw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kPyUyF5A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i74ta6o78zhpy98bluw6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, congratulations on making it to the end and see you until next time 👋&lt;/p&gt;

&lt;p&gt;HAPPY CODING!!!&lt;/p&gt;

</description>
      <category>nim</category>
      <category>vim</category>
      <category>neovim</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
