DEV Community

Cover image for How I Use Vim to Code (Productivity Tips)

How I Use Vim to Code (Productivity Tips)

jones268 profile image jones268 ・2 min read

There’s a lot of good stuff being written about Vim and the way it can help you become a more productive programmer. Here’s my perspective on how Vim has made me a better programmer. ⚡

For those who don’t know, Vim is a powerful text editor that is often used in terminal environments. Since it is primarily designed for typing commands quickly into a shell, the keyboard-only interface can take a little time to learn.

I use vim-mode inside Visual Studio Code and vim inside the terminal for small files. If you want to learn vim try these exercises.

Vim allows me to code everywhere, on any operating system. Regardless of whether it's in an SSH session, in the terminal, on Mac, Windows, Linux or in a mobile phone.

It was one of the best productivity decisions I have ever made and my experience using it has been so positive and fun.

Productivity Tips 🚀

The Why of Better Productivity

Why do I use vim? Well, first off I’d like to talk about productivity and efficiency. I used to be a huge fan of /Sublime Text in the past but that has all changed since I’ve picked up vim. Why? Well, let me just give you a few examples.

Jump to line

Whenever you encounter an error, it shows a line number. For example line 5072. You can press the keys 5072G to immediately jump to the line instead of scrolling endlessly.

With one key press, you can also move to the beginning or end of the file.

Record and replay keystrokes

I use keyboard macros a lot. Vim lets you record and replay your keystrokes. Let's say you want to turn this into an HTML list:

Enter fullscreen mode Exit fullscreen mode

All you need is to record keystrokes qx for one item, and replay them @qx. Even if that is for hundreds of lines. Saves you a lot of typing.

Sure, you don't have to use keyboard macros. But if you have a lot of repetitive work, do you really want to waste your life on that?

typing on keyboard

jumping the cursor

Vim allows you to jump between words. You can quickly navigates the cursor, much faster than pressing the cursor keys x times. With one key press you can move to the beginning or end of the line.

multiple panes

You can view multiple code files in parallel by typing :sp or :vs. This works both in Visual Studio and in the terminal.

You can still use tabs at the same time if you want, but it's makes coding much more efficient 😄

Discussion (1)

moopet profile image
Ben Sinclair

I'm a big fan of Vim and someone who doesn't "get" why Sublime got so popular, but you're doing it a disservice by listing "jump to line" as something Vim's got over it.

Sublime lets you jump to a line with (I think) ctrl+g - that's the standard in most IDEs and text editors.

Incidentally, I prefer using :1234 to jump to a line over 1234G but that's just me :)

Forem Open with the Forem app