DEV Community

Angel Oduro-Temeng Twumasi
Angel Oduro-Temeng Twumasi

Posted on • Edited on

9 1 1 1 2

💻Mastering Emacs and Vi: A Beginners Guide

Introduction

Emacs and Vi are two editors which are very popular with terminal usage. While Emacs comes preinstalled with MacOS, Vi comes preinstalled with most Linux distros. If you use windows, you might have to download them to be able to use them.

Uses of emacs

  • For text editing and manipulation.
  • Could be used as an IDE for programming languages.
  • It comes with version control systems which makes it versatile for software development.

Uses of Vi

  • It is the preferred editor for terminal based tasked and hence used extensively.
  • Suitable for editing files on remote servers via SSH.
  • Its modal of editing allows for efficient and rapid editing once mastered.

Both Emacs and Vi have two identical modes. These are:

  1. The command mode
  2. The insert mode

Switching between modes

  • Press ESC key to enter into command mode
  • Press i to enter into insert mode ie you can now insert data

Basic commands in Emacs:

Opening files

  • C-x C-f : Open file
  • C-x C-s : Save current buffer
  • C-x C-w : Save current buffer with a different name

Moving commands

  • C-a : Move the cursor to the beginning of the line
  • C-e : Move the cursor to the end of line

Editing commands

  • C-x u : Undo the last change
  • C-y : Paste the most recently cut region
  • C-w : Cut the selected region (to select a region do C- or Ctrl + space then C-f for the highlights)_
  • M-w : Copy the selected region
  • C-d : Delete character at the cursor

Others

  • C-s : Search forward for a pattern
  • C-r : Search backwards for a pattern

  • C-x C-c : Quit Emacs (you'll be prompted for confirmation)

Note that in Emacs, C could be interpreted as Ctrl and M could be interpreted as Alt

Basic commands in Vi

Opening a file

  • Vi <filename> to open the file in Vi

Editing

  • x : Delete the character at the current cursor position
  • yy : Copy the current line
  • dd : Cut the current line
  • u : Undo the last change
  • p : Paste the recently cut or copied item

Moving commands

  • h : Move cursor to the left
  • j : Move cursor one line down
  • k : Move cursor one line up
  • l : Move cursor to the right
  • G : Move cursor to the last line of the file
  • gg : Move cursor to the first line of the file
  • 0 : Move cursor to the start of current line
  • $ : Move cursor to the end of current line

Others

  • :w : Save the file
  • :q : Quit Vi

  • :x : Quit Vi after writing out modified changes. If there are no modified changes, it just quits Vi

  • :wq : Save and Quit

  • :q! : Quit without saving

In conclusion, I hope you found this guide to Emacs and Vi helpful in enhancing your text editing skills. Remember to subscribe to stay updated with more informative content like this. Don't forget to hit the like button if you found it valuable! Share your favorite and most frequently used command or the one you're planning to use in the comments below. Your engagement and feedback are greatly appreciated. Happy editing 😎

Follow me on Twitter and LinkedIn

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

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

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay