{"id":1122,"date":"2024-11-28T13:57:05","date_gmt":"2024-11-28T18:57:05","guid":{"rendered":"https:\/\/wcarss.ca\/log\/?p=1122"},"modified":"2024-11-28T15:26:16","modified_gmt":"2024-11-28T20:26:16","slug":"i-learned-a-little-vim-thing-today","status":"publish","type":"post","link":"https:\/\/wcarss.ca\/log\/2024\/11\/i-learned-a-little-vim-thing-today\/","title":{"rendered":"I learned a little vim thing today"},"content":{"rendered":"\n<p>This is kind of a long ramble about vim, and a little bit about the joy of forgetting and re-learning <em>the basics<\/em>.<\/p>\n\n\n\n<p>I&#8217;ve been using vim regularly for nearly 20 years. I had an Asus 7&#8243; Eee PC back in university and initially, after breaking out of its preinstalled Mandrake or Mandriva or whatever distro it had, I didn&#8217;t have any window management system at all. I was usually ssh&#8217;d into servers for schoolwork, so I had to use something terminal-based, and my style was far more walk around thumb-typing on the tiny keyboard than stopping to fumble complex meta key combos, so I fell for vim hard.<\/p>\n\n\n\n<p>Somewhere a year or two into my vim journey, already an expert at <code>:&lt;line_no&gt;<\/code> (goto line_no) and hjkl-movement, and <code>dd<\/code> (cut a line) and <code>yy<\/code> (yank a line) and <code>3dd<\/code> (cut 3 lines) and <code>g=G<\/code> (go to top of the file, autoindent to the bottom of the file) and complex regex find and replaces like <code>:10,20s\/file:\\(.*\\).[a-z]\\+\/\\1<\/code> (between lines 10 and 20 change patterns like <code>file:hello.tgz<\/code> to <code>hello<\/code>), somewhere in there, I learned about the grammar of vim, e.g. <code>ciw<\/code> for &#8220;<code>change in word<\/code>&#8221; or <code>dt'<\/code> for &#8220;<code>cut til '<\/code>&#8220;, and damn, I have to say, I felt I knew vim pretty good.<\/p>\n\n\n\n<p>About 10 years ago, I started using Sublime Text 2 more frequently for professional work. I&#8217;d never been a big vim plugins guy (of course I had custom syntax colours!) but I wasn&#8217;t up on NERD tree and fzf plugins and goodness knows what else. I had developed the opinion that I liked vim <em>because<\/em> of its spartan, austere simplicity, and the guarantee it&#8217;d be the same no matter where I went.<\/p>\n\n\n\n<p>Yeah, I was one of <em>those<\/em> people.<\/p>\n\n\n\n<p>But Sublime Text 2 had a fuzzy filename search I could open by just typing command-p, and that was a revelation for me at the time. I suddenly saw codebases very, very differently: I only needed to know the gist of the name of the thing I was looking for to find the thing, <em>fast<\/em>. That and <em>multiple cursors<\/em> &#8212; I got even better with multiple cursors than I ever was with vim&#8217;s find and replace. I could slice and dice text like mad! I likely could have got the same things over in vim, too, but the (maybe imagined) barrier of plugin management system hell kept me at bay.<\/p>\n\n\n\n<p>My vim skills languished.<\/p>\n\n\n\n<p>I could still use vim <em>fine<\/em>, but over years, I stopped being anywhere near as comfortable or as fluid as I once had been. I wanted a mouse. I wanted my multiple cursors. I only ever opened vim in SSH sessions or for toy projects with &lt;20 files.<\/p>\n\n\n\n<p>Jump to yesterday: I&#8217;m working on a small game in Godot, editing my gdscript code in Godot&#8217;s built-in editor. I&#8217;m maintaining a TODO list in a text file outside of the editor, so of course I&#8217;m just opening in vim. As I write up lines of todos, I occasionally shuffle them around. To do that, I tend to initiate a visual selection of a few lines by hitting <code>v<\/code> and select across them:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"129\" src=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-1024x129.png\" alt=\"\" class=\"wp-image-1123\" srcset=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-1024x129.png 1024w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-300x38.png 300w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-768x97.png 768w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image.png 1284w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>then I hit <code>d<\/code> to <code>cut<\/code> the lines:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"143\" src=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-1-1024x143.png\" alt=\"\" class=\"wp-image-1124\" srcset=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-1-1024x143.png 1024w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-1-300x42.png 300w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-1-768x107.png 768w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-1.png 1206w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>and <em>wow<\/em> is it annoying how it omits the rest of the line. So I <code>u<\/code> to undo, <code>v<\/code> to re-enter visual selection, and then manually scroll my selection down and <em>alllll<\/em> the way across that last line:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1010\" height=\"164\" src=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-2.png\" alt=\"\" class=\"wp-image-1125\" srcset=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-2.png 1010w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-2-300x49.png 300w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-2-768x125.png 768w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/figure>\n\n\n\n<p>Then I hit <code>d<\/code> again:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"150\" src=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-3-1024x150.png\" alt=\"\" class=\"wp-image-1126\" srcset=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-3-1024x150.png 1024w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-3-300x44.png 300w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-3-768x112.png 768w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-3.png 1026w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>there, that&#8217;s better. Got the whole line cut to move elsewhere.<\/p>\n\n\n\n<p>And I think: Wyatt &#8212; you <em>must<\/em> be doing this wrong. You cannot really believe that in vim you&#8217;re supposed select character by character <em>all the way<\/em> to the end of the line, just to copy+paste a selected block of text in the most common way.<\/p>\n\n\n\n<p>That critical voice was right! A brief search later, I&#8217;ve found at least two good options. Here they are:<\/p>\n\n\n\n<p>First, I could use <code>$<\/code> to pop the selection to the end of the line, which (along with its go-to-start complement, <code>^<\/code>) I almost never use, because almost every time I&#8217;m jumping to the end or start of a line I want to get into insert mode, so I instead use <code>SHIFT+a<\/code> (go to end and enter insert) or <code>SHIFT+i<\/code> (go to beginning and enter insert), then my dumb hands actually hit <code>ESC<\/code> <em>very often<\/em> to get back to command mode when I didn&#8217;t want to insert!<\/p>\n\n\n\n<p>Second, and I think this is even better: using D instead of d will just <em>cut directly to the end of the line<\/em>. So I can be here (at the initial spot I was in, with a visual selection at the start of a line I want to cut):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"129\" src=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-1024x129.png\" alt=\"\" class=\"wp-image-1123\" srcset=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-1024x129.png 1024w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-300x38.png 300w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-768x97.png 768w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image.png 1284w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>and just hit <code>D<\/code> instead of <code>d<\/code>, and then I go straight to here, with the line cut:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1024\" height=\"148\" src=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-4.png\" alt=\"\" class=\"wp-image-1127\" srcset=\"https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-4.png 1024w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-4-300x43.png 300w, https:\/\/wcarss.ca\/log\/wp-content\/uploads\/2024\/11\/image-4-768x111.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>These are very basic things. Tiny facts. I think I likely even knew them at points in the past, but somewhere along the way I forgot how to use them in concert. Maybe I managed to skip right by them in the first place, or all along, and just never the pieces together in this way. Seeing them here, I think: well this is obvious. This is the way I&#8217;m going to do it forever. But who knows? Maybe I&#8217;ve thought that before.<\/p>\n\n\n\n<p>As is often said, learning vim is a lifelong journey. But that&#8217;s not just true in the ways you know it is; it&#8217;s also true in <em>new<\/em> ways, which you only discover as you go along.<\/p>\n\n\n\n<p>&#8212;<\/p>\n\n\n\n<p>As a post script, of course <em>I know<\/em> I could just use the commands <code>3dd<\/code>, (<em>or<\/em> <code>3D<\/code>) to &#8220;<code>cut 3 lines<\/code>&#8221; and get the same result even faster. I even mentioned <code>3dd<\/code> way up above! But I very rarely have a clear &#8220;I want this many lines&#8221; mindset when editing text idly. I tend to start selecting text, and I know what I want when I see it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is kind of a long ramble about vim, and a little bit about the joy of forgetting and re-learning the basics. I&#8217;ve been using vim regularly for nearly 20 years. I had an Asus 7&#8243; Eee PC back in university and initially, after breaking out of its preinstalled Mandrake or Mandriva or whatever distro [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts\/1122"}],"collection":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/comments?post=1122"}],"version-history":[{"count":3,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts\/1122\/revisions"}],"predecessor-version":[{"id":1130,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/posts\/1122\/revisions\/1130"}],"wp:attachment":[{"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/media?parent=1122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/categories?post=1122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wcarss.ca\/log\/wp-json\/wp\/v2\/tags?post=1122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}