<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Configuration on Clément Joly – Open-Source, Rust &amp; SQLite</title><link>https://cj.rs/tags/configuration/</link><description>Recent content in Configuration on Clément Joly – Open-Source, Rust &amp; SQLite</description><image><title>Clément Joly – Open-Source, Rust &amp; SQLite</title><url>https://cj.rs/images/open-graph-pages.jpg</url><link>https://cj.rs/images/open-graph-pages.jpg</link></image><generator>Hugo</generator><language>en</language><copyright>Clément Joly</copyright><atom:link href="https://cj.rs/tags/configuration/index.xml" rel="self" type="application/rss+xml"/><item><title>Generating Snippets with LuaSnip in Neovim</title><link>https://cj.rs/blog/generating-snippets-with-luasnip/</link><pubDate>Sun, 31 Jul 2022 22:10:49 +0100</pubDate><guid>https://cj.rs/blog/generating-snippets-with-luasnip/</guid><description>Generating repetitive snippets with code, like time variant of section titles.</description><content:encoded><![CDATA[



  
  
  
  

  <div class="alert alert-tldr">
    <p class="alert-heading">
      ⚡
      
        TL;DR
      
    </p>
    <p>When you have many variations of the same snippet, one option is to generate those with Lua code. The complete example is <a href="#the-final-code">at the end</a>.</p>
  </div>



<p>I’ve <a href="https://cj.rs/blog/ultisnips-to-luasnip/">recently moved</a> to <a href="https://github.com/L3MON4D3/LuaSnip">LuaSnip</a> as my snippets plugin for Neovim.
When I first started, I sticked to the simplest features of LuaSnip, in particular the SnipMate-like syntax for snippets.
But I have now started to explore the more distinctive features of LuaSnip, like Lua-defined snippets.
It turns out that generating snippets with code can save tedious repetition.</p>
<h2 id="markdown-journaling">Markdown Journaling</h2>
<p>I tend to take notes in Markdown documents.
I usually set up one text file for each recurring themes or project.
Then, there is a “h1” title per day, a bit like the <a href="https://help.bulletjournal.com/article/27-daily-log">Bullet Journal daily log</a>.
The resulting file looks like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;display:grid;"><code class="language-markdown" data-lang="markdown"><span style="display:flex; background-color:#3d4148"><span># 2022-07-31 Sun
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#c678dd">*</span> Point 1
</span></span><span style="display:flex;"><span><span style="color:#c678dd">*</span> Point 2
</span></span><span style="display:flex;"><span><span style="color:#c678dd">*</span> Point 3
</span></span></code></pre></div><p>I have a snippet to generate the <code># 2022-07-31 Sun</code> line, based on the current date and day of the week, as I explained <a href="https://cj.rs/blog/ultisnips-to-luasnip/#advanced-snippets-with-environment-variables">last time</a>.
For reference, here is the snippet from back then:</p>
<pre tabindex="0"><code class="language-snippet" data-lang="snippet"># “Bullet Journal”-styled date for today
snippet bjtoday
  # ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} $CURRENT_DAY_NAME_SHORT
</code></pre><h2 id="lua-generated-snippets">Lua-Generated Snippets</h2>
<p>But then, I also sometimes want to put notes for the next session.
I usually know when that will be, because the meeting happens, say, every Thursday or every month.
So it would be great to have snippets for those dates as well.
Let’s build them step by step.</p>
<h3 id="1-computing-the-date-of-next-friday">1. Computing the Date of “Next Friday”</h3>
<p>The first step is to calculate the date and weekday from human concepts like “next Friday” or “next week”.
Thankfully <a href="https://www.gnu.org/software/coreutils/manual/html_node/date-invocation.html#date-invocation">GNU date</a> supports this, and it’s preinstalled on most GNU/Linux systems:</p>
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ date -d <span style="color:#98c379">&#39;next Friday&#39;</span> +<span style="color:#98c379">&#39;%F %a&#39;</span>
</span></span><span style="display:flex;"><span>2022-08-05 Fri
</span></span></code></pre></div><h3 id="2-putting-those-dates-in-luasnip">2. Putting Those Dates in LuaSnip</h3>
<p>The second step is to use the output of the <code>date</code> command in LuaSnip.</p>
<p>We could <a href="https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#variables">define our own variables</a> like <code>${NEXT_MONDAY_DATE}</code>.
That would be similar to the <code>${CURRENT_DATE}</code> we used before.
But we would need many such variables, for the date and weekday of the next Monday, Tuesday, …, next week or next month.
Plus I use those dates only in Markdown snippets, so it feels a bit wasteful to define those variables everywhere.</p>
<p>In the end, I chose to use <a href="https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#functionnode">function nodes</a> to call the <code>date</code> command on the fly, when the snippet gets expanded.
This node is inserted in a particular snippet definition and is thus contained to that particular snippet.
This way, we avoid creating values everywhere, and we keep the global namespace clean.
It looks like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-lua" data-lang="lua"><span style="display:flex;"><span><span style="color:#e06c75">f</span>(<span style="color:#c678dd">function</span>(<span style="color:#e06c75">args</span>, <span style="color:#e06c75">snip</span>, <span style="color:#e06c75">user_arg_1</span>)
</span></span><span style="display:flex;"><span>    <span style="color:#c678dd">return</span> <span style="color:#e06c75">vim.fn</span>.<span style="color:#e06c75">trim</span>(<span style="color:#e06c75">vim.fn</span>.<span style="color:#e06c75">system</span>(<span style="color:#98c379">[[date -d &#39;]]</span> <span style="color:#56b6c2">..</span> <span style="color:#e06c75">target_date</span> <span style="color:#56b6c2">..</span> <span style="color:#98c379">[[&#39; +&#39;%F %a&#39;]]</span>))
</span></span><span style="display:flex;"><span><span style="color:#c678dd">end</span>, {}),
</span></span></code></pre></div><h3 id="3-generating-snippets-variants">3. Generating Snippets Variants</h3>
<p>The last step is to generate the variants of the base snippet: <code>bj_today</code>, <code>bj_next_monday</code>, …, <code>bj_next_week</code> and <code>bj_next_month</code>.</p>
<p>In LuaSnip, snippets defined using Lua are just a table calling some agreed-upon functions.
Here is an example from the <a href="https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#basics">documentation</a>:</p>
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-lua" data-lang="lua"><span style="display:flex;"><span><span style="color:#e06c75">ls.add_snippets</span>(<span style="color:#98c379">&#34;all&#34;</span>, {
</span></span><span style="display:flex;"><span>	<span style="color:#e06c75">s</span>(<span style="color:#98c379">&#34;ternary&#34;</span>, {
</span></span><span style="display:flex;"><span>		<span style="color:#7f848e">-- equivalent to &#34;${1:cond} ? ${2:then} : ${3:else}&#34;</span>
</span></span><span style="display:flex;"><span>		<span style="color:#e06c75">i</span>(<span style="color:#d19a66">1</span>, <span style="color:#98c379">&#34;cond&#34;</span>), <span style="color:#e06c75">t</span>(<span style="color:#98c379">&#34; ? &#34;</span>), <span style="color:#e06c75">i</span>(<span style="color:#d19a66">2</span>, <span style="color:#98c379">&#34;then&#34;</span>), <span style="color:#e06c75">t</span>(<span style="color:#98c379">&#34; : &#34;</span>), <span style="color:#e06c75">i</span>(<span style="color:#d19a66">3</span>, <span style="color:#98c379">&#34;else&#34;</span>)
</span></span><span style="display:flex;"><span>	})
</span></span><span style="display:flex;"><span>})
</span></span></code></pre></div><p>This creates a snippet (the <code>s</code> function) for <code>all</code> file types. This snippet will expand <code>ternary</code> into <code>cond ? then : else</code>, prompting the user to change the <code>cond</code>, <code>then</code> and <code>else</code> bits (function <code>i</code>) while <code>?</code> and <code>:</code> are “static text” (function <code>t</code>).</p>
<p>We want to write a function that builds a table of date snippet definitions.
That will be returned when the Lua module is loaded.</p>
<h4 id="the-final-code">The Final Code</h4>
<p>The final snippet looks like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;display:grid;"><code class="language-lua" data-lang="lua"><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f"> 1</span><span><span style="color:#7f848e">-- Bullet Journal styled dates in the future</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f"> 2</span><span><span style="color:#c678dd">local</span> <span style="color:#c678dd">function</span> <span style="color:#61afef;font-weight:bold">gen_date_snippets</span>()
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f"> 3</span><span>  <span style="color:#c678dd">local</span> <span style="color:#e06c75">snippets</span> <span style="color:#56b6c2">=</span> {}
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f"> 4</span><span>  <span style="color:#c678dd">local</span> <span style="color:#e06c75">target_dates</span> <span style="color:#56b6c2">=</span> {
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f"> 5</span><span>    <span style="color:#98c379">&#34;today&#34;</span>,
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f"> 6</span><span>    <span style="color:#98c379">&#34;tomorrow&#34;</span>,
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f"> 7</span><span>    <span style="color:#98c379">&#34;next monday&#34;</span>,
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f"> 8</span><span>    <span style="color:#98c379">&#34;next tuesday&#34;</span>,
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f"> 9</span><span>    <span style="color:#98c379">&#34;next wednesday&#34;</span>,
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">10</span><span>    <span style="color:#98c379">&#34;next thursday&#34;</span>,
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">11</span><span>    <span style="color:#98c379">&#34;next friday&#34;</span>,
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">12</span><span>    <span style="color:#98c379">&#34;next week&#34;</span>,
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">13</span><span>    <span style="color:#98c379">&#34;next month&#34;</span>,
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">14</span><span>  }
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">15</span><span>  <span style="color:#c678dd">for</span> <span style="color:#e06c75">_</span>, <span style="color:#e06c75">target_date</span> <span style="color:#c678dd">in</span> <span style="color:#e06c75">pairs</span>(<span style="color:#e06c75">target_dates</span>) <span style="color:#c678dd">do</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">16</span><span>    <span style="color:#e06c75">table.insert</span>(
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">17</span><span>      <span style="color:#e06c75">snippets</span>,
</span></span><span style="display:flex; background-color:#3d4148"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">18</span><span>      <span style="color:#e06c75">s</span>(<span style="color:#98c379">&#34;bj_&#34;</span> <span style="color:#56b6c2">..</span> <span style="color:#e06c75">target_date</span>:<span style="color:#e06c75">gsub</span>(<span style="color:#98c379">&#34; &#34;</span>, <span style="color:#98c379">&#34;_&#34;</span>), {
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">19</span><span>        <span style="color:#e06c75">t</span> <span style="color:#98c379">&#34;# &#34;</span>,
</span></span><span style="display:flex; background-color:#3d4148"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">20</span><span>        <span style="color:#e06c75">f</span>(<span style="color:#c678dd">function</span>(<span style="color:#e06c75">args</span>, <span style="color:#e06c75">snip</span>, <span style="color:#e06c75">user_arg_1</span>)
</span></span><span style="display:flex; background-color:#3d4148"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">21</span><span>          <span style="color:#c678dd">return</span> <span style="color:#e06c75">vim.fn</span>.<span style="color:#e06c75">trim</span>(<span style="color:#e06c75">vim.fn</span>.<span style="color:#e06c75">system</span>(<span style="color:#98c379">[[date -d &#39;]]</span> <span style="color:#56b6c2">..</span> <span style="color:#e06c75">target_date</span> <span style="color:#56b6c2">..</span> <span style="color:#98c379">[[&#39; +&#39;%F %a&#39;]]</span>))
</span></span><span style="display:flex; background-color:#3d4148"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">22</span><span>        <span style="color:#c678dd">end</span>, {}),
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">23</span><span>      })
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">24</span><span>    )
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">25</span><span>  <span style="color:#c678dd">end</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">26</span><span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">27</span><span>  <span style="color:#c678dd">return</span> <span style="color:#e06c75">snippets</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">28</span><span><span style="color:#c678dd">end</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">29</span><span>
</span></span><span style="display:flex; background-color:#3d4148"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#55595f">30</span><span><span style="color:#c678dd">return</span> <span style="color:#e06c75">gen_date_snippets</span>()
</span></span></code></pre></div><p>This generates the snippets name (line 18), for instance <code>bj_today</code> or <code>bj_next_tuesday</code> from the arguments passed to the <code>date</code> command.
The body of the snippet is made of text (<code>t &quot;# &quot;</code>) and our function node from earlier (line 20-22).
All those snippets get collected in a table that is returned at the end of the Lua module (line 30).
It’s then usable by LuaSnip.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Generating a bunch of similar snippets like this turned out to be an unanticipated benefit of using Lua to define snippets.
Before using LuaSnip, I only had <code>bj_today</code>, <code>bj_tomorrow</code> and <code>bj_next_monday</code>.
If I had wanted to expand this set further, I would have to do some more copying and pasting, which quickly becomes unmaintainable.</p>
<p>Of course for simpler or less repetitive snippets, it’s probably best to use the less verbose SnipMate-like syntax presented in the <a href="https://cj.rs/blog/ultisnips-to-luasnip/">previous post</a>.</p>
]]></content:encoded></item><item><title>From UltiSnips to LuaSnip</title><link>https://cj.rs/blog/ultisnips-to-luasnip/</link><pubDate>Sun, 15 May 2022 07:06:49 +0100</pubDate><guid>https://cj.rs/blog/ultisnips-to-luasnip/</guid><description>Shaving off a few milliseconds from Neovim startup time.</description><content:encoded><![CDATA[



  
  
  
  

  <div class="alert alert-tldr">
    <p class="alert-heading">
      ⚡
      
        TL;DR
      
    </p>
    <p><a href="https://github.com/L3MON4D3/LuaSnip">LuaSnip</a> is fast and doesn’t have to be complicated. Give it a try!</p>
  </div>







  
  
  
    
    
  
  

  <details class="alert alert-note">
    <summary class="alert-heading">
      ℹ️
      
        About UltiSnips
      
    </summary>
    <p>Even if that article shows how <a href="https://github.com/L3MON4D3/LuaSnip">LuaSnip</a> shines, I have great respect for the work that has gone into <a href="https://github.com/sirver/UltiSnips">UltiSnips</a>. It is still a reliable, reasonably fast plugin given the constraint it operates in (in particular, Vim compatibility requires a fair amount of Vimscript). I’ve written this article shortly after trying LuaSnip and I’m still very much evaluating it.</p>
  </details>



