We use cookies on our website, hope you don’t mind. Just imagine a plate of delicious meringues, they look like clouds. Read more

Development

How to switch to Vim without ruining your workflow

Share this Article on:

Stay in touch. Subscribe to our Newsletter

I’ve always been looking for ways to improve my coding workflow. Trying different editors and adjusting the configuration in an attempt at finding that sweet spot. I’d wanted to switch to Vim, but I could never find time to grasp it. It was so different from everything I was familiar with.

Vim has a steep learning curve – it’s not a myth. Most editors have a single mode: you put the cursor where you need and start writing. Vim has six of them. Each offers different bindings and is meant to accomplish different things. Vim runs inside a terminal and is deeply integrated with console utilities. To make things harder, it doesn’t even enable mouse support by default. Basic things such as searching for files, moving between tabs or executing global find-replace actions become quite challenging. Here you can see the TypeScript workflow in Vim.

I caved in and gave Vim a chance

‘Why?’ you may ask:

  • People have used Vim for decades. There must be something special in it. I was really impressed when I saw someone using Vim in web development. I wanted to experience the same flow.
  • Shortcuts in editors were hard to remember for me. I’ve always struggled with modifier keys. Should I press Control, Alt, Shift or some combination of them? Vim has different modes for each feature set. Only one mode allows you to write freely into the document. On top of that, most bindings are logically linked to the name of the feature. You can even combine them for more flexibility.
  • I wanted to limit my need for using the mouse when moving the cursor. Since Vim doesn’t have mouse support enabled by default, it must have more powerful options to move around.
  • Many other tools use Vim-like bindings. They are mostly command-line tools, but you can find similar shortcuts in your run-of-the-mill everyday applications (try shift + / in Gmail). For real geeks, I’d recommend Vimperator or Vimium and trying out browsing the internet without a mouse.
  • Vim is fast. At the time, I was using Atom, which had problems handling big files and a large number of selections.

Switch to Vim while keeping your workflow in order

Even though I knew all these perfectly sane reasons, I didn’t switch to Vim right away. I started with something different. In my editor of choice, I looked up a Vim-mode extension. This way, I got the core Vim features in an environment that I was used to. I could focus on mastering the cursor movement without worrying about other things.

It took me a week or so to get used to the Vim way of moving my cursor around. Of course, there were moments of frustration. Mostly when I needed to make some quick edits. Using the mouse was just easier. As time went on, I found ways to move the cursor exactly where I wanted more efficiently. I quickly became faster with the Vim-mode than I have ever been without it.

How to switch to Vim without ruining your workflow
Comparison: standard one-mode editor vs Vim mode (click for full size)

Start with the Vim-mode in your editor

You have to be patient and hungry for knowledge. Try to understand default bindings. Most of the time, they are quite logical. There are multiple ways to do things in Vim – always challenge yourself to find the one that’s most efficient for you. Things will feel weird at the beginning, but after some time, you won’t even notice. It imprints itself into your muscle memory.

Let me give you some extra tips to help you get started:

  1. Remap Caps Lock to Escape. You probably don’t use Caps Lock anyway. In Vim, you will reach for Escape quite often when switching between modes. Caps Lock is much closer to the home row.
  2. Find 30 minutes and go through Vimtutor (you should have it installed by default alongside Vim on Linux and Mac OS). It will teach you the basics.
  3. Install a Vim-mode plugin for your editor of choice. Check the popularity and reviews. Not every plugin is equally useful. Some editors have them built-in, e.g. Sublime Text.
  4. Switch line numbers to be relative (some editors might not support it). It really helps when you start joining Vim commands.
  5. Learn from multiple sources:
    Vim wiki
    Vimcasts for more advanced techniques
    Laracasts (paid) in-depth course

Next steps after mastering the movement

I progressed with cursor movement and basic editing. However, everything else didn’t feel right with me still using non-Vim shortcuts. I was watching more and more Vimcasts and decided to take the plunge. Mostly because of Vim’s plugins. They have been created with Vim in mind. I found them very robust and polished. It took me awhile to get to the point where I was just as efficient as with my previous setup, but I’m very happy that I took the time and effort.

I can’t say that I’ve mastered Vim. I still have some old habits to work on. Sometimes, I have to use applications such as Google Docs. This is when I see how much faster I am with Vim, even when writing this blog post. I don’t have to think about reaching for the mouse and pointing the cursor to a specific position. In Vim, It just takes me a couple of keystrokes to get there.

These are the things that I found the most powerful in Vim:

  • Modes. Most of the time I read, move around, edit or delete things in a document. This applies especially to code. Having modes to do one specialised thing gives you more flexibility.
  • Bindings. They are built around modes. There are a lot of simple one-key shortcuts. In three modes, you can’t write text, so every letter on the keyboard can be assigned to a function. Even simple things like `b` for the beginning of a word, `e` for the end are really helpful.
  • Combinations. `cib`. Change Inside Brackets. `dw`. Delete Word. `viw` Visual Inside Word (select word below cursor). You get the idea.

Wrapping up

Learning Vim is an investment into your productivity. Someone said that it’s like learning to play an instrument. I couldn’t agree more. Things are hard in the beginning. The hardest part is to give it some time. It’s really easy to go back to your comfort zone. Don’t do this, watch other people, find ways to handle repetitive tasks. Use a Vim-mode plugin in your editor of choice to switch to Vim in a familiar environment.

by Adam Florczak, JavaScript Developer
  • Great article! I’m impressed that author describe his experience about VIM in that positive way.
    PS Option “(click for full size)” doesn’t work.

    • Thanks for kind words 🙂 We’ve updated the link and now clicking for full size should work

  • Gurdit Singh Bedi

    Well `d$` you mentioned `which deletes` till the end of the line can be accomplised by `D` only. 🙂

  • Aod Engine

    instead of escape to capslock, try control to capslock and use ctrl (now caps) + [ to escape. way more comfortable!

    • Nice idea and control is closer to home row for other apps as well. I will definitely try it

  • Concatinating two lines is Shift-J, while Ctrl-J just moves cursor downward. 🙂

    • Of course it is 🙂 Thanks for pointing it out. We will soon update the table.

  • “VIm runs in the terminal”, there are graphical versions as well, gvim but also macvim. Personally I prefer ctrl mapped to caps (Or get at keyboard that does that for you like the happy hacking series). I also like the default second esc ctrl-‘. Adding something like Vundler to VIm greatly increases ease of use when it comes to plugins.

    I’ve been using VIm since 1997 and I’m still learning new things 😊 It’s a joy to work with.

  • pjz

    Vimadventures.com is a fun way to get better at some of the basics as well.

  • Kyle Zhu

    `Shift + D` will also delete to the end of the line. Still need to hit 2 keys, but I found it easier than hit `d$`

  • For the browser you can use this extension https://chrome.google.com/webstore/detail/wasavi/dgogifpkoilgiofhhhodbodcfgomelhe?hl=en-US
    “vi editor for any web page : wasavi is a clone of vi editor and extends a TEXTAREA element. ”
    So you don’t lose your vim custom.

  • (Vimcasts creator) Drew Neil’s “Practical Vim” book helped me a lot at the beginning.

you may also like these posts

Behaviours in Xcode: the ultimate guide for iOS developers

Xcode tips and tricks to make your daily work easier

Infrastructure as code 101. Part 1: what, why, how?

SUBSCRIBE TO OUR NEWSLETTER

Get the latest info about technology, design, product management (and some snaps from 10Clouds life) - subscribe to our newsletter.