Erik Ramsgaard Wognsen

Thoughts & technology

Learn Vim the Harder Way, Part II

In a previous post I introduced learning Vim the harder way. To summarize:

  • The easy way: Use the arrow keys for cursor movement
  • The hard way: Don’t use arrow keys; use hjkl in normal mode
  • The harder way: Don’t use hjkl; learn Vim’s multitude of other motion commands

Now, there’s nothing wrong with using the arrow keys per se, but it very often leads to staying in insert mode most of the time and thus missing out on all the stuff you can do from normal mode. As someone wrote about vi/Vim:

your keyboard becomes a huge specialized text-editing gamepad with almost a hundred buttons.

There’s nothing wrong with using hjkl either, in fact they’re very good because they force you to use normal mode as your, well, normal mode. However, normal mode only really provides an advantage if you harness its power and go beyond the basics. For motions, that involves reducing your use of hjkl. In this part we see how to do that for inserting and deleting text.

INSIDE

I don’t game a lot, but after seeing rave reviews, I knew I had to try Playdead’s INSIDE.

And, like many others, I was blown away.

Learn Vim the Harder Way

The first lesson of the official Vim tutorial (“vimtutor”) introduces the navigation keys h, j, k, l. This is where the user might go “What?”, followed perhaps by “What’s wrong with the arrow keys?” The tutorial has this answer: “The cursor keys should also work. But using hjkl you will be able to move around much faster, once you get used to it. Really!”

From here, I think most people continue using Vim with the arrow keys and perhaps mouse because that’s what they’re used to, and why change something that works? Users who actually use hjkl from this point onwards (either by sheer willpower or by disabling the mouse and arrow keys) are learning Vim “the hard way”.

Let me say from the beginning that I agree with the tutorial: Using hjkl is better. But for most people the hard way is not the right way. Learning Vim progressively is more fun and will allow you to switch to Vim while still getting work done. In addition to the official vimtutor, you can also try an interactive tutorial, or even an adventure game.

If, however, you are going for the hard way, let me propose learning Vim the harder way!

Leaving Academia

Last fall, I had been at Aalborg University for nine years: One year in electronic engineering, five years studying software engineering, and three years doing a PhD in computer science. The first six years as a bachelor and master’s student were relatively straightforward and satisfying. The last three years formed my introduction to the academic world.

Being a PhD student in computer science does not mean you are a student of computer science at a high level. Well, you are that, but first and foremost, you are an apprentice of academia. The distinction is important because, while I love computer science, academia is, it turned out for me, not great.

I left the university before having finished my PhD, to work at a private company as an IT consultant. I managed to finish my thesis concurrently with my new job, and I have now defended it successfully. But the last half year has also helped me see more clearly my motivation for switching jobs. It can be summed up like this: Now, I go home from work most days feeling a sense of accomplishment. Before, I came home from work many days with the feeling of having failed.

Entering Dates and Times in Vim

As a young Windows user, I learned that if you write .LOG as the first line of a text file, then each time you open it in Notepad, it appends the current time and date to the file. That was pretty cool. And useful for logging things, as .LOG implies. Later I became a Vim user and started enjoying all the customization I can do to my editor. Or perhaps I became a Vim user because I enjoy customizing! Either way, I like my date and time shortcuts in Vim. For example:

1
noremap! <expr> ,t strftime("%H:%M")

This means: Map the key sequence ,t (comma followed by ’t’) to the result of the expression strftime("%H:%M") in the insert and command line modes. So if I write “The package arrived ,t”, what I will see is “The package arrived 13:43”, or whatever the time was. I use capital T for further precision (seconds), ,d to insert the date (of course in ISO 8601 format), and ,l to insert date and time together (‘l’ for log, as with .LOG):

1
2
3
noremap! <expr> ,T strftime("%H:%M:%S")
noremap! <expr> ,d strftime("%Y-%m-%d")
noremap! <expr> ,l strftime("%Y-%m-%d %H:%M")

Remote Desktop White Screen - Solved

At work, I often connect to Windows servers over Remote Desktop Protocol (RDP). A few times, I have been met with a blank white screen, typically after changing screen resolution in the Remote Desktop Connection options.

The first time this happened I spent a lot of time googling to no avail, so now I will put the solution I found by chance here in case it might help someone else. And note that encountering a blank black screen is a different and more frequent problem, the solutions to which didn’t help me with my white screen in the time that I spent on it.

Solution: Alt-F4

An Alt-F4 was all it took to get rid of the white screen. However, if that does not work, you can also try a Ctrl-Alt-End (the remote desktop equivalent of Ctrl-Alt-Del), and see if you can work anything out from there. Good luck!

Keep Track With a Year at a Glance

The calendar helped me floss (more or less) daily.The calendar helped me floss (more or less) daily.

If you are already starting to forget about your New Year’s resolutions, here’s a tip to keep going: Visualize your progress: Put X’s on a calendar on every day you do what whatever you want to do more of. Stick the calendar on the wall or wherever it would remind you of your goal.

Some years back, each time I visited my dentist, she recommended that I floss. And I would decide that this time I would start doing it. But some days later, I started slipping and forgetting about it. It wasn’t until I put a year-at-a-glance calendar on the bathroom cabinet door that the habit stuck.

Putting a mark on a calendar is not rocket science, but the satisfaction of marking a completed task and of seeing your progress is a mental reward that can make a big difference. If you want to try, I made a one page 2016 calendar you can print (LibreOffice/odt, Word/docx). (It was easily made with the open source ncal utility, invoked as ncal -bh 2016.)

Fun with Declarative Programming

My girlfriend introduced me to Eric Wastl’s Advent of Code, a programming puzzle Advent calendar. The best advent calendar I’ve had in my adult life! (If you’re planning on playing it, this article is one big spoiler for Day 5.) I compare declarative programming puzzle solutions on readability and speed.

Ode to my Casio

The year was 2002 and I had started gymnasium (≈high school). My parents had bought me the graphic calculator required for our maths classes: Casio fx-9750G PLUS. It was white and green and curvy and Casio — not dark and rectangular and from Texas Instruments, as a calculator was expected to be. Soon, however, this happy-looking thing became my companion on my journey into the world of programming.

Checks for Your Django Project

The Django web framework has a management command to check your code for various problems. For example, it checks that your database CharFields define the max_length attribute, and that you have not set DEBUG = True in deployment. This is good for catching various mistakes in using the framework before the problem shows up in production. And for your own business logic, you have unit tests. But there are still many things to not mess up, and they are easy to forget if they are not incredibly easy to check. So I wrote a script to check every problem I could think of in one go.