<?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: Frank Bicknell</title>
    <description>The latest articles on DEV Community by Frank Bicknell (@fbicknel).</description>
    <link>https://dev.to/fbicknel</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%2F242984%2Fb4437235-dd4a-491e-8a01-3f1d94276dee.png</url>
      <title>DEV Community: Frank Bicknell</title>
      <link>https://dev.to/fbicknel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fbicknel"/>
    <language>en</language>
    <item>
      <title>Open Oft-used Files when Starting Vim</title>
      <dc:creator>Frank Bicknell</dc:creator>
      <pubDate>Sat, 24 Aug 2024 16:07:34 +0000</pubDate>
      <link>https://dev.to/fbicknel/open-oft-used-files-when-starting-vim-1lf7</link>
      <guid>https://dev.to/fbicknel/open-oft-used-files-when-starting-vim-1lf7</guid>
      <description>&lt;p&gt;Admit it. You've got some files in your project that you work on often and you're tired of typing their filenames or finding them in a list ... laziness is a virtue.&lt;/p&gt;

&lt;p&gt;So long as your vim session is open, you can &lt;a href="https://dev.to/iggredible/a-faster-vim-workflow-with-buffers-and-args-51kf"&gt;use Vim's buffer system&lt;/a&gt; to access those files quickly and easily. I know my main site playbook is buffer #1 and my inventory is in buffer #3, so &lt;code&gt;:b 1&lt;/code&gt; and I'm there. I don't want to have to resort to even typing a portion of the filename: &lt;code&gt;:b site&amp;lt;tab&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Supreme laziness is a supreme virtue.&lt;/p&gt;

&lt;p&gt;But I might work on something else when I first open the editor. The coveted buffer #1 position is taken by that. Suddenly, my lazy system is ruined and I can't be lazy.&lt;/p&gt;

&lt;p&gt;True, you can only do this for a few files. And fortunately, it's not often you have more files that merit this treatment than you can write on the fingers of one hand.&lt;/p&gt;

&lt;p&gt;There is a solution. Well, as always, there's more than one solution, but I think this one is better than others.&lt;/p&gt;

&lt;p&gt;Especially if you work on more than one project, this solution give you a little laziness system for each of your projects. Assuming, that is, you don't have too many projects.&lt;/p&gt;

&lt;p&gt;The solution is to create a map for each project that opens a handful of files that you commonly work on for that project. Put this map in your &lt;code&gt;.vimrc&lt;/code&gt; and when you've moved to the project directory and opened vim, all your most-used files are open with two keystrokes.&lt;/p&gt;

&lt;p&gt;Here, let me demonstrate:&lt;/p&gt;

&lt;p&gt;Say you have three files in the web project you're working on that you nearly always want to refer to or work on. Those files are &lt;em&gt;index.html&lt;/em&gt;, &lt;em&gt;main_page.html&lt;/em&gt;, and &lt;em&gt;editors_letters.html&lt;/em&gt;. They're in different, insanely complicated and deep directory structures.&lt;/p&gt;

&lt;p&gt;Add this to your &lt;code&gt;.vimrc&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;map &amp;lt;Leader&amp;gt;f :args webpages/index.html content/main_page.html editorial/editors_letters.html&amp;lt;CR&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok, so &lt;code&gt;content/&lt;/code&gt; and &lt;code&gt;webpages/&lt;/code&gt; is not insanely complicated. Admittedly, this example is contrived, but it serves, I think.&lt;/p&gt;

&lt;p&gt;Now when you open vim, of course there are no files and no buffers open. Buffer 1 occupies the first position, but it just says &lt;code&gt;[No Name]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Just hit your leader key (usually this is &lt;code&gt;\&lt;/code&gt;, but you can change that) and &lt;code&gt;f&lt;/code&gt; in quick succession. Just like that all three files are open and if you type &lt;code&gt;:ls&lt;/code&gt;, you can see them all in buffers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:ls
  1 %a   "webpages/index.html"           line 1
  3      "content/main_page.html" line 0
  4      "editorial/editors_letters.html" line 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There remains the mystery of why Vim has skipped buffer #2, but maybe someone who knows better can comment on that.&lt;/p&gt;

&lt;p&gt;Ok, so the extension of this simple trick is equally simple: use a different mapping for each of your different projects. Here's where things break down if you have more than &lt;del&gt;26&lt;/del&gt; 52 projects. Yes, you can also use capital letters. Actually, you can also use numbers and most non-alphanumeric ascii characters in mappings, but I digress. Suffice to say there are a LOT of projects you could represent; likely more than you could remember without sticking Post-It notes all over your monitor to remind you what project &lt;code&gt;&amp;lt;Leader&amp;gt;~&lt;/code&gt; represents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;map &amp;lt;Leader&amp;gt;F :args foodir1/foo.yml bardir1/foo.yml bazdir1/snort.yml&amp;lt;CR&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope this helps you get "started" in all of your projects.&lt;/p&gt;

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