• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Vim Modes

Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Published: 1/31/2024

About Terminus

Introduction

Vim (Vi iMproved) essentially differs from other editors by its use of “modes” inherited from vi. Each mode serves a different purpose like editing text, inserting text, running commands, and so on. It is therefore important to understand what they do, how to switch between them, and how they may influence or change the behavior of Vim’s predefined hotkeys. We’ll cover the 7 most frequently used modes any developer should know:

  • Normal
  • Insert
  • Visual
  • Command-line
  • Replace
  • Binary
  • Org

Normal mode

The Normal mode is the default mode when launching Vim. It is the one you’ll spend the most time using as it allows you to navigate the text, copy/cut/paste characters, words and lines, but also roll-back actions, and so on.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

The fastest way to get back to the Normal mode from any mode you are currently in is to press on the <Esc> key twice, which should cause the screen to flash or the bell to ring.

Insert mode

The Insert mode is the one you should be the most familiar with. It allows you to modify the text buffer by typing and removing characters, the same way you would do in most modern text editors.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

There are 3 ways to enter the Insert mode from the default Normal mode:

  • Pressing i (for insert) will directly switch to Insert mode.
  • Pressing a (for append) will switch to Insert mode and move the cursor after the current character.
  • Pressing o will switch to Insert mode and insert a new line below the line the cursor is on.

Visual mode

The Visual mode allows you to visually highlight (select) specific text areas and run commands on them.

To enter the Visual mode from the Normal mode, you can press on v—which will mark the beginning of the selection—and then use the arrow keys to move the cursor to the desired end of the selection. You can then use any of the commands available in the Normal mode for cutting, copying, pasting, and so on.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Alternatively, you can also use:

V (for Visual Line mode) which will automatically select entire lines.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

<Ctrl> + v (for Block Visual mode) which will select rectangular regions of the text.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Command-line mode

The Command-line mode offers a more advanced way of executing commands that are cumbersome or impossible to perform through the Normal mode. For example searching and replacing, or saving and quitting.

To enter the Command-line mode, you can press on :, which will cause the cursor to move at the bottom of the window in the command box. You can then write any command you like and press enter to execute it.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

For example:

  • :w (for write) will save the buffer to the file.
  • :q (for quit) will attempt to close the program (without saving).
  • :%s/old/new/g (for search) will search and replace all occurrences of old by new in the document.

Note that, on completion of the command, Vim automatically returns to the previous mode it was in.

Replace mode

The Replace mode allows you to replace existing text by directly typing over it.

To enter the Replace mode from the Normal mode, you can press on R and start typing characters, which will automatically move the cursor on to the next character.

When you’re done typing, simply press on <Esc> to come back to the Normal mode.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Note that when in Replace mode, hitting <Backspace> will automatically undo the changes and replace the new characters by the previous ones.

Binary mode

The Binary mode allows you to edit binary files, which as a reminder, are files that are not text files and that can be seen as a succession of bytes, such as compiled programs, images, compressed archives, and so on.

To open a file in Binary mode, we can use the -b option flag that will automatically alter Vim’s default behavior by setting the textwidth and wrapmargin properties to 0 as well as turning off the modeline and expantab options.

 $ vim -b 
Run in Warp

One thing to note is that in Binary mode, the <EOL> (end of line) will only be written if it was already present in the original file.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

In order to facilitate the modification of a binary file—to apply a patch for example—we can use the :%!xxd command that will replace the buffer with an editable hexadecimal dump where:

  • The left column shows the offset of the first byte on each line.
  • The middle column shows the bytes in hexadecimal.
  • The right column shows the printable characters.
Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Once you’re done editing the hexadecimal part, you can reverse the hexadecimal bytes to binary using the :%!xxd -r command, and save your file using the :s command. Note that any modifications performed on the right-hand side column will automatically be ignored.

Org mode

Vim-OrgMode is a text and task management plugin for Vim based on Emacs’ Org-Mode. It enhances Vim’s experience by providing support for keeping notes, maintaining todo lists, and planning projects.

Some of these features include:

  • Syntax highlighting for displaying the text in different colors and fonts.
  • Headlines for creating outline trees making it possible to show or hide parts of the text in the buffer.
  • Plain lists such as ordered lists (with numbers) and unordered lists (with dashes).
  • Links that behave like HTML hyperlinks to include references to either external files or website URLs.
  • Todo lists with checkbox support.
  • Formatted dates and times.

Written by

Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Filed Under

Related Articles

Vim Find And Replace

You can use either the substitute command or the slash and dot method to search for patterns and replace with different values.

VimVi
Thumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory Kim
Glory Kim

Vim / Vi Page Up and Down Controls

Quick reference for Vim's page up and down controls

VimVi
Thumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory Kim
Glory Kim

Copy & Paste in Vim / Vi

Copy (Yank), Paste (Put) and Cut (Delete) in Vim

VimVi
Thumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica Wang
Jessica Wang

Undo & Redo in Vim / Vi

Keyboard shortcuts and summary of how Vim tracks changes

VimVi
Thumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica Wang
Jessica Wang

Show & Hide Line Numbers in Vim / Vi

Toggle absolute and relative line numbers

VimVi
Thumbnail for Amber ChenThumbnail for Amber ChenThumbnail for Amber ChenThumbnail for Amber Chen
Amber Chen

Select all in Vim / Vi

Select all and copy, paste, or delete the contents

VimVi
Thumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory Kim
Glory Kim

Searching in Vim

Search forward, backward, case insensitive, and more

VimVi
Thumbnail for Neeran GulThumbnail for Neeran GulThumbnail for Neeran GulThumbnail for Neeran Gul
Neeran Gul

Go To End of File in Vim / Vi

Select and delete to the end of a file in Vim

VimVi
Thumbnail for Preston Tunnell WilsonThumbnail for Preston Tunnell WilsonThumbnail for Preston Tunnell WilsonThumbnail for Preston Tunnell Wilson
Preston Tunnell Wilson

How to delete lines in Vim / Vi

The best answer depends on which mode you use

VimVi
Thumbnail for Andrew CarlsonThumbnail for Andrew CarlsonThumbnail for Andrew CarlsonThumbnail for Andrew Carlson
Andrew Carlson

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for nullThumbnail for nullThumbnail for nullThumbnail for null