<?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: Pradyumna Shembekar</title>
    <description>The latest articles on DEV Community by Pradyumna Shembekar (@pradyumna2905).</description>
    <link>https://dev.to/pradyumna2905</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%2F128943%2F35a0bd79-7fb0-4577-9b24-0bb62acd75a7.jpg</url>
      <title>DEV Community: Pradyumna Shembekar</title>
      <link>https://dev.to/pradyumna2905</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pradyumna2905"/>
    <language>en</language>
    <item>
      <title>Search Ruby Method Declarations in vim</title>
      <dc:creator>Pradyumna Shembekar</dc:creator>
      <pubDate>Mon, 21 Jan 2019 23:03:20 +0000</pubDate>
      <link>https://dev.to/pradyumna2905/search-ruby-method-declarations-in-vim-23fe</link>
      <guid>https://dev.to/pradyumna2905/search-ruby-method-declarations-in-vim-23fe</guid>
      <description>&lt;p&gt;While searching method declarations in vim can be tricky and you can use &lt;code&gt;ctags&lt;/code&gt;, I found that using &lt;code&gt;ag&lt;/code&gt; or &lt;a href="https://github.com/ggreer/the_silver_searcher"&gt;the silver searcher&lt;/a&gt; yields great results.&lt;/p&gt;

&lt;p&gt;I've been an active vim user for almost 3 years now and primarily develop Rails apps. I started using vim because I really liked the idea of having your entire development environment on one screen.&lt;/p&gt;

&lt;p&gt;Run your server, tests, install gems, write code, without leaving or &lt;code&gt;Alt + Tab&lt;/code&gt;'ing out.&lt;/p&gt;

&lt;p&gt;As developers, we occasionally find the need to search for the method declaration. Here are a couple &lt;code&gt;vimscript&lt;/code&gt; functions you can use along with &lt;code&gt;&amp;lt;Leader&amp;gt;&lt;/code&gt; commands to efficiently search for the method declarations and increase productivity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;!&lt;/span&gt; SearchForDeclarationCursor&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; searchTerm &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;expand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;cword&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;call&lt;/span&gt; SearchForDeclaration&lt;span class="p"&gt;(&lt;/span&gt;searchTerm&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;endfunction&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we just expand and capture the word where the cursor is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;!&lt;/span&gt; SearchForDeclaration&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;term&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; definition &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'def '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;a:term&lt;/span&gt;
  &lt;span class="k"&gt;cexpr&lt;/span&gt; &lt;span class="nb"&gt;system&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ag -w '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nb"&gt;shellescape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;definition&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;endfunction&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function prepends the word &lt;code&gt;def&lt;/code&gt; with the search term. This will give you a string like &lt;code&gt;def some_method&lt;/code&gt;. &lt;code&gt;system&lt;/code&gt; function executes any &lt;code&gt;bash&lt;/code&gt; commands provided to it. The &lt;code&gt;-w&lt;/code&gt; option matches the exact search term, thereby giving us accurate results.&lt;/p&gt;

&lt;p&gt;And finally, we can map this to a &lt;code&gt;&amp;lt;Leader&amp;gt;&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;&lt;span class="nb"&gt;map&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;Leader&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;cd&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;call&lt;/span&gt; SearchForDeclarationCursor&lt;span class="p"&gt;()&amp;lt;&lt;/span&gt;CR&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope this helps ya'll!&lt;/p&gt;

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