Fundamentals 10 min read

Master Vim: 12 Essential Tips to Boost Your Coding Efficiency

This guide presents twelve practical Vim techniques—from using built‑in help and saving files with sudo to converting indentation, displaying line numbers, and configuring spell checking—empowering developers to work faster and avoid common pitfalls.

Linux Cloud Computing Practice
Linux Cloud Computing Practice
Linux Cloud Computing Practice
Master Vim: 12 Essential Tips to Boost Your Coding Efficiency

1. Use Built‑in Help

Vim’s internal help can be accessed with :help followed by a command or keyword, e.g., :help :w for the write command.

2. Edit as Normal User, Save as Root

When a file requires elevated privileges, type: :w !sudo tee % The command writes the buffer to stdout, pipes it to sudo tee, which writes to the original file ( %).

3. Convert Spaces ↔ Tabs

3.1 Convert spaces to tabs

:set noexpandtab</code>
<code>:retab!

3.2 Convert tabs to spaces

:set expandtab</code>
<code>:set tabstop=4</code>
<code>:set shiftwidth=4</code>
<code>:retab

4. Indent All Lines

Press gg to go to the top, then = and G to re‑indent the whole file, or use the command :gg=G.

5. Preserve Indentation When Pasting

Add the following to .vimrc: set pastetoggle=<F2> Press F2 before pasting to keep original indentation.

6. Start Writing at Correct Indent Depth

In normal mode, press S (uppercase) at the beginning of a line; Vim moves the cursor to the proper indent and enters insert mode.

7. Show Diff Before Saving

Use: :w !diff % - This writes the unsaved buffer to stdin and compares it with the file on disk.

8. Enable Spell Checking

Turn on Vim’s spell checker with: :set spell Misspelled words are highlighted according to the color scheme.

9. Display Line Numbers

Add to .vimrc: set number relativenumber This shows absolute numbers on the current line and relative numbers on others.

10. Open File at a Specific Line

Launch Vim with +n where n is the line number:

vim +n <file-name>

11. Use Readable Color Schemes

Select a color scheme that highlights syntax clearly; examples are shown in the accompanying screenshots.

12. Delete Text in Insert Mode

Ctrl+w

– delete the previous word. Ctrl+h – delete the previous character. Ctrl+u – delete everything before the cursor on the current line. Ctrl+k – delete everything after the cursor on the current line.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ConfigurationText Editingcommand-lineEditor Tips
Linux Cloud Computing Practice
Written by

Linux Cloud Computing Practice

Welcome to Linux Cloud Computing Practice. We offer high-quality articles on Linux, cloud computing, DevOps, networking and related topics. Dive in and start your Linux cloud computing journey!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.