James CookeJames Cooke

Irregular Vim

My frustrations with Vim arise when it makes actions that are unexpected. At Vim London I presented some of my “pet misbehaviours” - these are the ones that affect my regular use of Vim.

Background

If you’re new to Vim then one of the key features of Vim is that it’s a modal editor. As a result, to quote a quote from a previous talk:

The “Zen” of vi is that you’re speaking a language.

So what happens when a language has many irregularities and frequently broken rules? They become hard to learn. For example the English language is hard because:

… although there are rules, there are lots of exceptions to those rules.

My fear is that if Vim is hard to learn it will be overlooked by new users and it will cease to exist in the future. I think we should all be working on the maxim that Drew has put on the Vim London meetup page:

Use Vim better, make Vim better.

Pet misbehaviours

Here are the five behaviours looked at in this talk, each one linked to its section in the slides on Github.

Testing process

Automated and predictable testing is an important part of how I work and so I attempted to use a repeatable process for testing each of the behaviours.

  1. Outline the assumption about Vim. Highlight the docs (where available) that make the statement or assertion.
  2. Do some small tests of this assertion. Does it work as expected? How do we feel about the behaviour?
  3. Update the assertion with any exceptions and look at any reasons for those exceptions.

Learnings

One of my annoyances that started this journey arose when attempting to delete everything up to but not including a character. As you’ll see at the end of the talk, I learned a new movement command t (thanks Audience!).

t is like f but not inclusive. From the help :help t file:

Till before [count]’th occurrence of {char} to the right. The cursor is placed on the character left of {char} inclusive. {char} can be entered like with the f command.

This exactly solves the problem that started my exploration of Vim’s irregularities. It’s a humbling experience when you talk for 20 minutes about Vim commands and still learn a ‘basic’ one at the end of the talk. I think that this is a reminder to me that Vim is deep.

Future

I would like to improve these misbehaviours and make them more regular. My hope is that, if this could be achieved, it would make Vim’s interface even more great and also easier to learn.

The main thing for me going forwards is to use Neovim. A project that is open to improving how Vim works. Here’s a great post about why Neovim is better than Vim - thanks Geoff.

From there I will check out how many of these irregularities can be improved with code changes because having to have a vimrc file that resets Vim to ‘regular’ behaviour by turning off things like octal numerical increments seems horrible and repellent to new users.

We can do better.

Thanks

  • Drew for asking me to talk and providing the cw example.
  • Kris for inspiring me at my first Vim London meetup with Barebones Vim navigation. This showed me so much about Vim that I didn’t know and also that you can do a high quality presentation from Vim. (I hope that one day I’ll be able to meet your standard Kris).

And thanks to you for reading!