<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: pianocomposer321</title>
    <description>The latest articles on DEV Community by pianocomposer321 (@pianocomposer321).</description>
    <link>https://dev.to/pianocomposer321</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F336341%2F5e694edb-01fa-4f4d-8aa6-28a2c84cd1d8.png</url>
      <title>DEV Community: pianocomposer321</title>
      <link>https://dev.to/pianocomposer321</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pianocomposer321"/>
    <language>en</language>
    <item>
      <title>I Wrote a Macro That Will Expand Python Imports</title>
      <dc:creator>pianocomposer321</dc:creator>
      <pubDate>Sun, 15 Nov 2020 23:21:46 +0000</pubDate>
      <link>https://dev.to/pianocomposer321/i-wrote-a-macro-that-will-expand-python-imports-mhd</link>
      <guid>https://dev.to/pianocomposer321/i-wrote-a-macro-that-will-expand-python-imports-mhd</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;We've all been there. You just added yet &lt;em&gt;another&lt;/em&gt; item to the list of imports. You passed the 80 character limit long ago, and the list is still growing. Refactoring now would take a lot of effort, but the longer you wait, the worse it will get. You are doomed to be forever trapped in the never-ending downward spiral of your worst python import nightmare.&lt;/p&gt;

&lt;p&gt;Never fear! Vim macros are here!&lt;/p&gt;

&lt;p&gt;That's right. I'm here to tell you that there exists a vim macro that will turn your ugly python import statement that looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;random&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;randint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;randrange&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shuffle&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...into a beautiful piece of idiomatic and readable code that looks a bit more like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;random&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;randint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;randrange&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;shuffle&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The macro
&lt;/h2&gt;

