DEV Community

Cover image for Why Every Developer Should Learn Vim πŸ’»πŸ«΅
Martins Gouveia
Martins Gouveia

Posted on β€’ Edited on

2 1 1 1

Why Every Developer Should Learn Vim πŸ’»πŸ«΅

No matter if you are a sysadmin or a software developer, if you work in the Linux terminal, you would face the situation where you need to edit text files in the terminal

What is Vim?

Vim is a powerful text editor used in Unix/Linux systems, known for its efficiency and flexibility. It operates in different modes, each serving a specific purpose. Here are some essential Vim commands to help you get started:

Modes in Vim

Vim has three primary modes:

Command Mode: This is the default mode when you start Vim. You can navigate, delete, and copy text in this mode.

Insert Mode: Used for inserting text into the file. Enter this mode by pressing i, a, I, A, o, or O.

Visual Mode: Allows you to select text using the arrow keys.

Basic Commands

Entering Insert Mode

  • i: Insert before the cursor.
  • a: Insert after the cursor.
  • I: Insert at the beginning of the line.
  • A: Insert at the end of the line.
  • o: Open a new line below the current line.
  • O: Open a new line above the current line.

Navigating in Vim

  • h: Move left.
  • j: Move down.
  • k: Move up.
  • l: Move right.
  • gg: Move to the beginning of the file.
  • G: Move to the end of the file.
  • nG: Move to line number n.

Editing Text

  • x: Delete the character under the cursor.
  • X: Delete the character before the cursor.
  • dd: Delete the current line.
  • dw: Delete from the cursor to the end of the word.
  • d$: Delete from the cursor to the end of the line.
  • dG: Delete from the cursor to the end of the file.

Copying and Pasting

  • yy: Copy the current line.
  • yw: Copy from the cursor to the end of the word.
  • y$: Copy from the cursor to the end of the line.
  • yG: Copy from the cursor to the end of the file.
  • p: Paste after the cursor.
  • P: Paste before the cursor.

Undo and Redo

  • u: Undo the last change.
  • Ctrl + r: Redo the undone change.

Searching and Replacing

  • /search_term: Search for search_term.
  • n: Move to the next match.
  • N: Move to the previous match.
  • :%s/foo/bar/g: Replace all occurrences of foo with bar in the entire file.
  • :%s/foo/bar/gc: Replace all occurrences with confirmation.

Saving and Quitting

  • :w: Save the file.
  • :wq: Save and quit.
  • :q: Quit (if no changes have been made).
  • :q!: Quit without saving changes.

These commands cover the basics of using Vim effectively. For more advanced usage, refer to the detailed guides and cheat sheets available online

Image of Docusign

πŸ› οΈ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay