Want to take your Vim game to the next level? From my time using Vim, I’ve learned many neat tips and tricks that have saved me tons of time and headaches while editing with Vim. I’m sharing some of my top tips in this guide so you can incorporate them into your workflow.

1Quickly Moving the Cursor

Vim is designed for efficient navigation without relying on the mouse or arrow keys. Knowing Vim’s cursor movement commands can save you a lot of time and sanity when dealing with large files. Vim provides several ways to move the cursor quickly from moving by characters, words, and paragraphs to jumping to specific locations.

Besides the arrow keys, you may use H (left), J (down), K (up), and L (right) to move by characters. You can also add a number before the character to jump that number of characters. So, pressing 5j will move the cursor by five rows. For moving bigger distances, you have:

Indenting all lines in a file on Vim.

Moreover, if you want to jump to a specific line, type that line number and then useGto go to that line. So if you want to go to line 500, type500Gand press to jump to that line.

2Convert Tabs to Spaces and Spaces to Tabs

A common issue developers and content creators face is inconsistency in indentation. Some teams or projects may prefer tabs for indentation, while others prefer spaces. In Vim, you’re able to convert tabs to spaces and vice versa, depending on the specific requirements of your project.

If you want to convert all spaces back to tabs in an existing file, run these two commands:

Misspelled words highlighted in the text in Vim.

The first command ensures that tabs will be used instead of spaces. The second one enforces converting spaces back into tab characters based on the tabstop setting.

If you prefer spaces and want to convert the tabs in an existing file, then run:

An example of changing the visual selection drection in Vim.

These commands tell Vim about the details of the indentation block when converting tabs to spaces.

3Indent Multiple Lines

Indentation is good practice for keeping your file clean and organized. If you’re working with a language like Python, then correct indentation becomes more crucial. With a single command, you can indent all lines in a file. First, typeggto jump to the first line of the file (that could just be another useful tip.) Then type=Gto indent the lines. So the final command is:

4Highlight Spelling Mistakes

I make a lot of typos and mistakes when typing fast. In modern word processors likeMicrosoft WordandGoogle Docs, you have a spell checker that suggests the correctly spelled word. Vim also has a built-in spell checker. It will highlight the words it thinks have been misspelled. To turn on the spell checker, use this command:

5Change Visual Select Direction

When you’re working in Visual Mode, you may select text by character, line, or block. Once you’ve started selecting text in any direction, you might realize that you need to expand or change the selection in the opposite direction. Instead of exiting the Visual Mode and starting the selection again, you can change the selection direction by pressing the o button.

6Jump to the Matching Bracket

When working on a large codebase, you often need to find the end of a code block. Unless the code is well formatted and indented, that’s difficult. In Vim, you’re able to easily find the beginning or end of a code block by jumping to the matching bracket. Pressing the percent sign (%) does exactly that. If you’re on the opening bracket and press %, you’ll jump to the end bracket and vice versa.

This works for parentheses, curly braces, and square brackets.

A demonstration of jumping between the starting and ending brackets of a code block

7Display Line Numbers

This one is fairly easy. By default, Vim shows no line numbers, only tilde signs. You canturn on line numbers on Vimin different modes. In the absolute line number mode, you see line numbers starting from one to the last line. To set that up, run this command:

In relative number mode, the line that your cursor is on is the zeroth line. The rest of the lines are numbered relative to the line your cursor is on. So, lines above and below your cursor start from one and continue. To enable relative numbering, run:

Text in Vim displayed along with line numbers.

What if you need both? There’s another mode called hybrid mode, where you may use both. By enabling the hybrid mode, the line your cursor is on shows its absolute line number. But the lines above and below show their relative numbers. Enable this mode by running:

8Normal Mode

The :norm command in Vim allows you to run normal mode commands from command-line mode. This is useful for repetitive tasks and batch editing. When you need to apply the same normal mode commands to multiple lines simultaneously, you can do that by writing a single line instead of repeating the same thing for each line.

For example, I want to add a semicolon (;) at the end of a few lines. First, I need to select all the lines. Then run these commands:

Text in Vim displayed in a relative number scheming.

Once I press Enter, all selected lines will have a semicolon at the end.

Similarly, you may insert text, change case, or indent multiple lines at once.

Text in Vim displayed in a hybrid numbering scheming.

9Delete Text in Insert Mode

In traditional text editors, there are many keyboard shortcuts for deleting characters and words. Vim has its own set of shortcuts to quickly delete pieces of text. You can delete characters, words, and whole lines. You can delete either from the backward or forward direction of the cursor. Here are a few useful shortcuts:

10Dynamic Snippets

Snippets are like pre-defined pieces of text that you can quickly insert to speed up workflow. Instead of repeatedly typing the same boilerplate code or text, you can use snippets to quickly expand into a longer text block, saving time and reducing typos. Dynamic snippets take this a step further by allowing snippets to include dynamic content, such as the current time, date, or other variable information.

Using plugins likeUltiSnipsorvim-snippets, you can define dynamic snippets that adjust based on the current context. For example, let’s create a snippet to expand ‘jd’ into John Doe. If you’re using UltiSnips, add the following to your UltiSnips file (usually ~/.vim/UltiSnips/snippet_file_name.snippets:)

A demonstration of appending a semicolon to multiple lines in Vim’s normal mode.

For dynamic snippets like time and date, you’re able to format it like this:

Now, if you type ‘time’ and press the Tab button, you should get the current time inserted automatically.