&lt;p&gt;So here it is, folks - the macro you've all been waiting for:&lt;br&gt;
&lt;code&gt;0f,F a()&amp;lt;ESC&amp;gt;lDPa&amp;lt;CR&amp;gt;&amp;lt;ESC&amp;gt;d0kf(a&amp;lt;CR&amp;gt;&amp;lt;ESC&amp;gt;^@q&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Because of the limitations of pasting metacharacters into a web browser, I couldn't paste the actual macro in all of its &lt;code&gt;^M&lt;/code&gt;- and &lt;code&gt;^[&lt;/code&gt;-riddled glory, so be sure that you replace all of the &lt;code&gt;&amp;lt;CR&amp;gt;&lt;/code&gt;s, &lt;code&gt;&amp;lt;ESC&amp;gt;&lt;/code&gt;s, etc. with their respective metacharacters when you paste this into your editor.&lt;/p&gt;

&lt;p&gt;The perceptive among you may have noticed that this macro actually calls another macro at the end. Without that call, the code would end up looking like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;random&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;randint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;randrange&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shuffle&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...which isn't much better than before.&lt;/p&gt;

&lt;p&gt;Here's what that other macro looks like:&lt;br&gt;
&lt;code&gt;f r&amp;lt;CR&amp;gt;@q&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is a recursive macro, so be sure that you either record this macro into register 'q' or replace the &lt;code&gt;@q&lt;/code&gt; in both the macro bodies with the register that you do record it into.&lt;/p&gt;

&lt;p&gt;What this second macro does is it finds the next space, replaces it with a carriage return, and then recurses. This will continue until it hits a line that does not contain a space, which in this case will be the line with the closing parenthesis. So in effect, this does the opposite of &lt;code&gt;&amp;lt;S-j&amp;gt;&lt;/code&gt;, breaking lines at each space.&lt;/p&gt;

&lt;p&gt;For those of you who are still scratching your heads trying to figure out what in the world the macro is doing, here it is broken down into bite-sized pieces:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;0f,F&lt;/code&gt; - Find the first comma and jump back to the previous space. This puts the cursor right in front of the first imported variable.&lt;br&gt;
&lt;code&gt;a()&amp;lt;ESC&amp;gt;&lt;/code&gt; - Pretty self-explainitory. Appends a pair of parentheses.&lt;br&gt;
&lt;code&gt;lDP&lt;/code&gt; - Goes to the right one char and deletes to the end of the line, then pastes it before the cursor. This puts the entire line after the parentheses between them.&lt;br&gt;
&lt;code&gt;a&amp;lt;CR&amp;gt;&amp;lt;ESC&amp;gt;&lt;/code&gt; - Inserts a new line before the closing paren.&lt;br&gt;
&lt;code&gt;d0&lt;/code&gt; - Gets rid of the whitespace added after adding the newline (this macro assumes you have &lt;code&gt;autoindent&lt;/code&gt; enabled).&lt;br&gt;
&lt;code&gt;kf(a&amp;lt;CR&amp;gt;&amp;lt;ESC&amp;gt;&lt;/code&gt; - Goes up one line, jumps to the opening paren, and adds a newline after it.&lt;br&gt;
&lt;code&gt;^@q&lt;/code&gt; - Goes to the first non-whitespace char and executes the 'q' macro&lt;/p&gt;

&lt;p&gt;Here's a GIF of what the macro would look like if you could see it one keypress at a time:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uhwjeG2y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2prisgpy149f1qpfsuyx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uhwjeG2y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2prisgpy149f1qpfsuyx.gif" alt="Macro GIF"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>vim</category>
      <category>macros</category>
    </item>
    <item>
      <title>project-templates.nvim</title>
      <dc:creator>pianocomposer321</dc:creator>
      <pubDate>Sat, 08 Aug 2020 20:15:41 +0000</pubDate>
      <link>https://dev.to/pianocomposer321/project-templates-nvim-3ecg</link>
      <guid>https://dev.to/pianocomposer321/project-templates-nvim-3ecg</guid>
      <description>&lt;p&gt;A Neovim Project Management Plugin &lt;a href="https://github.com/pianocomposer321/project-templates.nvim"&gt;https://github.com/pianocomposer321/project-templates.nvim&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  project-templates.nvim
&lt;/h1&gt;

&lt;p&gt;I made this plugin mainly out of pure frustration. I had been using the extension &lt;a href="https://marketplace.visualstudio.com/items?itemName=cantonios.project-templates"&gt;Project Templates&lt;/a&gt; back when I used VSCode as my IDE, and I had come to rely on it. When I migrated to Neovim, I thought "this extension was sooo helpfull! Clearly there &lt;em&gt;must&lt;/em&gt; be an equivialent for vim, right?" I went searching and searching, but I couldn't find &lt;em&gt;anything&lt;/em&gt;. There were plugins that created templates for individual files, and even multiple related files, like &lt;a href="https://github.com/tomtom/templator_vim"&gt;templator_vim&lt;/a&gt;, but nothing that creates templates for an entire project, that defines the project structure and boilerplate code for each necessary file. In most IDEs, the IDE will take care of these things for you automatically when you start a new project. But with vim, you have to create each individual file and folder yourself. This plugin aims to fix that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p2c27duy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yk2kbknlhofrk5rslsyl.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p2c27duy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yk2kbknlhofrk5rslsyl.gif" alt="demo.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Quick Start
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;You will need neovim compiled with python3 support. To determine whether or not your neovim has python support, type &lt;code&gt;:echo has('python3')&lt;/code&gt; and press enter. If it outputs &lt;code&gt;1&lt;/code&gt;, you have python3 support, otherwise you will need to run the command &lt;code&gt;pip install pynvim&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You will also need to run the command &lt;code&gt;pip install binaryornot&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Add this to your init.vim:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;vim-plug:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Plug 'pianocomposer321/project-templates.nvim', { 'do': ':UpdateRemotePlugins' }&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Vundle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Plugin 'pianocomposer321/project-templates.nvim', { 'do':  ':UpdateRemotePlugins'}&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;etc, etc.&lt;/p&gt;

&lt;p&gt;Then run &lt;code&gt;:PlugInstall&lt;/code&gt; (vim-plug) or &lt;code&gt;:PluginInstall&lt;/code&gt; (Vundle).&lt;/p&gt;

&lt;p&gt;Finally, restart Neovim.&lt;/p&gt;

&lt;h1&gt;
  
  
  Usage
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:LoadTemplate&lt;/code&gt; - Load a template into a new project. The plugin will look for placeholders (e.g. &lt;code&gt;#{PLACEHOLDER}&lt;/code&gt;), and ask for values to replace them in each non-binary file&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:DeleteTemplate&lt;/code&gt; - Delete a template&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:SaveAsTemplate&lt;/code&gt; - Save the current folder and all files and subfolders as a new template&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The plugin will look for templates in ~/.templates. Sample templates can be found at &lt;a href="https://github.com/pianocomposer321/project-template-samples"&gt;https://github.com/pianocomposer321/project-template-samples&lt;/a&gt;. If you want to create your own templates, simply create a new project, add the placeholders you want, and save it in ~/.templates, or use the &lt;code&gt;:SaveAsTemplate&lt;/code&gt; command.&lt;/p&gt;

&lt;h1&gt;
  
  
  Credits
&lt;/h1&gt;

&lt;p&gt;Finder.vim - &lt;a href="https://vim.fandom.com/wiki/Implement_your_own_interactive_finder_without_plugins"&gt;https://vim.fandom.com/wiki/Implement_your_own_interactive_finder_without_plugins&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inspired by &lt;a href="https://github.com/bit101/ProjectMaker"&gt;This&lt;/a&gt; Sublime text plugin and &lt;a href="https://github.com/cantonios/vscode-project-templates"&gt;this&lt;/a&gt; VS Code Extension.&lt;/p&gt;

</description>
      <category>python</category>
      <category>vim</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
