2020-08-09-what-is-this-vim-talk-all-about.html (7115B) - raw
1 <!-- title: What is this vim talk all about? --> 2 <!-- slug: what-is-this-vim-talk-all-about --> 3 <!-- categories: FOSS, Miscellany --> 4 <!-- date: 2020-08-09T15:16:00Z --> 5 6 <p> 7 Oh no! Another <a href="https://www.vim.org/">vim</a> post! Well... yes. I have seen a lot of 8 people criticizing vim before even trying it, so I am going to try and explain my history with it 9 and what I like about it. If you aren't aware, vim is a text editor that is normally used from the 10 command line (and, normally, the mouse doesn't work in it or is deactivated).</p> 11 <!-- /p --> 12 13 <h2>Getting into vim</h2> 14 15 <p> 16 When I first saw people that got around a computer with the keyboard, I realized how much faster 17 you can do stuff when you don't use your mouse. By that time, I used the copy/cut/paste shortcuts 18 and that was pretty much it, I didn't even use <code>Alt</code>+<code>Tab</code> to change between 19 windows, so I was mindblown when I saw people moving around so quickly without touching the mouse. 20 For me, the keyboard was simply a tool to write text.</p> 21 <!-- /p --> 22 23 <p> 24 Although I realized that being more familiar with the keyboard would make me more efficient, it 25 was hard to get used to it. I had to think before every keystroke, and everything was very slow. 26 GNU/Linux helped a lot with getting more used to the keyboard, not only did I use a couple more 27 shortcuts, but I also found myself using the terminal often.</p> 28 <!-- /p --> 29 30 <p> 31 At some point, a friend introduced me to vim. I remember<sup id="fnref1"><a href="#fn1">1</a></sup> 32 seeing such a weird program—and in the terminal!—and thinking: why would anyone use that?! I was 33 told that there were a lot of shortcuts, and experienced programmers could move through a file 34 very quickly with it, as well as do complex operations with the file contents. I believed it, but 35 I didn't want to spend years mastering vim, so I kept going with a simpler text editor. A couple 36 of months later, I had a programming class where the teacher would sometimes show us his screen 37 while writing solutions to exercises. He was fast, very fast. He moved around the file very 38 quickly and the craziest part was that he was using Geany. All that speed was reached with 39 <code>Home</code>, <code>End</code>, arrow keys, etc. No <em>real</em> shortcuts. I think that is 40 the point in time when I understood what a program focused on keyboard shortcuts (like vim) had to 41 offer.</p> 42 <!-- /p --> 43 44 <p> 45 Since then, I have tried vim many times and, truth be told, it is hard to start with. I also 46 didn't code a lot during certain times, and when I had to, I just wanted to get stuff done, so 47 finding times to figure out vim wasn't as easy. Another friend recommended using vim when editing 48 Latex files because of a plugin. I was creating Latex documents for some classes so I used vim for 49 a while to edit those files<sup id="fnref2"><a href="#fn2">2</a></sup>. This is how I started to 50 be able to do some things in vim. I eventually started managing servers and used it more and 51 finally, at the start of the confinement, I decided to use it exclusively. It took some time 52 adjusting to it, but I haven't opened any other editor except for a couple of occasions.</p> 53 <!-- /p --> 54 55 <h2>What I like about vim</h2> 56 57 <p> 58 The first thing that I like is that it is a modal editor, meaning it has modes: you are always on 59 one mode, and the editor responds differently to keypresses depending on the mode. The two most 60 basic modes are normal and insert. Insert mode responds to keypresses like you would expect from a 61 text editor: if you press <code>x</code>, an <code>x</code> is appended to the file you are 62 editing, and so on. Normal mode, however, will not print the letter you just typed. For instance, 63 if you press <code>x</code> the letter under the cursor will be deleted, and if you press <code>w</code> 64 the cursor will move to the first character of the next word. This is great because there are a 65 lot of shortcuts on normal mode that are incredibly useful, and let you move around the document 66 without the need of leaving the <a href="https://en.wikipedia.org/wiki/Home_row">home row</a> or 67 pressing modifier keys.</p> 68 <!-- /p --> 69 70 <p> 71 Now, normal mode has a ridiculous amount of shortcuts, each key has some behavior assigned to it, 72 so it can be hard to learn it all. In the end, it is only a matter of practice and it is easier 73 than it looks like. On top of that, these shortcuts act like a language, which makes them really 74 powerful. With that, I mean that shortcuts can be mixed to create new shortcuts. It is hard to 75 explain and there are a lot of explanations online, so I will refer you to two sources, and you 76 can keep investigating if you are interested:</p> 77 <!-- /p --> 78 79 <ul> 80 <li><a href="https://stackoverflow.com/a/1220118">Your problem with Vim is that you don't grok vi</a>: A very detailed Stack Overflow answer.</li> 81 <li><a href="https://www.youtube.com/watch?v=wlR5gYd6um0">Mastering the Vim Language</a>: A YouTube video of a talk in the Boston Vim Meetup of 2015 by Chris Toomey.</li> 82 </ul> 83 84 <p> 85 This is it for me. The fact that you can do so many things with the keyboard without the need to 86 keep <code>Ctrl</code> or <code>Alt</code> pressed and do them in such a natural "language" is 87 what makes vim the best editor I have tried so far. Of course, you can make other editors behave 88 like vim (<a href="https://en.wikipedia.org/wiki/Vi">vi</a> really), but vim is the best one I've 89 tried. Well... I actually use <a href="https://neovim.io/">neovim</a>, but for my use-case, I 90 probably wouldn't be able to tell them apart.</p> 91 <!-- /p --> 92 93 <h2>Final comments</h2> 94 95 <p> 96 There are still a lot of things left for me to learn about vim, especially when dealing with a 97 project with lots of files, but I am now more comfortable with vim than with a normal editor where 98 you move around using the mouse.</p> 99 <!-- /p --> 100 101 <p> 102 As you can see from this post, what I appreciate the most of vim is how it behaves, so I could 103 easily change to another editor that would copy this behavior and add other features. It is useful 104 that it is run on the terminal, as it is normally how I move around the computer, but I don't have 105 anything against other editors. I also want to try <a href="https://www.gnu.org/software/emacs/">Emacs</a> 106 again at some point (with <a href="https://www.emacswiki.org/emacs/Evil">Evil mode</a>, of 107 course), we'll see how that goes!</p> 108 <!-- /p --> 109 110 <!-- footnotes --> 111 <hr /> 112 113 <ol> 114 <li id="fn1"> 115 This is how I remember it, but it was—I think—three years ago, so it might not be completely 116 accurate. <a href="#fnref1" title="Jump back to footnote 1 in the text">↩</a></li> 117 <!-- /li --> 118 <li id="fn2"> 119 The plugin is really nice (especially when writing big amounts of text), but I was so 120 uncomfortable with vim that I would write everything in vim and then edit/review it with a 121 different editor. <a href="#fnref2" title="Jump back to footnote 2 in the text">↩</a> 122 </li> 123 <!-- /li --> 124 </ol>