<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>sglavoie.com – Tag: Neovim</title><link>https://www.sglavoie.com/tags/neovim/</link><description>Posts and writings by Sébastien Lavoie. Customization setups and articles on productivity for developers who like minimalism.</description><language>en</language><atom:link href="https://www.sglavoie.com/tags/neovim/feed.xml" rel="self" type="application/rss+xml"/><lastBuildDate>Sat, 13 Jul 2019 13:10:00 -0500</lastBuildDate><item><title>Black: A Python Formatter to Brighten Your Workflow</title><link>https://www.sglavoie.com/posts/black-a-python-formatter-to-brighten-your-workflow/</link><description>Meet Black, a superb Python code formatter that will automatically reformat your code in accordance to PEP-8 standards.</description><content:encoded>&lt;hr&gt;
&lt;h2 id="what-is-black"&gt;What is Black?&lt;/h2&gt;
&lt;p&gt;From its &lt;a href="https://github.com/python/black"&gt;GitHub repository&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
 &lt;p&gt;Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.&lt;/p&gt;

&lt;/blockquote&gt;&lt;p&gt;&lt;strong&gt;Black&lt;/strong&gt; will take less than ideal code and will automatically reformat it according to the &lt;a href="https://www.python.org/dev/peps/pep-0008/"&gt;PEP-8 style guide&lt;/a&gt;. It will take care of many things, including the following (taken in that order from &lt;code&gt;README.md&lt;/code&gt; in &lt;strong&gt;Black&lt;/strong&gt;&amp;rsquo;s repo):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Wrapping lines properly by shortening as much as possible single statements;&lt;/li&gt;
&lt;li&gt;Break long lines;&lt;/li&gt;
&lt;li&gt;Remove superfluous empty lines;&lt;/li&gt;
&lt;li&gt;Take care of adding trailing commas where necessary;&lt;/li&gt;
&lt;li&gt;Convert single quotes (&lt;code&gt;'&lt;/code&gt;) to double quotes (&lt;code&gt;&amp;quot;&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;Convert numeric literals to lowercase (&lt;code&gt;0XAB&lt;/code&gt; to &lt;code&gt;0xAB&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;Superfluous parentheses are removed;&lt;/li&gt;
&lt;li&gt;Split call chains on different lines;&lt;/li&gt;
&lt;li&gt;Works from the terminal and support many code editor integrations (Emacs, Vim, VS Code, Sublime, etc.).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now that it&amp;rsquo;s clear &lt;em&gt;why&lt;/em&gt; it can be a good idea to use it, let&amp;rsquo;s see how it works with Vim and the terminal.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="how-to-use-it"&gt;How to use it?&lt;/h2&gt;
&lt;p&gt;First, we need to install it using Python 3.6.0+:&lt;/p&gt;
&lt;div class="code-block" data-prompted&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;bash&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="code-block__prompt"&gt;$ &lt;/span&gt;pip install black&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;That&amp;rsquo;s it!&lt;/p&gt;
&lt;h3 id="use-it-from-the-terminal"&gt;Use it from the terminal&lt;/h3&gt;
&lt;p&gt;In its simplest invocation, we can use &lt;strong&gt;Black&lt;/strong&gt; by specifying a file or a directory by typing:&lt;/p&gt;
&lt;div class="code-block" data-prompted&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;bash&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="code-block__prompt"&gt;$ &lt;/span&gt;black path_to_file_or_directory&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It doesn&amp;rsquo;t come with many options as its goal is to automatically format code consistently, but you can find out more about this tool in the following way:&lt;/p&gt;
&lt;div class="code-block" data-prompted&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;bash&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="code-block__prompt"&gt;$ &lt;/span&gt;black --help&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id="use-it-with-vim"&gt;Use it with Vim&lt;/h3&gt;
&lt;p&gt;Using &lt;strong&gt;Black&lt;/strong&gt; as part of your workflow in a code editor is where I believe it really shines, because you can see almost in real-time when you make a formatting mistake, which will help down the road in committing less sins.&lt;/p&gt;
&lt;p&gt;Integrating &lt;strong&gt;Black&lt;/strong&gt; with Vim or Neovim is quick and painless, adding a simple line in your &lt;code&gt;.vimrc&lt;/code&gt; or &lt;code&gt;init.vim&lt;/code&gt; file. You can also proceed to do a manual installation without a plugin manager as explained in the GitHub repository.&lt;/p&gt;
&lt;p&gt;With &lt;a href="https://github.com/junegunn/vim-plug"&gt;vim-plug&lt;/a&gt;:&lt;/p&gt;
&lt;div class="code-block"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;vim&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-vim" data-lang="vim"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;Plug&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;python/black&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With &lt;a href="https://github.com/VundleVim/Vundle.vim"&gt;Vundle&lt;/a&gt;:&lt;/p&gt;
&lt;div class="code-block"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;vim&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-vim" data-lang="vim"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;Plugin&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;python/black&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Once the plugin is installed, it may well be convenient to automatically format Python files when saving the buffer, which can be accomplished by adding the following line to the configuration file:&lt;/p&gt;
&lt;div class="code-block"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;vim&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-vim" data-lang="vim"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;autocmd&lt;/span&gt; &lt;span class="nx"&gt;BufWritePre&lt;/span&gt; *.&lt;span class="nx"&gt;py&lt;/span&gt; &lt;span class="k"&gt;execute&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;:Black&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;By default, &lt;strong&gt;Black&lt;/strong&gt; works surprisingly well on its own. I only went ahead and changed the default line length from 88 to 79 characters by also adding this line:&lt;/p&gt;
&lt;div class="code-block"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;vim&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-vim" data-lang="vim"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;g&lt;/span&gt;:&lt;span class="nx"&gt;black_linelength&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;79&lt;/span&gt; &lt;span class="c"&gt;&amp;#34; default is 88&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Finally, it&amp;rsquo;s worth noting you can update &lt;strong&gt;Black&lt;/strong&gt; at any point from the terminal with &lt;code&gt;pip&lt;/code&gt; and you can also do it directly from within Vim/Neovim with this command:&lt;/p&gt;
&lt;div class="code-block"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;vim&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-vim" data-lang="vim"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;BlackUpgrade&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Vim will then output something along those lines:&lt;/p&gt;
&lt;blockquote&gt;
 &lt;p&gt;Upgrading Black with pip&amp;hellip;&lt;/p&gt;

&lt;/blockquote&gt;&lt;blockquote&gt;
 &lt;p&gt;DONE! You are all set, thanks for waiting&lt;/p&gt;

&lt;/blockquote&gt;&lt;h2 id="any-example"&gt;Any example?&lt;/h2&gt;
&lt;p&gt;Taking a random Python 3.6+ code sample, we could originally have something like this (hopefully not):&lt;/p&gt;
&lt;div class="code-block"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;python&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data_sources&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;# Retrieve a list of all matching log files in `source`&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;log_files&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;glob&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;glob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;LOG_NAME&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s1"&gt;*&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;log_files&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;]:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s1"&gt;There is no log file to delete in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s1"&gt;.&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;continue&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Log files in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s1"&gt;:&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;log_file&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;log_files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ARGUMENTS&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remind&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="n"&gt;REMINDER_IS_SET&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;log_file&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s1"&gt;Do you want to delete log files &amp;#39;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;for this source? (y/n) &amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_says_yes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;log_file&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;log_files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;log_file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s1"&gt;&amp;#39;Log files deleted.&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;continue&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Exiting script...&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="n"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Running &lt;strong&gt;Black&lt;/strong&gt;, we will get something that&amp;rsquo;s quite a bit more palatable:&lt;/p&gt;
&lt;div class="code-block"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;python&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data_sources&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;# Retrieve a list of all matching log files in `source`&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;log_files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;glob&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;glob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;LOG_NAME&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;*&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;log_files&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;[]:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;There is no log file to delete in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;continue&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Log files in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;:&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;log_file&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;log_files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ARGUMENTS&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;REMINDER_IS_SET&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;log_file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;Do you want to delete log files &amp;#34;&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;for this source? (y/n) &amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user_says_yes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;log_file&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;log_files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;log_file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Log files deleted.&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;continue&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;continue&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Exiting script...&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I think the results speak for themselves: enforcing a style with a tool like &lt;strong&gt;Black&lt;/strong&gt; is definitely useful to avoid arguments about conflicting coding styles. It lets you focus on what matters instead: being productive while providing value to the world.&lt;/p&gt;</content:encoded><dc:creator>Sébastien Lavoie</dc:creator><pubDate>Sat, 13 Jul 2019 13:10:00 -0500</pubDate><guid isPermaLink="false">https://www.sglavoie.com/posts/black-a-python-formatter-to-brighten-your-workflow/</guid><category>workflow</category><category>neovim</category><category>plugin</category><category>productivity</category><category>python</category><category>terminal</category><category>vim</category></item><item><title>Using Embedded Terminals Inside Neovim</title><link>https://www.sglavoie.com/posts/using-embedded-terminals-inside-neovim/</link><description>Because every pixel counts, this neat trick will allow to use terminals inside Neovim and maximize the screen estate for a flawless integration with one of the best text editor available.</description><content:encoded>&lt;hr&gt;
&lt;h2 id="terminals--neovim"&gt;Terminals &amp;amp; Neovim&lt;/h2&gt;
&lt;p&gt;Terminal buffers are a built-in feature of &lt;code&gt;Neovim&lt;/code&gt;. This means that
terminals can be launched inside Neovim just like any other buffer, may
it be a split window, a new tab or an independent buffer. Why is this so
useful? Be prepared to be amazed.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.sglavoie.com/images/posts/0006_using-embedded-terminals-inside-neovim/work_on_article.png"&gt;&lt;img src="https://www.sglavoie.com/images/posts/0006_using-embedded-terminals-inside-neovim/work_on_article.png" alt="embedded-terminal" class="max-size-img-post"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.sglavoie.com/images/posts/0006_using-embedded-terminals-inside-neovim/terminal_buffers.png"&gt;&lt;img src="https://www.sglavoie.com/images/posts/0006_using-embedded-terminals-inside-neovim/terminal_buffers.png" alt="terminal-buffers" class="max-size-img-post"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;(click to open)&lt;/p&gt;
&lt;h3 id="seamless-integration-with-vim-commands"&gt;Seamless integration with Vim commands&lt;/h3&gt;
&lt;p&gt;For a start, terminals are not just &lt;em&gt;opened&lt;/em&gt; inside Neovim: they are
truly integrated. When you type the letter &lt;code&gt;i&lt;/code&gt; in a terminal buffer,
it switches to a new mode, &lt;code&gt;Terminal&lt;/code&gt;, where you have access to all
underlying features of a regular Bash terminal, such as &lt;code&gt;CTRL + r&lt;/code&gt;
to search, tab completion of commands, &lt;code&gt;CTRL + w&lt;/code&gt; to delete a word
backwards or &lt;code&gt;CTRL + u&lt;/code&gt; to delete the whole line backwards.&lt;/p&gt;
&lt;p&gt;When you escape the &lt;code&gt;Terminal&lt;/code&gt; mode, you switch back to &lt;code&gt;Normal&lt;/code&gt; mode,
where all Vim commands are available as usual, such as navigation,
search, etc. Where this gets interesting is when you consider that the
terminal is just like any other buffer (except it&amp;rsquo;s not &lt;em&gt;modifiable&lt;/em&gt;)
and so you can for instance copy its content or paste into it from
different registers. You can split them, view the line number, get
automatic scrolling when output appears in &lt;code&gt;Insert&lt;/code&gt; mode, you can switch
back to &lt;code&gt;Normal&lt;/code&gt; mode at any time even if a command hasn&amp;rsquo;t completed&amp;hellip;
and of course all commands like &lt;code&gt;gt&lt;/code&gt; to &lt;strong&gt;g&lt;/strong&gt;o to another &lt;strong&gt;t&lt;/strong&gt;ab work
as always.&lt;/p&gt;
&lt;h3 id="terminals-get-supercharged-with-the-power-of-vim"&gt;Terminals get supercharged with the power of Vim&lt;/h3&gt;
&lt;p&gt;This is getting exciting (at least for me). Now, having a terminal with
more power is useful in many cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A whole terminal session can be saved to another file easily by
copying the desired range (&lt;code&gt;:%y&lt;/code&gt; to copy everything, for example).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Instead of having to scroll with the mouse, all Vim commands are
available to search and navigate through the buffer: &lt;code&gt;gg&lt;/code&gt; to go to the
beginning of the session, &lt;code&gt;G&lt;/code&gt; to go to the end, &lt;code&gt;12G&lt;/code&gt; to go to line
number &lt;strong&gt;12&lt;/strong&gt;, &lt;code&gt;/&lt;/code&gt; or &lt;code&gt;?&lt;/code&gt; to search forward and backward respectively.
You can even set local or global marks to jump back and forth to precise
lines consistently!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It&amp;rsquo;s even possible to send commands directly to a specific
terminal or set up a REPL to execute any code, either a
selection, a line or a range of lines. I don&amp;rsquo;t personally
use that feature yet, but I see how useful that can be and
you can too if you watch this [screencast presented by Drew
Neil](&lt;a href="https://thoughtbot.com/upcase/videos/neovim-sending-commands-to-a-"&gt;https://thoughtbot.com/upcase/videos/neovim-sending-commands-to-a-&lt;/a&gt;
terminal-buffer) on
&lt;a href="https://thoughtbot.com"&gt;thoughtbot.com&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the terminal is opened in &lt;code&gt;Normal&lt;/code&gt; mode, the cursor and the current
position are kept intact even though new output could appear, such as
would be the case if you are running a server in the background or
waiting for a system update to finish. This is especially nice for
instance if you are trying to debug a web application: you can leave the
cursor exactly where you would like to keep reading the output and never
get lost&amp;hellip; Plus you have the ability to easily move around, search and
copy like a ninja!&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="the-workflow-is-more-compact-and-centralized"&gt;The workflow is more compact and centralized&lt;/h3&gt;
&lt;p&gt;Because the terminals are running with one Neovim instance, you get
everything in the same place, which is usually how you need to access
your work anyway. If for some reasons you need to have multiple
instances of Neovim running, this is possible too and in that situation
you could simply split them into different workspaces.&lt;/p&gt;
&lt;p&gt;Because everything is launched with Neovim, every terminal left open
will also be exited when you close Neovim, shutting down any server
or quitting any background interaction going on in the terminals. I
have found that this behaviour is what I expect pretty much all the
time because the idea of having a terminal inside a working session
of Neovim is to work on something related, so it makes sense to close
everything that&amp;rsquo;s to do with a single project or task when you exit the
text editor. No need for &lt;code&gt;CTRL + d&lt;/code&gt; or &lt;code&gt;exit&lt;/code&gt; anymore!&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="terminal-settings-to-consider"&gt;Terminal settings to consider&lt;/h2&gt;
&lt;p&gt;I don&amp;rsquo;t use many settings or mappings related to terminals, but I guess
the nicest one is to remap the &lt;code&gt;Escape&lt;/code&gt; key because by default, this is
a weird mapping that leads to twisted fingers (&lt;code&gt;&amp;lt;C-\&amp;gt;&amp;lt;C-n&amp;gt;&lt;/code&gt;). Here is
what I currently have in my &lt;code&gt;init.vim&lt;/code&gt; file (the equivalent of &lt;code&gt;.vimrc&lt;/code&gt;
for Neovim):&lt;/p&gt;
&lt;div class="code-block"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__lang"&gt;vim&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-vim" data-lang="vim"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;set&lt;/span&gt; &lt;span class="nx"&gt;termguicolors&lt;/span&gt; &lt;span class="c"&gt;&amp;#34; Make colors look better in terminal&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;&amp;#34; Exit from terminal buffer (Neovim) more easily (remaps Esc key in&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;&amp;#34; terminal)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;tnoremap&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;[&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;\&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;&amp;#34; Open terminal buffer (M stands for the Alt key)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;nnoremap&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;M&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; :&lt;span class="nx"&gt;te&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CR&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;&amp;#34; Switch to terminal buffer automatically (when only one terminal is&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;&amp;#34; open)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;nnoremap&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;M&lt;/span&gt;&lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; :&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="nx"&gt;term&lt;/span&gt;:&lt;span class="sr"&gt;//&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CR&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;&amp;#34; Move between windows exactly the same way as usual&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;tnoremap&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;\&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;tnoremap&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;h&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;\&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;h&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;tnoremap&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;\&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;tnoremap&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;\&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;tnoremap&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;l&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;\&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;C&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;l&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This was a quick overview of a feature that I have neglected for some
time but recently realized how well it integrates with my workflow. You
can find some more information by typing &lt;code&gt;:h terminal&lt;/code&gt;. If you already
use Neovim, it&amp;rsquo;s worth giving it a try! Otherwise, it&amp;rsquo;s worth giving
&lt;a href="https://neovim.io/"&gt;Neovim&lt;/a&gt; a try.&lt;/p&gt;</content:encoded><dc:creator>Sébastien Lavoie</dc:creator><pubDate>Wed, 16 Jan 2019 17:32:00 -0600</pubDate><guid isPermaLink="false">https://www.sglavoie.com/posts/using-embedded-terminals-inside-neovim/</guid><category>tips-and-tricks</category><category>neovim</category><category>productivity</category><category>terminal</category></item><item><title>Using Vimwiki for Note-Taking</title><link>https://www.sglavoie.com/posts/using-vimwiki-for-note-taking/</link><description>This short article explains why Vimwiki felt like the right solution to organize my notes.</description><content:encoded>&lt;hr&gt;
&lt;h2 id="what-is-vimwiki"&gt;What is Vimwiki?&lt;/h2&gt;
&lt;p&gt;From the &lt;a href="https://vimwiki.github.io/"&gt;official website&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
 &lt;p&gt;Vimwiki is a personal wiki for Vim – interlinked, plain text files
written in a markup language.&lt;/p&gt;

&lt;/blockquote&gt;&lt;p&gt;As this relies upon Vim&amp;rsquo;s power to write content in a simple format,
this quickly became a viable option to organize more and more notes!&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="what-were-the-other-options-considered"&gt;What were the other options considered?&lt;/h2&gt;
&lt;p&gt;I have used various approaches in the past for different purposes and
reasons, including &lt;em&gt;Evernote&lt;/em&gt;, &lt;em&gt;Simplenote&lt;/em&gt;, &lt;em&gt;Microsoft OneNote&lt;/em&gt;,
&lt;em&gt;Google Docs&lt;/em&gt;, &lt;em&gt;Boostnote&lt;/em&gt;, &lt;em&gt;Freeplane&lt;/em&gt;/&lt;em&gt;FreeMind&lt;/em&gt; (mind-mapping),
&lt;em&gt;Workflowy&lt;/em&gt; and even plain &lt;code&gt;.txt&lt;/code&gt; files. Each has its pros and cons, but
I then decided to limit my options based on the following self-imposed
requirements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It has to be &lt;strong&gt;available on Linux&lt;/strong&gt;. Right from the start, this would
disqualify many applications such as &lt;em&gt;Notational Velocity&lt;/em&gt;, &lt;em&gt;Bear&lt;/em&gt;,
&lt;em&gt;Quiver&lt;/em&gt;, &lt;em&gt;Paper&lt;/em&gt;, &lt;em&gt;Ulysses&lt;/em&gt; and &lt;em&gt;Squid&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;It has to be &lt;strong&gt;open source&lt;/strong&gt; as this is a philosophy that I strongly
embrace. Plus, having the ability to freely modify it and contribute to
the project is an important additional bonus. Adiós &lt;em&gt;Evernote&lt;/em&gt;, &lt;em&gt;Google
Docs&lt;/em&gt;, &lt;em&gt;Dropbox Paper&lt;/em&gt;, &lt;em&gt;Microsoft OneNote&lt;/em&gt;, &lt;em&gt;Workflowy&lt;/em&gt; and &lt;em&gt;Quip&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;It has to be &lt;strong&gt;fast to use&lt;/strong&gt; and it has to make it possible
to &lt;strong&gt;express oneself in more than one way&lt;/strong&gt;. Say goodbye to
&lt;em&gt;&lt;a href="https://www.freeplane.org"&gt;Freeplane&lt;/a&gt;&lt;/em&gt; (otherwise great for
general brainstorming!) and &lt;em&gt;FreeMind&lt;/em&gt; (which has been abandoned
by its own developers): both are relatively slow on an old machine
because they use Java and it is quite a stretch to use them for
something other than mind maps. In that same category would disappear
&lt;em&gt;&lt;a href="https://www.draw.io/"&gt;draw.io&lt;/a&gt;&lt;/em&gt;, which is fantastic for making
flowcharts and diagrams!&lt;/li&gt;
&lt;li&gt;It has to be versatile enough to handle features such as &lt;strong&gt;including
images, links and attached files&lt;/strong&gt; and have a way to perform &lt;strong&gt;search
and replace&lt;/strong&gt;. Ciao &lt;em&gt;&lt;a href="https://simplenote.com/"&gt;Simplenote&lt;/a&gt;&lt;/em&gt; which
is, well, simple. Even though it doesn&amp;rsquo;t fit the bill in this case,
it remains a great option as it can synchronize your notes with many
different devices (iOS, macOS, Android, Windows and Linux). It has
a feature that allows you to move a slider which acts as a timeline
and shows you a different version of your note since its creation
with the actual date and time down to the minute for each &lt;em&gt;restore
point&lt;/em&gt;. You can also use tags and Markdown and it has options to
share and collaborate with others. Highly recommended!&lt;/li&gt;
&lt;li&gt;It should have a hefty user base to back it up. This would exclude
text editor plugins such as &lt;code&gt;atom-notes&lt;/code&gt; for &lt;em&gt;Atom&lt;/em&gt; or &lt;code&gt;VSNotes&lt;/code&gt; for &lt;em&gt;VS
Code&lt;/em&gt;, which also lack features for accomplishing all of the above.&lt;/li&gt;
&lt;li&gt;On top of everything else, it has to be &lt;strong&gt;available offline&lt;/strong&gt;, in a
&lt;strong&gt;portable and readable format&lt;/strong&gt;. Now, after discarding most options, we
are left with &lt;em&gt;Boostnote&lt;/em&gt; which uses CoffeeScript-Object-Notation and
&lt;em&gt;Vimwiki&lt;/em&gt; which has its own Wiki syntax that&amp;rsquo;s similar in many ways to
Markdown*. Those are the strongest contenders that I could think of but
of course, if you would like to share your recommendations, please do so
in the comments below!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;* &lt;sub&gt;I somehow discredited
&lt;strong&gt;&lt;a href="https://www.gnu.org/software/emacs"&gt;Emacs&lt;/a&gt;&lt;/strong&gt; simply because I started
to learn Vim first and since I&amp;rsquo;m still far from understanding all of
its features, I had to postpone the discovery of Emacs.&lt;/sub&gt;&lt;/p&gt;
&lt;h3 id="one-feature-rich-alternative-to-vimwiki"&gt;One feature-rich alternative to Vimwiki&lt;/h3&gt;
&lt;p&gt;After settling down on Vimwiki, I later found out about &lt;a
href="https://joplin.cozic.net"&gt;Joplin&lt;/a&gt;, which comes with many great
features and characteristics such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Free &amp;amp; Open Source&lt;/li&gt;
&lt;li&gt;Manages notes and todo lists&lt;/li&gt;
&lt;li&gt;Search across all notes/todos&lt;/li&gt;
&lt;li&gt;Import/Export from/to various formats, including Markdown and even
imports from Evernote&lt;/li&gt;
&lt;li&gt;Support for attachments&lt;/li&gt;
&lt;li&gt;Tags&lt;/li&gt;
&lt;li&gt;Synchronization with multiple providers such as Dropbox, Nextcloud,
OneDrive and even your own private cloud&lt;/li&gt;
&lt;li&gt;Available for Windows, Linux, macOS, Android and iOS&lt;/li&gt;
&lt;li&gt;Web Clipper integration&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This application left me a great first impression to say the least and I
will make sure to stay up to date on its active development, which you
can &lt;a href="https://github.com/laurent22/joplin"&gt;follow on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="why-did-vimwiki-win-in-the-end"&gt;Why did Vimwiki win in the end?&lt;/h2&gt;
&lt;h3 id="in-short"&gt;In short&lt;/h3&gt;
&lt;blockquote&gt;
 &lt;p&gt;The modal nature of Vim makes it very hard to enjoy any other text
editor once you get used to it. The learning curve is quite considerable
and nearly infinite, but this is also why I think it is worth investing
more time to master it as it has proven to be an everlasting piece of
trusty software.&lt;/p&gt;

&lt;/blockquote&gt;&lt;blockquote&gt;
 &lt;p&gt;There is a feature in Boostnote to set the Editor Keymap to &lt;code&gt;vim&lt;/code&gt; so
that you can edit text in a very similar way, but then you miss out on
Vim&amp;rsquo;s &lt;code&gt;Command mode&lt;/code&gt; which adds tremendous extensibility and the ability
to create any mappings you wish on the fly.&lt;/p&gt;

&lt;/blockquote&gt;&lt;hr&gt;
&lt;h4 id="expanded-edition"&gt;Expanded edition&lt;/h4&gt;
&lt;p&gt;Boostnote comes with nice features such as Tags, the ability to set
multiple storage locations for notes, a &lt;code&gt;Preferences&lt;/code&gt; panel to adjust
many options, a feature to add code snippets, real-time preview of
Markdown being edited, etc. Make no mistake: this is a great program.
But there are many Vim features that are hard or impossible to replicate
and everything that you can do in Boostnote can be done in Vim also
(ctags, emmet syntax, plugins for Markdown, etc.).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For starters, the terminal integration is obviously unmatched. In
Vim, &lt;code&gt;CTRL+Z&lt;/code&gt; will &lt;em&gt;stop&lt;/em&gt; Vim and gives you access to the terminal to
do whatever you want to do. From that point, you can simply switch back
to Vim by issuing the command &lt;code&gt;fg&lt;/code&gt;. The terminal integration goes even
further: you can have full access to the terminal inside Vim buffers
since Vim 8.1 and that is a feature that has been available in Neovim
for even longer.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Even though &lt;code&gt;vim&lt;/code&gt; mode can be enabled to edit text, you have to use
the mouse to get many tasks done and the editing window can loose the
focus. On the other hand, Vim is just one single window by default that
you can split however you want, including adding tabs if your heart
tells you to.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You have to open your notes with Boostnote if you want them to be
fully readable out of the box. Vimwiki does almost no processing with
the content of the files so that it is very easy to open them with any
other text editor. On a related note, it is much easier to export many
notes at the same time with Vimwiki. Boostnote does have a few options
to export individual notes (&lt;code&gt;.md&lt;/code&gt;, &lt;code&gt;.txt&lt;/code&gt;, &lt;code&gt;.html&lt;/code&gt; and print), but it is
not as user-friendly with many notes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Vimwiki makes it easy to link notes together and navigate between
them, even within subfolders: highlight text, press &lt;code&gt;Enter&lt;/code&gt; to create a
link and open a new note, write your note and press &lt;code&gt;Backspace&lt;/code&gt; to go
back to where you created the link. That&amp;rsquo;s quick and easy!&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In the end, it is a matter of taste as those programs are indeed very
distinct. Boostnote has a polished interface, is much easier to use and
has many settings easily changed. Vim/Neovim, on the contrary, requires
a lot of initial effort both to understand and to set up according
to your needs, but it does deliver a good dose of productivity&amp;hellip;
Eventually!&lt;/p&gt;
&lt;p&gt;An honorable mention goes to Simplenote, which is a joy to use with
mobile devices and allows for quick synchronization between different
devices across all the supported platforms.&lt;/p&gt;
&lt;p&gt;Where things really get in favor of Vim, you could mention the extensive
help system (command &lt;code&gt;:help&lt;/code&gt;), the use of macros, words and lines
completion, the dot (&lt;code&gt;.&lt;/code&gt;) command, the many registers at your disposal
for different tasks, the impressive amount of plugins available, the
ways in which you can configure mappings, functions&amp;hellip; But that&amp;rsquo;s for a
whole new story!&lt;/p&gt;</content:encoded><dc:creator>Sébastien Lavoie</dc:creator><pubDate>Mon, 03 Dec 2018 13:26:00 -0600</pubDate><guid isPermaLink="false">https://www.sglavoie.com/posts/using-vimwiki-for-note-taking/</guid><category>workflow</category><category>neovim</category><category>note-taking</category><category>productivity</category><category>vim</category><category>vimwiki</category></item><item><title>Tmux Integration with Vim/Neovim — First Steps</title><link>https://www.sglavoie.com/posts/tmux-integration-with-vim-neovim-first-steps/</link><description>This is a short introduction that shows a possible workflow with tmux and Vim/Neovim.</description><content:encoded>&lt;hr&gt;
&lt;h2 id="tmux-integration"&gt;tmux integration&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://github.com/tmux/tmux"&gt;tmux&lt;/a&gt; offers many advantages in the
context of remote access to another machine, but it also shines on a
local setup! Here is how I currently like to set it up.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id="configuration-file"&gt;Configuration file&lt;/h3&gt;
&lt;div class="code-block code-block--titled"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__title"&gt;~/.tmux.conf&lt;/span&gt;
 &lt;span class="code-block__lang"&gt;bash&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight" title="~/.tmux.conf"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# split panes using | and -&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;bind&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; split-window -h
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;bind&lt;/span&gt; - split-window -v
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;unbind &lt;span class="s1"&gt;&amp;#39;&amp;#34;&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;unbind %
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# switch panes using Alt-arrow without prefix&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;bind&lt;/span&gt; -n M-Left &lt;span class="k"&gt;select&lt;/span&gt;-pane -L
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;bind&lt;/span&gt; -n M-Right &lt;span class="k"&gt;select&lt;/span&gt;-pane -R
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;bind&lt;/span&gt; -n M-Up &lt;span class="k"&gt;select&lt;/span&gt;-pane -U
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;bind&lt;/span&gt; -n M-Down &lt;span class="k"&gt;select&lt;/span&gt;-pane -D
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Enable mouse mode (tmux 2.1 and above)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;set&lt;/span&gt; -g mouse on
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;source-file &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;HOME&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/.tmux-themepack/blue.tmuxtheme&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This is all very self-explanatory. &lt;a href="https://github.com/jimeh/tmux-themepack"&gt;Many themes can be found
here&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id="automating-the-launch-of-a-default-session"&gt;Automating the launch of a default session&lt;/h3&gt;
&lt;p&gt;This is a small Bash script that I like to have for automatic set up
of a development environment with tmux and Vim/Neovim. As my current
workflow, I enjoy the following:&lt;/p&gt;
&lt;div class="code-block code-block--titled"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__title"&gt;~/.tmux_default_session.sh&lt;/span&gt;
 &lt;span class="code-block__lang"&gt;bash&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight" title="~/.tmux_default_session.sh"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;#!bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# var for session name (to avoid repeated occurences)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;sn&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;dev
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux new-session -s &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$sn&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; -d
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Create 3 windows&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux new-window -t &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$sn&lt;/span&gt;&lt;span class="s2"&gt;:0&amp;#34;&lt;/span&gt; -n &lt;span class="s2"&gt;&amp;#34;nvim&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux new-window -t &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$sn&lt;/span&gt;&lt;span class="s2"&gt;:9&amp;#34;&lt;/span&gt; -n &lt;span class="s2"&gt;&amp;#34;python&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux new-window -t &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$sn&lt;/span&gt;&lt;span class="s2"&gt;:8&amp;#34;&lt;/span&gt; -n &lt;span class="s2"&gt;&amp;#34;terminal&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Split terminal window vertically, then split the right pane&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# horizontally, then switch to the left pane (identified by `FOCUS IS&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# HERE`).&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# _________________&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# |&amp;gt;_ |&amp;gt;_ |&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# | | |&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# | FOCUS |-------|&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# | IS |&amp;gt;_ |&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# | HERE | |&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# -----------------&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux split-window -h
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux split-window -v
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux &lt;span class="k"&gt;select&lt;/span&gt;-pane -L
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Set up Neovim ready to open files&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux send-keys -t &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$sn&lt;/span&gt;&lt;span class="s2"&gt;:0&amp;#34;&lt;/span&gt; C-z &lt;span class="s1"&gt;&amp;#39;nvim .&amp;#39;&lt;/span&gt; Enter
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Set up alias for IPython and clear the screen when entering IPython&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux send-keys -t &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$sn&lt;/span&gt;&lt;span class="s2"&gt;:9&amp;#34;&lt;/span&gt; C-z &lt;span class="s1"&gt;&amp;#39;ipython&amp;#39;&lt;/span&gt; Enter
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux send-keys -t &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$sn&lt;/span&gt;&lt;span class="s2"&gt;:9&amp;#34;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;clear&amp;#39;&lt;/span&gt; Enter
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Select window #0 and attach to the session&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux &lt;span class="k"&gt;select&lt;/span&gt;-window -t &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$sn&lt;/span&gt;&lt;span class="s2"&gt;:0&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tmux -2 attach-session -t &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$sn&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id="aliases-to-make-use-of"&gt;Aliases to make use of&lt;/h3&gt;
&lt;p&gt;I add the following aliases in &lt;code&gt;~/.bash_aliases&lt;/code&gt; to automate a chunk of
the workflow:&lt;/p&gt;
&lt;div class="code-block code-block--titled"&gt;
 &lt;div class="code-block__bar" data-pagefind-ignore&gt;
 &lt;span class="code-block__title"&gt;~/.bash_aliases&lt;/span&gt;
 &lt;span class="code-block__lang"&gt;bash&lt;/span&gt;
 &lt;button class="code-block__wrap" type="button" aria-pressed="false" hidden&gt;Wrap&lt;/button&gt;
 
 &lt;/div&gt;
 &lt;div class="highlight" title="~/.bash_aliases"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# This will launch tmux with the desired configuration&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;alias&lt;/span&gt; &lt;span class="nv"&gt;dev&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;bash ~/.tmux_default_session.sh&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# This will kill the tmux server if the need arises. By detaching from&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# the tmux session, you simply run this command and can reattach easily&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# to the default session configuration on another project.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;alias&lt;/span&gt; &lt;span class="nv"&gt;kdev&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;pkill tmux&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# If the session has been detached but the tmux server is still running,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# I use the following alias to quickly reattach to the default session&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# named `dev` in that example.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;alias&lt;/span&gt; &lt;span class="nv"&gt;adev&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;tmux attach-session -t dev&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id="tmux-demo"&gt;tmux demo&lt;/h3&gt;
&lt;p&gt;(click to open image)
&lt;a href="https://www.sglavoie.com/images/posts/0001_tmux-integration-with-vim/tmux-demo.gif"&gt;&lt;img src="https://www.sglavoie.com/images/posts/0001_tmux-integration-with-vim/tmux-demo.gif" alt="Animated tmux and Vim integration demo" class="max-size-img-post" width="1366" height="768" loading="lazy" decoding="async"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;The content of this post can be found on
&lt;a href="https://github.com/sglavoie/better-vim-experience#tmux-integration"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;</content:encoded><dc:creator>Sébastien Lavoie</dc:creator><pubDate>Mon, 19 Nov 2018 20:31:00 -0600</pubDate><guid isPermaLink="false">https://www.sglavoie.com/posts/tmux-integration-with-vim-neovim-first-steps/</guid><category>workflow</category><category>neovim</category><category>terminal</category><category>tmux</category><category>vim</category></item></channel></rss>