<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Ruslan&#39;s Tech Blog</title>
    <link>https://blog.bekenev.net/tags/vim.html</link>
    <description>Software development related stuff</description>
    <language>en-us</language>
    <lastBuildDate>Sat, 06 Feb 2021 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://blog.bekenev.net/tags/vim/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Vim Fugitive. :Glog - show a commit author</title>
      <link>https://blog.bekenev.net/2021/02/06/vim-fugitive-glog-format.html</link>
      <pubDate>Sat, 06 Feb 2021 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2021/02/06/vim-fugitive-glog-format.html</guid>
      <description>&lt;h1 id=&#34;tldr&#34;&gt;TL;DR&lt;/h1&gt;&#xA;&lt;p&gt;&lt;code&gt;let g:fugitive_summary_format = &amp;quot;%&amp;lt;(16,trunc)%an || %s&amp;quot;&lt;/code&gt;&lt;/p&gt;&#xA;&lt;h1 id=&#34;the-path-of-figuring-that-line-out&#34;&gt;The path of figuring that line out&lt;/h1&gt;&#xA;&lt;p&gt;Vim-Fugitive is a great package. Recently I started to use :Glog command a lot to look at range of changes added to a branch after git pull.&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;:Glog &amp;lt;hash&amp;gt;..&amp;lt;another hash&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;By default the command only shows a commit hash and its subject.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://blog.bekenev.net/assets/img/vim-fugitive-default-glog.png&#34;&gt;&lt;img alt=&#34;vm screenshot&#34; src=&#34;https://blog.bekenev.net/assets/img/vim-fugitive-default-glog.png&#34; width=&#34;600px&#34;/&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I really wanted to see how can I show a commit author name as well.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;:h fugitive&lt;/code&gt; didn&amp;rsquo;t help much.&lt;/p&gt;&#xA;&lt;p&gt;Inspecting the fugitive&amp;rsquo;s source code I came across not documented &lt;code&gt;g:fugitive_summary_format&lt;/code&gt; variable.&#xA;Initially it wasn&amp;rsquo;t clear how to use it what values I can assign to it but then I noticed that it is assigned with values like &lt;code&gt;%s&lt;/code&gt; or &lt;code&gt;%h %P\t%H&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;These things looks familiar. &lt;code&gt;man git-log&lt;/code&gt; - the place those control symbols can be found at.&#xA;Searching by &amp;ldquo;author&amp;rdquo; gives us &lt;code&gt;%an&lt;/code&gt; that we can use.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s do &lt;code&gt;let g:fugitive_summary_format = &amp;quot;%an&amp;quot;&lt;/code&gt; and see how does it look.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://blog.bekenev.net/assets/img/vim-fugitive-author-only.png&#34;&gt;&lt;img alt=&#34;vm screenshot&#34; src=&#34;https://blog.bekenev.net/assets/img/vim-fugitive-author-only.png&#34; width=&#34;600px&#34;/&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Nice&amp;hellip; no commit message. By searching in &lt;code&gt;man git-log&lt;/code&gt; I found &lt;code&gt;%s&lt;/code&gt; which is a subject (first top line) part of a commit message.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s do &lt;code&gt;let g:fugitive_summary_format = &amp;quot;%an\t%s&amp;quot;&lt;/code&gt;  (separate name and subject with a tab symbol)&lt;/p&gt;&#xA;&lt;p&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://blog.bekenev.net/assets/img/vim-fugitive-author-subject-no-aligned.png&#34;&gt;&lt;img alt=&#34;vm screenshot&#34; src=&#34;https://blog.bekenev.net/assets/img/vim-fugitive-author-subject-no-aligned.png&#34; width=&#34;600px&#34;/&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Better but subject is not vertically aligned so let&amp;rsquo;s keep reading &lt;code&gt;man git-log&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;There is a subject &lt;strong&gt;Placeholders that affect formatting of later placeholders&lt;/strong&gt; where you can find this scary expression - &lt;code&gt;%&amp;lt;(&amp;lt;N&amp;gt;[,trunc|ltrunc|mtrunc])&lt;/code&gt;&lt;br/&gt;&#xA;The definition of this scary thing is - &lt;strong&gt;make the next placeholder take at least N columns, padding spaces on the right if necessary&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Exactly what we need.&#xA;Let&amp;rsquo;s try to use it:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;let g:fugitive_summary_format = &amp;quot;%&amp;lt;(16,trunc)%an || %s&amp;quot;&lt;/code&gt; - here I assume 16 chars in user name is enough for me to recognize an author.&#xA;Adding || too as a separator between author and subject.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://blog.bekenev.net/assets/img/vim-fugitive-author-subject-aligned.png&#34;&gt;&lt;img alt=&#34;vm screenshot&#34; src=&#34;https://blog.bekenev.net/assets/img/vim-fugitive-author-subject-aligned.png&#34; width=&#34;600px&#34;/&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Much better!&lt;/p&gt;&#xA;</description>
    </item>
    <item>
      <title>Vim save file without AutoCmd</title>
      <link>https://blog.bekenev.net/2019/08/08/vim-save-without-autocmd.html</link>
      <pubDate>Thu, 08 Aug 2019 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2019/08/08/vim-save-without-autocmd.html</guid>
      <description>&lt;p&gt;Vim&amp;rsquo;s &lt;strong&gt;autocmd&lt;/strong&gt; is very powerful feature.&lt;/p&gt;&#xA;&lt;p&gt;In my workflow I have many of them including &lt;strong&gt;autocmd&lt;/strong&gt; for &lt;strong&gt;BufWrite&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;There are rare cases when I want to save file and ignore any &lt;strong&gt;autocmd&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;To do this you can just save it by:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;:noa w&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Of course there can be any command after &lt;code&gt;:noa&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Check &lt;code&gt;:h noa&lt;/code&gt; for more details.&lt;/p&gt;&#xA;</description>
    </item>
    <item>
      <title>Vim folding</title>
      <link>https://blog.bekenev.net/2018/12/09/vim-folding.html</link>
      <pubDate>Sun, 09 Dec 2018 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2018/12/09/vim-folding.html</guid>
      <description>&lt;p&gt;Hi,&#xA;I didn&amp;rsquo;t use folding functionality previously at all in any other editors,&#xA;but after I watched &lt;a href=&#34;https://www.youtube.com/watch?v=oqYQ7IeDs0E&#34;&gt;this awesome video&lt;/a&gt; by Greg Hurrell&#xA;I found this Vim feature super useful.&lt;/p&gt;&#xA;&lt;p&gt;So to start getting all benefits from Vim folding just add this to your &lt;code&gt;.vimrc&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-vim&#34; data-lang=&#34;vim&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;set&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;foldmethod&lt;/span&gt;=&lt;span style=&#34;color:#a6e22e&#34;&gt;indent&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;set&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;foldlevelstart&lt;/span&gt;=&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;What these lines do is:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;code&gt;set foldmethod&lt;/code&gt; - setting the folding method. &lt;code&gt;indent&lt;/code&gt; is actually works mostly for all programming&#xA;languages. There are other options though (see &lt;code&gt;:h fold-methods&lt;/code&gt;)&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;code&gt;set foldlevelstart=1&lt;/code&gt; - this is magic line. It kind of force you to use foldings. Using this line&#xA;your files will be folded by default and you have to unfold functions/methods you want to look at.&#xA;Value &lt;code&gt;1&lt;/code&gt; in this case means &amp;ldquo;fold everything and then unfold it back by one level&amp;rdquo;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;So in case you have class defined then this class will be unfolded and fully visible but all&#xA;methods inside will be folded.&lt;/p&gt;&#xA;&lt;p&gt;Here is the example:&lt;/p&gt;&#xA;&lt;center&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://blog.bekenev.net/assets/img/vim-folding.png&#34;&gt;&lt;img alt=&#34;fun first&#34; src=&#34;https://blog.bekenev.net/assets/img/vim-folding.png&#34; width=&#34;100%&#34;/&gt;&lt;/a&gt;&#xA;&lt;small&gt;Please not, in this case I use `set foldlevelstart=2` because class is wrapped in module. &lt;/smalL&gt;&lt;/center&gt;&#xA;&lt;br/&gt;&#xA;&lt;p&gt;Here is keybindings to fold/unfold your code:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;zo&lt;/code&gt; - open folded part&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;zO&lt;/code&gt; - open folded part with all sub-foldings&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;zc&lt;/code&gt; - fold the code&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;zM&lt;/code&gt; - fold everything&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;zR&lt;/code&gt; - unfold everything&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;zm&lt;/code&gt; - change fold level (fold everything by one step)&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;zr&lt;/code&gt; - unfold everything (unfold by one step)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Folding mechanism is great in Vim, and actually in every other editors, but I never used it&#xA;mostly because I&amp;rsquo;m too lazy to fold the code.&#xA;Since Vim does it for me (&lt;code&gt;set foldlevelstart=1&lt;/code&gt;) I always have something folded and it&amp;rsquo;s easy&#xA;to always remember and use this feature.&lt;/p&gt;&#xA;&lt;p&gt;Try it!&lt;/p&gt;&#xA;</description>
    </item>
    <item>
      <title>Vim, dumb-jump</title>
      <link>https://blog.bekenev.net/2018/12/02/vim-dumb-jump.html</link>
      <pubDate>Sun, 02 Dec 2018 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2018/12/02/vim-dumb-jump.html</guid>
      <description>&lt;p&gt;hi everyone,&lt;/p&gt;&#xA;&lt;p&gt;I&amp;rsquo;m currently using Vim in my day to day work, and if you don&amp;rsquo;t know I migrated from&#xA;another perfect editor called Emacs.&lt;/p&gt;&#xA;&lt;p&gt;It was pretty easy to migrate since I used evil-mode in Emacs but the only library/plugin&#xA;I miss is &lt;a href=&#34;https://github.com/jacktasia/dumb-jump&#34;&gt;dumb-jump&lt;/a&gt; which is brilliant because&#xA;allows you to jump to definition without any CTAGS/GTAGS.&lt;/p&gt;&#xA;&lt;p&gt;There is brilliant guy &lt;a href=&#34;https://github.com/bounceme&#34;&gt;Chris Paul&lt;/a&gt; who made &lt;code&gt;dim-jump&lt;/code&gt; plugin which does the same as &lt;code&gt;dumb-jump&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Moreover the plugin is using &lt;code&gt;dumb-jump&lt;/code&gt; rules and download them at the first usage of the plugin.&lt;/p&gt;&#xA;&lt;p&gt;Just add&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Plug &amp;#34;bounceme/dim-jump&amp;#34;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;to your &lt;code&gt;.vimrc&lt;/code&gt;/&lt;code&gt;init.vim&lt;/code&gt; and have fun.&lt;/p&gt;&#xA;&lt;p&gt;The plugin currently just jumps to the first most relevant definition found which is not always correct for me.&lt;/p&gt;&#xA;&lt;p&gt;In case you need a fixed version which shows you all possible founds add my fork to you &lt;code&gt;.vimrc&lt;/code&gt;/&lt;code&gt;init.vim&lt;/code&gt; file:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Plug &amp;#39;KryDos/dim-jump&amp;#39;, { &amp;#39;branch&amp;#39;: &amp;#39;krydos-adaptation&amp;#39; }&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I&amp;rsquo;ll update this post as soon as my changes will be accepted by Chris,&#xA;otherwise choose between these two versions of plugin depending on your needs.&lt;/p&gt;&#xA;</description>
    </item>
    <item>
      <title>Vim, project specific settings</title>
      <link>https://blog.bekenev.net/2018/11/20/vim-project-specific-settings.html</link>
      <pubDate>Tue, 20 Nov 2018 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2018/11/20/vim-project-specific-settings.html</guid>
      <description>&lt;p&gt;Hey,&#xA;I&amp;rsquo;ve just been looking for a good plugin that can help me to configure some VIM variables per project.&lt;/p&gt;&#xA;&lt;p&gt;For example I want &lt;code&gt;set shiftwidth=2&lt;/code&gt; for my JavaScript project and &lt;code&gt;set shiftwidth=4&lt;/code&gt; for PHP one.&lt;/p&gt;&#xA;&lt;p&gt;Turned out no plugin needed.&lt;/p&gt;&#xA;&lt;p&gt;Just put this to your &lt;code&gt;.vimrc&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-vim&#34; data-lang=&#34;vim&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;silent&lt;/span&gt;! &lt;span style=&#34;color:#a6e22e&#34;&gt;so&lt;/span&gt; .&lt;span style=&#34;color:#a6e22e&#34;&gt;vimlocal&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now if you put &lt;code&gt;.vimlocal&lt;/code&gt; file to your project root, it will be sourced and &amp;ldquo;executed&amp;rdquo;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;silent!&lt;/code&gt; is using to supress warnings when there is no .vimlocal file in a directory.&lt;/p&gt;&#xA;</description>
    </item>
    <item>
      <title>vim-easygrep</title>
      <link>https://blog.bekenev.net/2018/08/31/vim-easygrep.html</link>
      <pubDate>Fri, 31 Aug 2018 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2018/08/31/vim-easygrep.html</guid>
      <description>&lt;p&gt;I&amp;rsquo;m currently trying to use Vim instead of Emacs and one of important workflow I&amp;rsquo;ve used to&#xA;is grepping things in a project.&lt;/p&gt;&#xA;&lt;p&gt;There are few options:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;use &lt;code&gt;:vimgrep something **/*&lt;/code&gt;. It&amp;rsquo;s pretty long to type so I don&amp;rsquo;t really like it.&lt;/li&gt;&#xA;&lt;li&gt;bind that vimgrep command to a key sequence. Which is better but still not ideal.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://github.com/dkprice/vim-easygrep&#34;&gt;EasyGrep&lt;/a&gt;. The tool I chose.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;My config looks like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-vim&#34; data-lang=&#34;vim&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;g&lt;/span&gt;:&lt;span style=&#34;color:#a6e22e&#34;&gt;EasyGrepCommand&lt;/span&gt;=&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;grep&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;g&lt;/span&gt;:&lt;span style=&#34;color:#a6e22e&#34;&gt;EasyGrepRoot&lt;/span&gt;=&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;repository&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;g&lt;/span&gt;:&lt;span style=&#34;color:#a6e22e&#34;&gt;EasyGrepRecursive&lt;/span&gt; = &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;g&lt;/span&gt;:&lt;span style=&#34;color:#a6e22e&#34;&gt;EasyGrepFilesToExclude&lt;/span&gt; = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;vendor,docker,node_modules&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;By default EasyGrep use &lt;code&gt;vimgrep&lt;/code&gt; which is not able to ignore folders as far as I got.&lt;/p&gt;&#xA;&lt;p&gt;So setting &lt;code&gt;grep&lt;/code&gt; as &lt;code&gt;EasyGrepCommand&lt;/code&gt; makes &lt;code&gt;EasyGrepFilesToExclude&lt;/code&gt; being considered.&lt;/p&gt;&#xA;&lt;p&gt;Setting &lt;code&gt;EasyGrepRoot&lt;/code&gt; to &lt;code&gt;repository&lt;/code&gt; turns EasyGrep to &amp;ldquo;search from project root&amp;rdquo; mode.&lt;/p&gt;&#xA;&lt;p&gt;Now I can just place my cursor to a word I want to search for, press &lt;code&gt;&amp;lt;Leader&amp;gt;vv&lt;/code&gt; and that&amp;rsquo;s it.&lt;/p&gt;&#xA;&lt;p&gt;Works like a charm.&lt;/p&gt;&#xA;</description>
    </item>
  </channel>
</rss>