<h2 id="introduction">Introduction</h2>
<p><a href="https://en.wikipedia.org/wiki/Snippet_(programming)">Snippets</a> are a convenient feature of some text editors to insert and adapt reusable pieces of code. For instance, snippets for <code>for</code> loops are common, to get the tedious bits of the syntax out of the way.</p>
<p>To get this feature in Vim back in the days, I started using <a href="https://github.com/sirver/UltiSnips">UltiSnips</a>. There are <a href="https://github.com/honza/vim-snippets">default snippets sets</a> for it, and it’s easy to write custom snippets. These custom snippet can call Bash or Python scripts if you need more dynamic replacements. UltiSnips has been very powerful and has served me quite well over the past decade or so, and I have kept it when I migrated to NeoVim a few years ago.</p>
<h2 id="startup-time">Startup time</h2>
<p>Every once in a while though, I run the excellent <a href="https://github.com/rhysd/vim-startuptime">vim-startuptime</a> command to assess the impact of various configurations and plugins on the startup time of Neovim. With UltiSnips and the corresponding completion plugins in my configuration, the first few lines are:</p>
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;display:grid;"><code class="language-markdown" data-lang="markdown"><span style="display:flex;"><span>Extra options: []
</span></span><span style="display:flex;"><span>Measured: 10 times
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Total Average: 104.218300 msec
</span></span><span style="display:flex;"><span>Total Max:     109.719000 msec
</span></span><span style="display:flex;"><span>Total Min:     99.533000 msec
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  AVERAGE       MAX       MIN
</span></span><span style="display:flex;"><span>------------------------------
</span></span><span style="display:flex; background-color:#3d4148"><span>64.218600 70.419000 61.066000: ~/.config/nvim/init.lua
</span></span><span style="display:flex;"><span> 6.255900  7.238000  5.764000: loading packages
</span></span><span style="display:flex;"><span> 3.939000  5.338000  3.533000: ~/.local/share/nvim/site/pack/paqs/start/onedark.nvim/colors/onedark.lua
</span></span><span style="display:flex;"><span> 3.651100  4.003000  3.381000: loading rtp plugins
</span></span><span style="display:flex;"><span> 2.761600  3.957000  2.474000: expanding arguments
</span></span><span style="display:flex;"><span> 2.683900  3.035000  2.566000: reading ShaDa
</span></span><span style="display:flex;"><span> 2.418700  3.610000  2.131000: sourcing vimrc file(s)
</span></span><span style="display:flex;"><span> 2.389600  2.751000  2.228000: /usr/share/nvim/runtime/filetype.lua
</span></span><span style="display:flex;"><span> 1.954900  2.293000  1.702000: loading after plugins
</span></span><span style="display:flex;"><span> 1.842500  2.015000  1.763000: BufEnter autocommands
</span></span><span style="display:flex; background-color:#3d4148"><span> 1.583350  3.532000  0.018000: ~/.local/share/nvim/site/pack/paqs/start/ultisnips/plugin/UltiSnips.vim
</span></span><span style="display:flex;"><span> 1.027700  1.170000  0.831000: ~/.local/share/nvim/site/pack/paqs/start/nvim-treesitter/plugin/nvim-treesitter.lua
</span></span><span style="display:flex; background-color:#3d4148"><span> 0.968200  1.071000  0.860000: ~/.local/share/nvim/site/pack/paqs/start/cmp-nvim-ultisnips/after/plugin/cmp_nvim_ultisnips.lua
</span></span><span style="display:flex;"><span> 0.859000  1.014000  0.702000: ~/.local/share/nvim/site/pack/paqs/start/nvim-treesitter-textobjects/plugin/nvim-treesitter-textobjects.vim
</span></span><span style="display:flex;"><span> 0.590700  0.674000  0.524000: ~/.local/share/nvim/site/pack/paqs/start/indent-blankline.nvim/plugin/indent_blankline.vim
</span></span><span style="display:flex;"><span> 0.557200  0.817000  0.493000: init highlight
</span></span><span style="display:flex;"><span> 0.553200  0.898000  0.322000: opening buffers</span></span></code></pre></div>
<p>The <code>init.lua</code> line covers a lot of different plugins and mappings set up in that file. Besides the <a href="https://github.com/navarasu/onedark.nvim">onedark.nvim</a> colorscheme<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>, the next biggest contributor is <code>~/…/ultisnips/plugin/UltiSnips.vim</code>. The script to integrate UltiSnips with <a href="https://github.com/hrsh7th/nvim-cmp">cmp</a>, <code>~/…/cmp-nvim-ultisnips/after/plugin/cmp_nvim_ultisnips.lua</code>, is not far behind. In total, we spend nearly 4 ms of the startup time for UltiSnips-related files, on top of the setup done in <code>init.lua</code>. That feels suboptimal, so I’ve been looking for a possible snippet plugin alternative.</p>
<h2 id="installing-luasnip">Installing LuaSnip</h2>
<p><a href="https://github.com/L3MON4D3/LuaSnip">LuaSnip</a> aims to be a faster<sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup> snippet engine, with support of treesitter in the snippets. It can also understand the LSP snippet “format”. Finally, it’s a pure Lua plugin, without any Python requirement, contrary to UltiSnips. That makes installation on various system much easier.</p>
<p>Its drawbacks for me are that it does not support the same snippet definition as UltiSnips and even in its own SnipMate-like syntax, backticks to execute code are not supported. As a result, I’ll have to migrate my (admittedly very small) snippet collection. Conversely, if I want to do more advanced things, I’ll have to learn the relatively complex “VS Studio Code” snippets in JSON or even the pure Lua snippets.</p>
<p>That’s said, I believe I can get the LuaSnip benefits without writing Lua snippets or JSON ones, at least to start. So let’s try and do that, using only the SnipMate-like syntax!</p>
<h2 id="overview-of-the-configuration-changes">Overview of the Configuration Changes</h2>
<p>I’ve made the following changes.</p>
<ol>
<li>Remove UltiSnips and its associated plugins, namely for completion with <a href="https://github.com/hrsh7th/nvim-cmp">cmp</a> and the telescope integration.</li>
<li>Remove the UltiSnips mappings.</li>
<li>Add LuaSnip (following the instructions in the <a href="https://github.com/L3MON4D3/LuaSnip">Readme</a>), <a href="https://github.com/saadparwaiz1/cmp_luasnip">its cmp integration</a>, a <a href="https://github.com/rafamadriz/friendly-snippets">set of snippets</a> and a <a href="https://github.com/benfowler/telescope-luasnip.nvim">telescope integration</a> along with some mappings (requires nvim 0.7+<sup id="fnref:3"><a href="#fn:3" class="footnote-ref" role="doc-noteref">3</a></sup>):
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-lua" data-lang="lua"><span style="display:flex;"><span><span style="color:#e06c75">vim.keymap</span>.<span style="color:#e06c75">set</span>({ <span style="color:#98c379">&#34;i&#34;</span>, <span style="color:#98c379">&#34;s&#34;</span> }, <span style="color:#98c379">&#34;&lt;C-i&gt;&#34;</span>, <span style="color:#c678dd">function</span>() <span style="color:#e06c75">require</span><span style="color:#98c379">&#39;luasnip&#39;</span>.<span style="color:#e06c75">jump</span>(<span style="color:#d19a66">1</span>) <span style="color:#c678dd">end</span>, { <span style="color:#e06c75">desc</span> <span style="color:#56b6c2">=</span> <span style="color:#98c379">&#34;LuaSnip forward jump&#34;</span> })
</span></span><span style="display:flex;"><span><span style="color:#e06c75">vim.keymap</span>.<span style="color:#e06c75">se</span>({ <span style="color:#98c379">&#34;i&#34;</span>, <span style="color:#98c379">&#34;s&#34;</span> }, <span style="color:#98c379">&#34;&lt;M-i&gt;&#34;</span>, <span style="color:#c678dd">function</span>() <span style="color:#e06c75">require</span><span style="color:#98c379">&#39;luasnip&#39;</span>.<span style="color:#e06c75">jump</span>(<span style="color:#56b6c2">-</span><span style="color:#d19a66">1</span>) <span style="color:#c678dd">end</span>, { <span style="color:#e06c75">desc</span> <span style="color:#56b6c2">=</span> <span style="color:#98c379">&#34;LuaSnip backward jump&#34;</span> })
</span></span></code></pre></div></li>
<li><a href="#migrate-my-snippet-collection">Migrate my existing snippets</a>, see below.</li>
<li>Add code to load the snippet set and my own snippet collection:
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-lua" data-lang="lua"><span style="display:flex;"><span><span style="color:#e06c75">require</span>(<span style="color:#98c379">&#34;luasnip.loaders.from_vscode&#34;</span>).<span style="color:#e06c75">lazy_load</span>()
</span></span><span style="display:flex;"><span><span style="color:#e06c75">require</span>(<span style="color:#98c379">&#34;luasnip.loaders.from_snipmate&#34;</span>).<span style="color:#e06c75">lazy_load</span>({ <span style="color:#e06c75">paths</span> <span style="color:#56b6c2">=</span> {<span style="color:#98c379">&#34;./snippets&#34;</span>} })
</span></span></code></pre></div></li>
</ol>
<h3 id="after">After</h3>
<p>Let’s run vim-startuptime again. Here are the new top contributors:
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;display:grid;"><code class="language-markdown" data-lang="markdown"><span style="display:flex;"><span>Extra options: []
</span></span><span style="display:flex;"><span>Measured: 10 times
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Total Average: 98.251400 msec
</span></span><span style="display:flex;"><span>Total Max:     100.159000 msec
</span></span><span style="display:flex;"><span>Total Min:     96.519000 msec
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  AVERAGE       MAX       MIN
</span></span><span style="display:flex;"><span>------------------------------
</span></span><span style="display:flex; background-color:#3d4148"><span>60.469100 62.341000 59.619000: ~/.config/nvim/init.lua
</span></span><span style="display:flex;"><span> 5.991100  6.219000  5.865000: loading packages
</span></span><span style="display:flex;"><span> 4.088400  4.162000  3.942000: loading after plugins
</span></span><span style="display:flex;"><span> 3.635700  3.752000  3.415000: loading rtp plugins
</span></span><span style="display:flex;"><span> 3.561800  3.936000  3.220000: ~/.local/share/nvim/site/pack/paqs/start/onedark.nvim/colors/onedark.lua
</span></span><span style="display:flex;"><span> 2.550500  2.628000  2.492000: reading ShaDa
</span></span><span style="display:flex;"><span> 2.454200  2.525000  2.401000: expanding arguments
</span></span><span style="display:flex;"><span> 2.363000  2.420000  2.270000: /usr/share/nvim/runtime/filetype.lua
</span></span><span style="display:flex;"><span> 2.271100  2.337000  2.146000: sourcing vimrc file(s)
</span></span><span style="display:flex;"><span> 1.701000  1.767000  1.635000: BufEnter autocommands
</span></span><span style="display:flex;"><span> 1.676700  2.049000  1.366000: opening buffers
</span></span><span style="display:flex;"><span> 1.034100  1.280000  0.782000: ~/.local/share/nvim/site/pack/paqs/start/nvim-treesitter/plugin/nvim-treesitter.lua
</span></span><span style="display:flex;"><span> 0.901000  1.021000  0.799000: ~/.local/share/nvim/site/pack/paqs/start/nvim-treesitter-textobjects/plugin/nvim-treesitter-textobjects.vim
</span></span><span style="display:flex;"><span> 0.590700  0.674000  0.524000: ~/.local/share/nvim/site/pack/paqs/start/indent-blankline.nvim/plugin/indent_blankline.vim
</span></span><span style="display:flex;"><span> 0.549500  0.789000  0.514000: init highlight</span></span></code></pre></div></p>
<p>The snippet infrastructure is now absent from that list! More importantly, the overall startup time is down, and we can be confident that the new calls to load the snippets in <code>init.lua</code> are not costlier than UltiSnips settings before, because the <code>init.lua</code> line is down as well.</p>
<p>As a bonus, the snippet expansion feels slightly snappier with LuaSnip, although it might be an illusion and I don’t have hard numbers to back this claim.</p>
<h2 id="migrate-my-snippet-collection">Migrate my Snippet Collection</h2>
<p>Back to the topic of migrating existing UltiSnips snippets: LuaSnip will loudly complain when given UltiSnips snippets but it’s relatively easy to rewrite those snippets to the SnipMate-like format that LuaSnip understands.</p>
<h3 id="two-syntaxes">Two Syntaxes</h3>
<p>On the one hand, UltiSnips snippets roughly follow this syntax</p>
<pre tabindex="0"><code class="language-snippet" data-lang="snippet">snippet trigger &#34;Comment&#34; option
snippet content
endsnippet
</code></pre><p>And so, my markdown snippets would look like this:</p>
<pre tabindex="0"><code class="language-snippet" data-lang="snippet">priority 10

snippet bjtoday &#34;“Bullet Journal”-styled date for today&#34; b
# `date +&#39;%F %A&#39;`
endsnippet
</code></pre><p>On the other hand, LuaSnip uses a simplified version of SnipMate snippets:</p>
<pre tabindex="0"><code># Comment
snippet toggle
  snippet content
</code></pre><h3 id="simple-snippets">Simple Snippets</h3>
<p>Since I heavily rely on snippet sets, I have only about 30 snippets defined in my own snippet collection. Most of them are really simple, with only a few lines and almost no interactive text. So for most of those, the process has been to simply remove the <code>priority …</code> lines and then a simple substitution command<sup id="fnref:4"><a href="#fn:4" class="footnote-ref" role="doc-noteref">4</a></sup> did the trick.</p>
<h3 id="advanced-snippets-with-environment-variables">Advanced Snippets With Environment Variables</h3>
<p>However, there is also the case of the snippets calling external commands, like <code>date</code> in the example below:</p>
<pre tabindex="0"><code class="language-snippet" data-lang="snippet">snippet bjtoday &#34;“Bullet Journal”-styled date for today&#34; b
# `date +&#39;%F %A&#39;`
endsnippet
</code></pre><p>The problem is, to call arbitrary commands, one needs to define the snippets in Lua.</p>
<p>It turns out though that nearly all my snippets calling external command were actually inserting a date. And luckily LuaSnip defines “environment variables” holding just the values I need like <code>$CURRENT_MONTH</code>. So that snippet becomes:</p>
<pre tabindex="0"><code class="language-snippet" data-lang="snippet"># “Bullet Journal”-styled date for today
snippet bjtoday
  # ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} $CURRENT_DAY_NAME_SHORT
</code></pre><p>and we get to keep the simple SnipMate-like syntax!</p>
<p>You can find more of those environment variables in <a href="https://github.com/L3MON4D3/LuaSnip/blob/master/lua/luasnip/util/environ.lua">the sources</a>.</p>




  
  
  
  

  <div class="alert alert-edit">
    <p class="alert-heading">
      ✏
      
        Edit
      
    </p>
    <p>2022-08-03: See also <a href="https://github.com/smjonas/snippet-converter.nvim">snippet-converter.nvim</a> to convert between various snippet formats.<sup id="fnref:5"><a href="#fn:5" class="footnote-ref" role="doc-noteref">5</a></sup></p>
  </div>



<h2 id="whats-next">What’s Next</h2>
<p>I now have a slightly faster NeoVim and the snippet syntax that I use the most is simpler. However, there is more to explore!</p>
<p>So far, I’ve steered clear of writing more complicated JSON and Lua snippets. The latter would be necessary to unlock smart snippets using treesitter <a href="https://changelog.com/podcast/457#t=01:00:01.17">context</a>. I’ll look into that next, in particular to generate go error handling code.</p>
<p>This is also a very simple configuration, the impact on startup time of LuaSnip might go up slightly as we use more advanced feature, but during my tests, even using all available features, it was much lighter than UltiSnips.</p>




  
  
  
  

  <div class="alert alert-edit">
    <p class="alert-heading">
      ✏
      
        Edit
      
    </p>
    <p>2022-07-31: <a href="https://cj.rs/tags/luasnip/">Follow-up posts</a> dig deeper in other aspects of LuaSnip</p>
  </div>



<h2 id="resources">Resources</h2>
<ul>
<li>Many more details are covered in <a href="https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md">LuaSnip documentation</a>.</li>
<li>The <a href="https://github.com/garbas/vim-snipmate/blob/master/doc/SnipMate.txt">SnipMate help</a> contains the SnipMate snippet syntax, if you are unfamiliar with it.</li>
<li>The <a href="https://github.com/microsoft/language-server-protocol/blob/main/snippetSyntax.md">LSP snippet documentation</a> is also helpful.</li>
</ul>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>That run is actually on a fork of <a href="https://github.com/navarasu/onedark.nvim">onedark.nvim</a> that contains a massive speed up. The changes of that fork are being up streamed in <a href="https://github.com/navarasu/onedark.nvim/pull/76">this PR</a>.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:2">
<p>According to that comment from the author for instance: <a href="https://github.com/L3MON4D3/LuaSnip/issues/60#issuecomment-873630664">https://github.com/L3MON4D3/LuaSnip/issues/60#issuecomment-873630664</a>.&#160;<a href="#fnref:2" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:3">
<p>This code snippet uses new APIs introduced in Neovim 0.7 and the newly freed <code>&lt;C-i&gt;</code>, see <a href="https://gpanders.com/blog/whats-new-in-neovim-0-7/">https://gpanders.com/blog/whats-new-in-neovim-0-7/</a> for more details.&#160;<a href="#fnref:3" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:4">
<p>For instance: <code>%s/^\(snippet \+\S\+\) &quot;\(.*\)&quot; \w\+\n\(\_.\{-}\)endsnippet/# \2^M\1^M \3^M</code>.&#160;<a href="#fnref:4" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:5">
<p>Thanks to <a href="https://www.reddit.com/user/Miserable-Ad-7341">Miserable-Ad-7341</a> for <a href="https://www.reddit.com/r/neovim/comments/weonip/from_ultisnips_to_luasnip/iipheov/">pointing this out</a>.&#160;<a href="#fnref:5" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded></item><item><title>You “Own” 16 Milion+ IPv4 Addresses!</title><link>https://cj.rs/blog/tips/you-own-16-milion-ipv4-addresses/</link><pubDate>Sat, 05 Mar 2022 21:13:22 +0000</pubDate><guid>https://cj.rs/blog/tips/you-own-16-milion-ipv4-addresses/</guid><description>What can you do with the huge loopback range (127.0.0.0/8)? Is it future-proof?</description><content:encoded><![CDATA[



  
  
  
  

  <div class="alert alert-tldr">
    <p class="alert-heading">
      ⚡
      
        TL;DR
      
    </p>
    <p>For the foreseeable future, you can likely use <code>127.0.0.0/8</code> freely (or at least <code>127.0.0.0/16</code>).</p>
  </div>



<h2 id="introducing-1270008-the-loopback-range">Introducing <code>127.0.0.0/8</code>, the Loopback Range</h2>
<figure>
    <img loading="lazy" src="/blog/tips/you-own-16-milion-ipv4-addresses/opengraph.webp"
         alt="If you have a Cidr range 127.0.0.0/8 visualized with 4 colors, one color per number." width="1941" height="855"/> <figcaption>
            Visualization of the 127.0.0.0/8 range<p>From <a href="https://cidr.xyz">cidr.xyz</a> by <a href="https://yuv.al/">Yuval Adam</a></p>
        </figcaption>
</figure>

<p>If you have ever done web development or otherwise set up a local server, you have most likely used the IP address <code>127.0.0.1</code> to communicate with a local server. Often, <a href="https://en.wikipedia.org/wiki/Localhost"><code>localhost</code></a> is even internally translated to that address. But what if you want to run another server on the same computer? Easy, make the first one use, say, port <code>8080</code> and the second one, port <code>8181</code>!</p>
<p>Something more difficult now: say you can convince<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> your browser that your local service is serving a valid HTTPS connection only if you use port number <code>443</code>. How can you run many of those services? In turns out in IPv4, you have many such local addresses: <code>127.0.0.1</code>, <code>127.0.0.2</code>,  <code>127.0.0.3</code>, <code>127.0.0.4</code>… So you just need to spawn the various servers on the same <code>443</code> port number with different addresses and packets will go straight to your <a href="https://en.wikipedia.org/wiki/Localhost">localhost</a>.</p>
<p>But how many such addresses do we have? According to <a href="https://www.rfc-editor.org/rfc/rfc990.txt">RFC990</a> from 1986:</p>




  <figure>
    <blockquote cite="https://www.rfc-editor.org/rfc/rfc990.txt">
      <pre><code>   The class A network number 127 is assigned the &quot;loopback&quot;
   function, that is, a datagram sent by a higher level protocol
   to a network 127 address should loop back inside the host.  No
   datagram &quot;sent&quot; to a network 127 address should ever appear on
   any network anywhere.
</code></pre>

    </blockquote>
    
      <figcaption class="blockquote-caption">
        
          <cite style="text-align: right"><a href="https://www.rfc-editor.org/rfc/rfc990.txt">https://www.rfc-editor.org/rfc/rfc990.txt</a></cite>
          <br/>
        
        
      </figcaption>
    
  </figure>



<p>The “class A network” translate to a <code>/8</code> in <a href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing">CIDR notation</a>, so that’s all addresses between <code>127.0.0.0</code> and <code>127.255.255.255</code>. A quite sizeable 2²⁴ or <em>16,777,216</em> addresses<sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup>!</p>
<p>Note the wording of the RFC: IPs are not “owned”, there are just “allocated”. For addresses routable on the wider Internet, it’s usually done by <a href="https://en.wikipedia.org/wiki/Regional_Internet_registry">Regional Internet Registeries</a>. And allocations could change, as we will see at the end of this article.</p>
<h2 id="other-use-cases">Other Use Cases</h2>
<p>What can you do with so many IPs? A couple of things.</p>
<h3 id="multiple-servers-on-the-same-port-number">Multiple Servers on the Same Port Number</h3>
<p>As we have seen earlier with the port number <code>443</code> example, the <code>127.0.0.0/8</code> range is handy to run multiple local services on the same port. Thus, it’s not surprising to see <code>systemd-resolved</code> – a local DNS resolver that needs to listen on port <code>53</code> – use a couple addresses from that range. The <a href="https://man.archlinux.org/man/core/systemd/systemd-resolved.8.en">man page</a> reads:</p>




  <figure>
    <blockquote cite="https://man.archlinux.org/man/core/systemd/systemd-resolved.8.en">
      <p>Additionally, systemd-resolved provides a local DNS stub listener on the IP addresses 127.0.0.53 and
127.0.0.54 on the local loopback interface.</p>

    </blockquote>
    
      <figcaption class="blockquote-caption">
        
          <cite style="text-align: right"><a href="https://man.archlinux.org/man/core/systemd/systemd-resolved.8.en">https://man.archlinux.org/man/core/systemd/systemd-resolved.8.en</a></cite>
          <br/>
        
        
      </figcaption>
    
  </figure>



<p>In this case, <code>systemd-resolved</code> <em>has to</em> bind on the default port, because one of the main ways (on Unix-like systems) that DNS resolution is configured is through the file <a href="https://man.archlinux.org/man/resolv.conf.5.en"><code>/etc/resolv.conf</code></a>. This file does not widely support setting a port number, forcing the configured server to be reachable on the default port. Thanks to the use of a loopback addresse though, <code>systemd-resolved</code> can become the default resolver just by adding this line to <code>resolv.conf</code>:</p>
<pre tabindex="0"><code>nameserver 127.0.0.53
</code></pre><h3 id="naming-things">Naming Things</h3>
<p>On Unix-like systems, the <code>/etc/hosts</code> file associates IP addresses with names, like so:</p>
<pre tabindex="0"><code>127.0.0.1	localhost
::1		localhost
</code></pre><p>That’s how <code>localhost</code> is associated with <code>127.0.0.1</code> (and IPv6 <code>::1</code>).</p>
<p>You can edit this file and add useful aliases to other IPs (not necessarily in the local range by the way). Then, you just bind your multiple services to their default ports and access to them by name. No more complicated ports to remember! This benefit comes as a byproduct of using default ports but with different IPs for different services.</p>
<p>For instance, you could name one of the aforementioned <code>systemd-resolved</code> IPs by adding this line to <code>/etc/hosts</code>:</p>
<pre tabindex="0"><code>127.0.0.1	localhost
::1		localhost

127.0.0.53	sd
</code></pre><p>And then query it like so:</p>
<pre tabindex="0"><code>dig @sd s.cj.rs
</code></pre><p>instead of</p>
<pre tabindex="0"><code>dig @127.0.0.53 s.cj.rs
</code></pre><p>if you did not have the setting.</p>
<p>I’m using this trick to make the <a href="https://syncthing.net/">Syncthing</a> web interface accessible on a memorable port on an address with a memorable name in my web browser.</p>
<h2 id="future-of-1270008">Future of <code>127.0.0.0/8</code></h2>
<p>Even if the ability to give various services different IPs is handy, 16 milion addresses is huge. Given how IPv4 is sometimes called “internet <a href="https://fly.io/blog/32-bit-real-estate/">real-estate</a>”, there have been discussions to drastically limit the size of this loopback range, and use some of it as “normal” IPs. For instance, this <a href="https://www.ietf.org/id/draft-schoen-intarea-unicast-127-00.html">IETF draft</a> proposes to cut the loopback range to <code>127.0.0.0/16</code> (so only addresses between <code>127.0.0.0</code> and <code>127.0.255.255</code>) and make the rest (addresses between <code>127.1.0.0</code> and <code>127.255.255.255</code>) routable on the public internet. The 65536 addresses in <code>127.0.0.0/16</code> should to be enough for almost everyone on a local machine and nearly 16 million IPs could be used as a fresh supply of IPv4 addresses<sup id="fnref:3"><a href="#fn:3" class="footnote-ref" role="doc-noteref">3</a></sup>.</p>
<h3 id="and-ipv6">And IPv6?</h3>
<p>Even though IPv6 has a huge namespace, your IPv6 loopback only has one address <code>::1</code>. And that’s quite a shame because, as we have just seen, multiple loopback addresses are quite handy.</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>For instance using <a href="https://mkcert.dev/">mkcert</a>.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:2">
<p>Admittedly, some addresses like <code>127.0.0.0</code> or <code>127.255.255.255</code> are reserved, but there is still plenty of space.&#160;<a href="#fnref:2" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:3">
<p>Whether more useable IPv4 addresses is a good thing is debated. It might divert efforts from the IPv6 transition and even with a few millions more IPv4 addresses, these are still scarce.&#160;<a href="#fnref:3" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded></item><item><title>Configuration Management</title><link>https://cj.rs/blog/my-setup/chezmoi/</link><pubDate>Fri, 03 Sep 2021 19:59:01 +0100</pubDate><guid>https://cj.rs/blog/my-setup/chezmoi/</guid><description>I use Chezmoi to manage my configuration</description><content:encoded><![CDATA[



  
  
  
  

  <div class="alert alert-tldr">
    <p class="alert-heading">
      ⚡
      
        TL;DR
      
    </p>
    <p>Chezmoi follows a declarative approach to configuration management. Even if you already use a configuration-management system, you should <a href="https://www.chezmoi.io/docs/comparison/">check out how it compares</a>!</p>
  </div>



<h2 id="a-custom-configuration-makes-you-feel-at-home">A Custom Configuration Makes You Feel at Home</h2>
<p>Your git aliases, shell setup, keyboard shortcuts and even your favorite fonts are tweaked for your own needs and tastes. It’s part of what makes your computer, <em>your</em> computer. All this configuration evolves over years and is slowly refined over time. It may actually be your longuest-living project.</p>
<p>Do you want to start from scratch when you switch computer? Of course not! And you wouldn’t want to break it with adventurous changes either! Versioning it in <a href="https://drewdevault.com/2019/12/30/dotfiles.html">git</a> backs up the history and eases the management of this important work. Configuration updates are also more convenient to share between machines this way.</p>
<h2 id="enter-chezmoi">Enter Chezmoi</h2>
<p>In the git-based configuration management described above, how to account for the small variations (like between your <a href="https://utf9k.net/blog/conditional-gitconfig/">work environment and personal computer</a>)? Git supports <a href="https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/RelNotes/2.13.0.txt#n127">conditional inclusion of configuration files</a>, but how about the other tools? What if you want to encrypt your secrets in your config files, to publish your configuration on GitHub?</p>
<p><a href="https://www.chezmoi.io">Chezmoi</a> follows a <em>declarative approach</em>: it has a separate <em>source repository</em><sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> to describe a target state, that then gets applied to your home directory. This is possible through templates, that are activated selectively for some files. The rest of this post shows how powerful templating can be.</p>
<h2 id="account-for-variations-between-machines">Account for Variations Between Machines</h2>
<p>Let’s start with a simple example. In the git configuration, you put your email, that’s then included in all your commits. Thus, you often want to have a different email in <code>.gitconfig</code> for your work and personal profiles. To tackle this issue, I put the following in my <code>.gitconfig</code> chezmoi template:</p>
<pre tabindex="0"><code>[user]
    email = {{ .email }}
</code></pre><p>and it gets rendered to this:</p>
<pre tabindex="0"><code>[user]
    email = me@my.home
</code></pre><p>on my personal computer and this:</p>
<pre tabindex="0"><code>[user]
    email = me@my.work
</code></pre><p>on my work computer. It serves a purpose similar to <a href="https://utf9k.net/blog/conditional-gitconfig/">conditionally setting your gitconfig</a>, but it is applicable to any program.</p>
<h2 id="even-more-variations-with-templates">Even More Variations with Templates</h2>
<p>Now, let’s cover a more powerful use of templates.</p>
<p>You can have multiple files generated from one using <a href="https://www.chezmoi.io/docs/templating/#using-chezmoitemplates">“global” templates</a>. For instance, if you use <a href="https://i3wm.org/">i3</a> and <a href="https://swaywm.org/">sway</a> as your windows manager, you likely have slightly different configurations, given that sway’s configuration is mostly compatible with that of i3. To keep everything in one file, while taking advantages of sway-specific features, you can (in your chezmoi repository):</p>
<ol>
<li>Put your configuration in <code>.chezmoitemplates/sway_i3</code>. You can keep any sway specific section in a templated <code>if</code> statement, like so:
<pre tabindex="0"><code>{{- if eq .f &#34;sway&#34; }}
# Sway specific stuff here, like output configuration
{{- end }}
</code></pre></li>
<li>In <code>dot_config/i3/config.tmpl</code> (and <code>dot_config/sway/config.tmpl</code>), use something like:
<pre tabindex="0"><code>{{/* Environment */}}
{{- $env := . -}}

{{/* Flavor */}}
{{- $f := &#34;i3&#34; -}} # &lt;--- Change this to &#34;sway&#34; in dot_config/sway/config.tmpl

{{- template &#34;sway_i3&#34; dict &#34;f&#34; $f &#34;env&#34; $env -}}
</code></pre>As you may have noticed, chezmoi renames some files in the source state, to encode parameters and for readability. So <code>dot_config/sway/config.tmpl</code> becomes <code>.config/sway/config</code> (<code>.tmpl</code> means the file is executed as a template).    <br>
Also, <code>$env</code> is used to keep the general template context, for instance to check the OS version in our template config file.</li>
</ol>
<h2 id="chezmoiignore">.chezmoiignore</h2>
<p>Finally, chezmoi supports an ignore file named <code>.chezmoiignore</code>. The concept is similar to the well known <code>.gitignore</code>: patterns listed in this file are ignored by chezmoi. In other words, some files are stored in your chezmoi repository, but do not reflect in your home. This can be used if you put a <code>README.md</code> in your configuration repository, as you don’t want this file in your home directory. Just write:</p>
<pre tabindex="0"><code>README.md
</code></pre><p>in <code>.chezmoiignore</code> and the <code>README.md</code> won’t be copied in your home.</p>
<p>You can do more advanced things with <code>.chezmoiignore</code> as it is a template by default. From <a href="https://www.chezmoi.io/docs/reference/#chezmoiignore">the documentation</a>:</p>
<pre tabindex="0"><code>{{- if ne .email &#34;firstname.lastname@company.com&#34; }}
# Ignore .company-directory unless configured with a company email
.company-directory # note that the pattern is not dot_company-directory
{{- end }}
</code></pre><h2 id="conclusion">Conclusion</h2>
<p>Chezmoi has lot more <a href="https://www.chezmoi.io/docs/reference/">features</a>, like <a href="https://www.chezmoi.io/docs/how-to/#encrypt-whole-files-with-gpg">encryption</a> or <a href="https://www.chezmoi.io/docs/how-to/#use-chezmoi-with-github-codespaces-visual-studio-codespaces-or-visual-studio-code-remote---containers">installation in GitHub Codespaces</a>. It is quite <a href="https://www.chezmoi.io">well documented</a>, in particular with a <a href="https://www.chezmoi.io/docs/quick-start/">quick start guide</a>.</p>
<p>I’ve switched to it almost two years ago, I don’t regret it at all!</p>
<h2 id="bonus-vim-snippet">Bonus: Vim Snippet</h2>
<p>To update the target state automatically when editing the source file in the chezmoi repo, I use this vim snippet (with the <a href="https://fishshell.com/">fish shell</a>):</p>
<pre tabindex="0"><code>autocmd BufWritePost ~/.local/share/chezmoi/* ! chezmoi apply --source-path %; or for f in (rg -l &#39;template &#34;%:t&#34;&#39;); chezmoi apply --source-path $f; end
</code></pre><div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>You should store this source repository in a git repository to easily revert changes and share configuration update between various machines.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded></item><item><title>How I Got Started with NeoVim’s Lua Configuration</title><link>https://cj.rs/blog/my-setup/nvim-0-5/</link><pubDate>Sun, 18 Jul 2021 22:57:01 +0100</pubDate><guid>https://cj.rs/blog/my-setup/nvim-0-5/</guid><description>&lt;p&gt;Four months ago I was still using &lt;a href="https://spacevim.org/"&gt;SpaceVim&lt;/a&gt; when I stumbled upon a &lt;a href="https://oroques.dev/notes/neovim-init/"&gt;blog post&lt;/a&gt; on how to configure NeoVim with Lua. I then started to create my own configuration. In this post I’ll share the learnings acquired in the process. I hope you will find this useful to create your own configuration!&lt;/p&gt;
&lt;h2 id="why-create-your-own-vim-config-from-scratch"&gt;Why create your own Vim config from scratch?&lt;/h2&gt;
&lt;p&gt;Vim has been my daily driver for about ten years. Almost from the beginning, I used Vim distributions for ease of configuration. &lt;a href="https://vim.spf13.com"&gt;Spf13 vim&lt;/a&gt; first and then &lt;a href="https://spacevim.org/"&gt;SpaceVim&lt;/a&gt;. With a distribution, one gets a lot of bells and whistle without spending too much time configuring things. So why spend hours setting up NeoVim from scratch?&lt;/p&gt;</description><content:encoded><![CDATA[<p>Four months ago I was still using <a href="https://spacevim.org/">SpaceVim</a> when I stumbled upon a <a href="https://oroques.dev/notes/neovim-init/">blog post</a> on how to configure NeoVim with Lua. I then started to create my own configuration. In this post I’ll share the learnings acquired in the process. I hope you will find this useful to create your own configuration!</p>
<h2 id="why-create-your-own-vim-config-from-scratch">Why create your own Vim config from scratch?</h2>
<p>Vim has been my daily driver for about ten years. Almost from the beginning, I used Vim distributions for ease of configuration. <a href="https://vim.spf13.com">Spf13 vim</a> first and then <a href="https://spacevim.org/">SpaceVim</a>. With a distribution, one gets a lot of bells and whistle without spending too much time configuring things. So why spend hours setting up NeoVim from scratch?</p>
<p>SpaceVim does provide a lot of options and plugins so that everyone can find the functionalities they need and discover some new useful tricks. This ends up creating long key mappings like <code>&lt;space&gt;ff</code> and leads to long startup time. For instance on my machine with an SSD drive, it needs between 1 and 2 seconds to start. This is a common problem with distributions.</p>
<p>The long startup time issue can be mitigated by starting Vim less often or by choosing a lighter Vim distribution. One could even reuse only the core and some parts of a distribution, leaving out the rest. Regarding the long key mappings issue, shorter ones could be redefined. However, this has two major drawbacks:</p>
<ul>
<li>your customized configuration lies on the moving foundations of the underlying distributions,</li>
<li>debugging is made more difficult because of the incorporation of so much code you haven’t written and don’t know well.</li>
</ul>
<p>To solve all these problems, I found it easier and less time-consuming to have my own configuration. Additional benefits include a better recall of what exists and what functionalities are implemented<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>. The good news with NeoVim 0.5 is that you can now use Lua and not an arcane language like VimScript<sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup>. The result is also quite fast: with my configuration NeoVim starts in 100 to 110 <em>milliseconds</em>.</p>
<p>Starting your own configuration does not mean you can’t draw inspiration from other configurations! The next sections of this post reference guides, snippets and plugins I’ve found useful, so that you can evaluate them for inclusion into your own file.</p>
<h2 id="enjoy-the-ride">Enjoy the Ride!</h2>
<p>To tailor my experience to my liking, I tried my changes in a new instance of NeoVim after every addition of a plugin or of a set of mappings. Mappings in particular sometime looks good on the screen, but fingers don’t like it that much 😀.</p>
<p>In addition, NeoVim configuration can be notoriously complicated to debug. To quote the documentation:</p>




  <figure>
    <blockquote cite="https://neovim.io/doc/user/starting.html#bisect">
      <p>To find the cause of a problem in your config, you must &ldquo;bisect&rdquo; it.</p>

    </blockquote>
    
      <figcaption class="blockquote-caption">
        
          <cite style="text-align: right"><a href="https://neovim.io/doc/user/starting.html#bisect">https://neovim.io/doc/user/starting.html#bisect</a></cite>
          <br/>
        
        
      </figcaption>
    
  </figure>



<p>For this the previous point about regular testing helps, but I would advise for versioning your configuration, for instance with <a href="/blog/my-setup/chezmoi/">git and chezmoi</a>. With regular commits, you will be able to rely on the git bisect feature when things go wrong.</p>
<h2 id="guides">Guides</h2>
<p>Detailed guidance exists online to get started with your configuration. I got started with <a href="https://oroques.dev/notes/neovim-init/">a mostly one file Lua configuration</a>. This guide contains general explainations on where to put your Lua files, the reasoning behind the changes… If you are not familiar with NeoVim Lua configuration tricks, I strongly recommend reading the above link. See you in a bit 👋.</p>
<p>In addition, these links may prove useful:</p>
<ul>
<li><a href="https://github.com/mjlbach/defaults.nvim/blob/master/init.lua">Example <code>init.lua</code></a></li>
<li><a href="https://emilienl.medium.com/a-quick-guide-to-set-up-nvim-built-in-lsp-419bb6e91c0a">A quick guide to set up nvim built in LSP</a></li>
<li><a href="https://neovim.io/doc/lua-resources/">NeoVim’s Lua Resources</a></li>
</ul>
<h2 id="snippets-from-my-configuration">Snippets from my Configuration</h2>
<p>This section assumes basic knowledge of Lua configuration.</p>
<h3 id="mapping-hints">Mapping Hints</h3>
<figure>
    <img loading="lazy" src="../which-key-space.png"/> <figcaption>
            Pop up window showing the keys that can follow &lt;space&gt;
        </figcaption>
</figure>

<p><a href="https://github.com/folke/which-key.nvim">Which-Key</a> is a brilliant plugin to display a popup with the possible mappings as you press the keys of the shortcut. For instance, I have mapped <code>&lt;space&gt;j</code> to <code>:tabnew</code>, to open a new tab. On the figure above, I’ve just typed <code>&lt;space&gt;</code> (abbreviated <code>SPC</code>) and the keys that could be pressed then are displayed in a popup at the bottom of the screen.
What sets <code>which-key.nvim</code> apart is that you don’t have to configuration your mappings using a special function for it to work. It discovers most of your mappings right away and use them to populate the popup.</p>
<p>I’ve tweaked <code>timeoutlen</code> to get the popup more quickly. I’ve also changed labels for some keys to have shorter or more explicit names, like <code>SPC</code> for <code>&lt;space&gt;</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-lua" data-lang="lua"><span style="display:flex;"><span><span style="color:#c678dd">local</span> <span style="color:#e06c75">wk</span> <span style="color:#56b6c2">=</span> <span style="color:#e06c75">require</span>(<span style="color:#98c379">&#34;which-key&#34;</span>)
</span></span><span style="display:flex;"><span><span style="color:#e06c75">wk.setup</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#e06c75">key_labels</span> <span style="color:#56b6c2">=</span> {
</span></span><span style="display:flex;"><span>    [<span style="color:#98c379">&#34;&lt;space&gt;&#34;</span>] <span style="color:#56b6c2">=</span> <span style="color:#98c379">&#34;SPC&#34;</span>,
</span></span><span style="display:flex;"><span>    [<span style="color:#98c379">&#34;&lt;CR&gt;&#34;</span>] <span style="color:#56b6c2">=</span> <span style="color:#98c379">&#34;RET&#34;</span>,
</span></span><span style="display:flex;"><span>    [<span style="color:#98c379">&#34;&lt;tab&gt;&#34;</span>] <span style="color:#56b6c2">=</span> <span style="color:#98c379">&#34;TAB&#34;</span>,
</span></span><span style="display:flex;"><span>  },
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span><span style="color:#e06c75">vim.opt</span>.<span style="color:#e06c75">timeoutlen</span> <span style="color:#56b6c2">=</span> <span style="color:#d19a66">900</span>
</span></span></code></pre></div><h4 id="mapping-choices">Mapping Choices</h4>
<p>My custom mappings are mainly around the <code>&lt;space&gt;</code> key, often with only one key following, like <code>&lt;space&gt;s</code> to write the current file. The <code>&lt;Leader&gt;</code> key is mostly left for plugins, while the <code>&lt;LocalLeader&gt;</code> is sometimes used for some buffer local mappings.</p>
<p>In general, my mappings are heavily adapted to the <a href="https://bepo.fr">BÉPO layout</a>, a Dvorak-like keyboard for French.</p>
<h3 id="clever-f">Clever-F</h3>
<p><a href="https://github.com/rhysd/clever-f.vim">rhysd/clever-f.vim</a> extends <code>f</code>, <code>t</code>… so that:</p>
<ol>
<li>When you press <code>fc</code>, all characters <code>c</code> in the current line get highlighted</li>
<li>Another press on <code>f</code> jumps to the next occurence of <code>c</code></li>
<li>A press on <code>F</code> jumps backward</li>
</ol>
<p>This makes <code>,</code> and <code>;</code> redondant and these can be remapped.</p>
<h4 id="leaders">Leaders</h4>
<p>The universal leader is by default mapped on <code>\</code>. However, it is frequently remapped to <code>,</code>, which is easier to reach. Since clever-f freed two mappings, I reuse them like so:</p>
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-lua" data-lang="lua"><span style="display:flex;"><span><span style="color:#e06c75">g.mapleader</span> <span style="color:#56b6c2">=</span> <span style="color:#98c379">&#34;,&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#e06c75">g.maplocalleader</span> <span style="color:#56b6c2">=</span> <span style="color:#98c379">&#34;;&#34;</span>
</span></span></code></pre></div><h3 id="buffer-jump">Buffer Jump</h3>
<p>With the awesome <a href="https://github.com/phaazon/hop.nvim">hop.nvim</a>, one can get hints to jump to various parts of a buffer (see the figure below if that does not make sense just yet). It is similiar to EasyMotions and supports jumps by line, word, characters sequences and pattern. However, in my opinion this plugin is not replacement for <code>w</code> and the like, because for short movements I find <code>w</code> or <code>f</code> shorter to type and because the need to read the screen for caracters may be quite slow compared to <code>3w</code>. It is also not a replacement for <code>/</code> because hop.nvim highlights whats visible on the current buffer. Thus it fills the void left for medium range move.</p>
<figure>
    <img loading="lazy" src="../hop-nvim-word.png"
         alt="I invoqued HopWord from line 105 and if I press dr, I’ll jump to the last word of line 116"/> <figcaption>
            Word jump example with hop.nvim<p>I invoqued <code>HopWord</code> from line 105 and if I press <code>dr</code>, I’ll jump to the last word of line 116</p>
        </figcaption>
</figure>

<p>Here is my configuration for this plugin:</p>
<div class="highlight"><pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-lua" data-lang="lua"><span style="display:flex;"><span><span style="color:#e06c75">map</span>(<span style="color:#98c379">&#39;n&#39;</span>, <span style="color:#98c379">&#39;T&#39;</span>, <span style="color:#98c379">&#39;&lt;cmd&gt;HopLineStart&lt;CR&gt;&#39;</span>)
</span></span><span style="display:flex;"><span><span style="color:#e06c75">map</span>(<span style="color:#98c379">&#39;v&#39;</span>, <span style="color:#98c379">&#39;T&#39;</span>, <span style="color:#98c379">&#39;&lt;cmd&gt;HopLineStart&lt;CR&gt;&#39;</span>)
</span></span><span style="display:flex;"><span><span style="color:#e06c75">map</span>(<span style="color:#98c379">&#39;n&#39;</span>, <span style="color:#98c379">&#39;S&#39;</span>, <span style="color:#98c379">&#39;&lt;cmd&gt;HopWord&lt;CR&gt;&#39;</span>)
</span></span><span style="display:flex;"><span><span style="color:#e06c75">map</span>(<span style="color:#98c379">&#39;v&#39;</span>, <span style="color:#98c379">&#39;S&#39;</span>, <span style="color:#98c379">&#39;&lt;cmd&gt;HopWord&lt;CR&gt;&#39;</span>)
</span></span><span style="display:flex;"><span><span style="color:#e06c75">map</span>(<span style="color:#98c379">&#39;n&#39;</span>, <span style="color:#98c379">&#39;è&#39;</span>, <span style="color:#98c379">&#39;&lt;cmd&gt;HopChar2&lt;CR&gt;&#39;</span>)
</span></span><span style="display:flex;"><span><span style="color:#e06c75">map</span>(<span style="color:#98c379">&#39;v&#39;</span>, <span style="color:#98c379">&#39;è&#39;</span>, <span style="color:#98c379">&#39;&lt;cmd&gt;HopChar2&lt;CR&gt;&#39;</span>)
</span></span><span style="display:flex;"><span><span style="color:#e06c75">map</span>(<span style="color:#98c379">&#39;n&#39;</span>, <span style="color:#98c379">&#39;È&#39;</span>, <span style="color:#98c379">&#39;&lt;cmd&gt;HopPattern&lt;CR&gt;&#39;</span>)
</span></span><span style="display:flex;"><span><span style="color:#e06c75">map</span>(<span style="color:#98c379">&#39;v&#39;</span>, <span style="color:#98c379">&#39;È&#39;</span>, <span style="color:#98c379">&#39;&lt;cmd&gt;HopPattern&lt;CR&gt;&#39;</span>)
</span></span><span style="display:flex;"><span><span style="color:#e06c75">require</span>(<span style="color:#98c379">&#39;hop&#39;</span>).<span style="color:#e06c75">setup</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#e06c75">keys</span> <span style="color:#56b6c2">=</span> <span style="color:#98c379">&#39;auietsrncbpovdljyxqghf&#39;</span>, <span style="color:#7f848e">-- Hint keys</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>It is heavily optimized for the the <a href="https://bepo.fr">BÉPO layout</a>, whose <a href="https://en.wikipedia.org/wiki/Touch_typing#Home_row">home row</a> contains the <code>auie</code> keys on the left hand and the <code>tsrn</code> keys on the right hand. Hence the choice to put most mappings on <code>T</code> and <code>S</code>, easily reachable with the right hand and to start the hint keys with <code>auie</code> on the left hand.</p>
<h2 id="plugins">Plugins</h2>
<p>These plugin are often mostly written in Lua, although vim script plugins can be more mature. The Lua-plugin ecosystem is moving really quickly, you may find that other plugins are more suitable in a couple months.</p>
<h3 id="plugins-i-use">Plugins I use</h3>
<h4 id="telescope">Telescope</h4>
<p>I use <a href="https://github.com/nvim-telescope/telescope.nvim">telescope.nvim</a> as a fuzzy finder. It can be slow at times compared to <a href="https://github.com/lotabout/skim.vim">skim</a> or <a href="https://github.com/junegunn/fzf.vim">fzf</a>. However, it is relatively easy to script in Lua, making it easy to tightly integrate with other functions.</p>
<h4 id="completion-nvim">Completion-nvim</h4>
<p>I use <a href="https://github.com/nvim-lua/completion-nvim">nvim-lua/completion-nvim</a> in particular for its chains of completion (several completion sources are chained and sources lower in the chain are used when upper sources don’t have any results). However, <a href="https://github.com/hrsh7th/nvim-compe">nvim-compe</a> may be a better choice if you start fresh.</p>
<h4 id="complete-list">Complete List</h4>
<p>This is a list of plugins I use, roughly ordered by frequency of use.</p>

<details>
  <summary>
    Click to show the list of plugins
  </summary>

<ul>
<li>
<p><a href="https://github.com/savq/paq-nvim">paq-nvim</a> a light package manager written in lua. It supports lazy loading, although it’s easier to do with <a href="https://github.com/wbthomason/packer.nvim">packer.nvim</a></p>
</li>
<li>
<p><a href="https://github.com/folke/which-key.nvim">folke/which-key.nvim</a> a great plugin to dispaly a popup with possible mappings. It also offer a register preview, a bit like <a href="https://github.com/tversteeg/registers.nvim">tversteeg/registers.nvim</a></p>
<ul>
<li><a href="https://github.com/kosayoda/nvim-lightbulb">kosayoda/nvim-lightbulb</a> displays a lightbulb when a code action is available</li>
</ul>
</li>
<li>
<p>Completions &amp; snippets:</p>
<ul>
<li><a href="https://github.com/neovim/nvim-lspconfig/">nvim-lspconfig</a> and <a href="https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md">the guide for LSP Configurations</a> to use with the native LSP client in neovim.</li>
<li><a href="https://github.com/nvim-lua/completion-nvim">nvim-lua/completion-nvim</a> with these additional completion sources.
<ul>
<li><a href="https://github.com/nvim-treesitter/completion-treesitter">nvim-treesitter/completion-treesitter</a></li>
<li><a href="https://github.com/steelsojka/completion-buffers">steelsojka/completion-buffers</a></li>
</ul>
</li>
<li><a href="https://github.com/SirVer/ultisnips">SirVer/ultisnips</a> a well known snippets engine, see also <a href="https://github.com/honza/vim-snippets">honza/vim-snippets</a></li>
</ul>
</li>
<li>
<p>Mostly used with Git:</p>
<ul>
<li><a href="https://github.com/tpope/vim-fugitive">tpope/vim-fugitive</a> the well known git plugin
<ul>
<li><a href="https://github.com/tpope/vim-rhubarb">tpope/vim-rhubarb</a> :GBrowse for github</li>
</ul>
</li>
<li><a href="https://github.com/airblade/vim-gitgutter">airblade/vim-gitgutter</a> to see and manage git changes</li>
<li><a href="https://github.com/rhysd/conflict-marker.vim">rhysd/conflict-marker.vim</a> adds shortcuts to solve merge conflicts</li>
<li><a href="https://github.com/rhysd/committia.vim">rhysd/committia.vim</a> improves editing of commit messages with diff and status</li>
<li><a href="https://github.com/airblade/vim-rooter">airblade/vim-rooter</a> change to a project’s root directory</li>
</ul>
</li>
<li>
<p>Navigation:</p>
<ul>
<li><a href="https://github.com/phaazon/hop.nvim">phaazon/hop.nvim</a> a wonderful plugin that highlights text with short keystrokes to jump around</li>
<li><a href="https://github.com/rhysd/clever-f.vim">rhysd/clever-f.vim</a> &ndash; Better movements, frees “,” and “;” for <a href="#leaders">leaders</a></li>
<li><a href="https://github.com/arp242/jumpy.vim">arp242/jumpy.vim</a> allows to make big and precise jumps for instance from function to function</li>
</ul>
</li>
<li>
<p>Deal with symbols like <code>(</code> <code>[</code> or <code>&lt;</code></p>
<ul>
<li><a href="https://github.com/tpope/vim-surround">tpope/vim-surround</a> the well known plugin to add, change or delete symbols around text.</li>
<li><a href="https://github.com/jiangmiao/auto-pairs">jiangmiao/auto-pairs</a> closes pairs of symbols</li>
</ul>
</li>
<li>
<p><a href="https://github.com/ojroques/nvim-hardline">ojroques/nvim-hardline</a> a light and fast status line</p>
</li>
<li>
<p><a href="https://github.com/nvim-treesitter/nvim-treesitter">nvim-treesitter/nvim-treesitter</a>, one of the new big features of NeoVim 0.5. This is still in an early phase but it can already improve highlighting, refactoring and completions, sometimes with companion plugins like:</p>
<ul>
<li><a href="https://github.com/nvim-treesitter/nvim-treesitter-textobjects">nvim-treesitter/nvim-treesitter-textobjects</a></li>
<li><a href="https://github.com/nvim-treesitter/nvim-treesitter-refactor">nvim-treesitter/nvim-treesitter-refactor</a></li>
<li><a href="https://github.com/nvim-treesitter/playground">nvim-treesitter/playground</a></li>
</ul>
</li>
<li>
<p>Other convenience plugins</p>
<ul>
<li><a href="https://github.com/glepnir/indent-guides.nvim">glepnir/indent-guides.nvim</a> displays indentation guides.</li>
<li><a href="https://github.com/ojroques/nvim-bufdel">ojroques/nvim-bufdel</a> improve the deletion of buffers</li>
<li><a href="https://github.com/ojroques/vim-oscyank">ojroques/vim-oscyank</a> a that works across terminals, even over SSH</li>
<li><a href="https://github.com/winston0410/commented.nvim">winston0410/commented.nvim</a> (un)comment lines. It is the only lua comment plugin I’ve found that supports using <code>3gcc</code> to comment 3 lines,.</li>
<li><a href="https://github.com/dstein64/vim-startuptime">dstein64/vim-startuptime</a> a better interface to vim startup time profiles</li>
<li><a href="https://github.com/norcalli/nvim-colorizer.lua">norcalli/nvim-colorizer.lua</a> a plugin to highlight color codes with the right colors</li>
</ul>
</li>
<li>
<p><a href="https://github.com/nvim-telescope/telescope.nvim">nvim-telescope/telescope.nvim</a> a fuzzy finder with preview. I also use these extensions:</p>
<ul>
<li><a href="https://github.com/nvim-telescope/telescope-symbols.nvim">nvim-telescope/telescope-symbols.nvim</a></li>
<li><a href="https://github.com/fhill2/telescope-ultisnips.nvim">fhill2/telescope-ultisnips.nvim</a></li>
<li><a href="https://github.com/nvim-telescope/telescope-github.nvim">nvim-telescope/telescope-github.nvim</a></li>
</ul>
</li>
<li>
<p><a href="https://github.com/cj-rs/vim-bepo">cj-rs/vim-bepo</a> a customized fork of a plugin to adapt mappings to the <a href="https://bepo.fr/wiki/Accueil">bepo layout</a></p>
</li>
<li>
<p>If you work with more exotic syntaxes:</p>
<ul>
<li><a href="https://github.com/sheerun/vim-polyglot">sheerun/vim-polyglot</a></li>
<li><a href="https://github.com/cstrahan/vim-capnp">cstrahan/vim-capnp</a>

</details>
</li>
</ul>
</li>
</ul>
<h3 id="plugins-i-load-lazily">Plugins I load lazily</h3>
<p>I lazy load less often used plugins, so that they are not loaded at startup by default.</p>
<ul>
<li><a href="https://github.com/romgrk/nvim-treesitter-context">romgrk/nvim-treesitter-context</a> is a bit slow and buggy, but useful sometimes to get the context piled up at the top</li>
<li><a href="https://github.com/mattn/emmet-vim">mattn/emmet-vim</a> CSS abbreviations to generate HTML and other</li>
<li><a href="https://github.com/jbyuki/instant.nvim">jbyuki/instant.nvim</a> for remote pair programming</li>
</ul>
<h3 id="plugins-on-my-radar-for-the-future">Plugins on my Radar for the Future</h3>
<p>Plugins I might use in the future to replace existing pieces or add features:</p>
<ul>
<li><a href="https://github.com/puremourning/vimspector">vimspector</a> a debugger based on the DAP protocol (like LSP, but for debugguers)</li>
<li><a href="https://github.com/glepnir/lspsaga.nvim">lspsaga.nvim</a> a UI for the native LSP client</li>
<li><a href="https://github.com/hrsh7th/nvim-compe">nvim-compe</a> a completion engine with more advanced support for LSP. I quite like the chains in completion-nvim, but maybe nvim-compe could be a better fit at some point</li>
<li><a href="https://github.com/lambdalisue/gina.vim">gina.vim</a> to replace fugitive. It offers faster startup time and asynchronous git operations</li>
</ul>
<h2 id="other-interesting-configurations">Other Interesting Configurations</h2>
<ul>
<li><a href="https://github.com/tjdevries/config_manager/tree/master/xdg_config/nvim">tjdevries</a></li>
<li><a href="https://github.com/ojroques/dotfiles/tree/master/nvim">ojroques</a></li>
</ul>
<h2 id="thanks">Thanks</h2>
<p>Thanks to <a href="https://moverest.xyz">moverest</a> and <a href="https://jguer.space/">J. Guereiro</a> for reviewing drafts of this post.</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>That was my experience at least and that of <a href="https://news.ycombinator.com/item?id=27715513">others</a>&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:2">
<p>Some parts of the NeoVim Lua API are not mature and you end up running some VimScript. But this is mostly true for things like mappings, which are closer to settings toggle than scripts. Even if you really want to define some mappings by scripting, you can mix Lua and VimScript like in <a href="#buffer-jump">buffer jump</a>&#160;<a href="#fnref:2" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded></item></channel></rss>