Search our website

From the blog

Post authors

Currently displaying: Scott Davis

Developer
ugrc social card

Boost Your Productivity With Vim (3 min)

I was surprised to realize today that I have never written about one of my favorite tools that I use to write code. It's something that absolutely transformed my day-to-day coding. If it was suddenly taken away from me I would feel like I had gone back to the dark ages. That's right, I'm talk about Vim. Or more specifically Vim key bindings. Vim (Vi IMproved) [https://en.wikipedia.org/wiki/Vim_(text_editor)] is an old text editor that was first released in the 90's and is an improvement to an even older editor called Vi. The intriguing part of Vim for me was not the 20 year old piece of software but the system that it used to edit and navigate text. It's very efficient, requiring the coder to reach for his or her mouse almost never. Lest you think that I've abandoned my favorite text editor [https://atom.io/], the real power of Vim for me is not the actual software. In fact, I've only opened it up a few times out of curiosity. The power of Vim is the standard that it's set. There are Vim emulator plugins for every major text editor out there including Sublime [https://github.com/guillermooo/Vintageous], Atom [https://github.com/atom/vim-mode] and even online editors such as CodePen [https://blog.codepen.io/2014/02/21/vim-key-bindings/]. This means that if you invest the time into learning Vim commands they will be almost universally applicable across your development tools. Want to quickly go to the end or beginning of the current line? Change everything within the quotes? Delete everything from your cursor to the end of the line? Quickly go to a line number? Change the casing of the selected text? This and much, much, much [https://www.catswhocode.com/blog/130-essential-vim-commands] more can be done with just a few Vim commands. Here are a few of the commands that convinced me that I should learn Vim: * "A" Go to the end of the line and start inserting new text. * "I" Same as "A" but go to the start of the line * "ci"" Delete everything within the quotes and start inserting new text * "C" Delete everything from the cursor to the end of the line and start inserting * "545 gg" Go to line number 545 * "ct," Delete everything until the "," and start inserting new text These are just a few of the commands that I use every day. While it's significant learning curve, the time investment is worth it to me. After all... > Every year, the average Vim user saves over 4 seconds in accumulated time not > having to reach for their mouse… > > — I Am Devloper (@iamdevloper) April 3, 2014 > [https://twitter.com/iamdevloper/status/451792390865833984] There are endless tutorials available for you to learn Vim. After learning just a few of the basics I made it my practice to add one or two new commands to my personal reference [https://www.evernote.com/l/ABdguLm6UtRExY8VU_EZWbfJvRKE6rpjTCM] on a regular basis. After a few weeks you'll wonder how you ever lived without it. There are a few drawbacks that come to mind. Firstly, after a few months of using Vim, your fingers will start automatically typing commands into non-Vim interfaces. This can get annoying. Also, you've probably already realized that the learning curve is pretty steep. If you are not in a code editor on a daily basis then it's probably not worth the investment. But if you're in the mood to boost your productivity and give your poor mouse a break you may want to play some vim golf [https://www.vimgolf.com/] and see how it goes. :)

Developer
ugrc social card

Quick JavaScript Tip: The Arguments Object (2 min)

Recently, as I was slowly working my way through Rebecca Murphy's [https://rmurphey.com/] excellent js-assessment test suite [https://github.com/rmurphey/js-assessment], I ran into a problem that was quite vexing. I was creating a function that was to take an arbitrary number of arguments and combine them with an existing array [https://github.com/rmurphey/js-assessment/blob/master/tests/app/functions.js#L109-119]. I thought that this would be as trivial as using the concat method on the existing array and passing in the arguments object. However, as you can see below, it didn't work. See the Pen Arguments Concat Method [https://codepen.io/stdavis/pen/BPVWdQ/] by Scott Davis (@stdavis [https://codepen.io/stdavis]) on CodePen [https://codepen.io]. For a while I thought that I must be using the concat method incorrectly. I tested it using the terminal again and again with no problems. Finally I recalled a recent issue [https://us6.campaign-archive1.com/?u=2cc20705b76fa66ab84a6634f&id=c8f1074cb2] from A Drip of JavaScript that talked about the arguments object. I remembered that Joshua said that the arguments object "isn't exactly an array, [but rather an] object that acts like an array." This means that you can't use it exactly like an array. An easy fix for the situation was to bind a call to the slice method on an empty array to the arguments object which converts it to a true array object like so: See the Pen Arguments Slice [https://codepen.io/stdavis/pen/xJzqPB/] by Scott Davis (@stdavis [https://codepen.io/stdavis]) on CodePen [https://codepen.io]. Hopefully this will save you some time in the future. Scott [https://twitter.com/SThomasDavis]