Skip to main content
Engineering LibreTexts

05-A.2: Creating and Editing Text files - Vim Editor

  • Page ID
    32116
  • Vim Editor

    Vim offers more modes than the original vi (which offers only the "normal", "insert" and "command–line" modes). These additional modes make vim more powerful and easier to use; because of this, vim users should at least be aware that they exist. (NOTE: If you ever enter a mode you are unfamiliar with, you can usually press ESC to get back to normal mode.)

    Here is a short overview of each mode available in vim:

    Mode Name Description help page
    normal For navigation and manipulation of text. This is the mode that vim will usually start in, which you can usually get back to with ESC. :help Normal-mode
    insert For inserting new text. The main difference from vi is that many important "normal" commands are also available in insert mode - provided you have a keyboard with enough meta keys (such as Ctrl, Alt, Windows-key, etc.). :help Insert-mode
    visual For navigation and manipulation of text selections, this mode allows you to perform most normal commands, and a few extra commands, on selected text. :help Visual-mode
    command-line For entering editor commands - like the help commands in the third column. :help Command-line-mode

    Each mode is described below.

    Normal Mode

    Open a console terminal from your Linux operating system, and enter vi .

    Starting the vi editor from the command line is as simple as entering vi or vim
    Figure \(\PageIndex{1}\): Run the vi command from the command line. ("vi command line" by Patrick McClanahan is licensed under CC BY-SA 4.0)

    You are now in Normal mode - also referred to as Command mode, because we enter commands from this mode. This is where vim normally starts. If you have text, you can move around with your arrow keys or other navigation keystrokes (which you will see later). To make sure you are in Normal mode, simply hit the Esc (Escape) key.

    Tip: Esc switches to Normal mode. Even though you are already in Normal mode, hit Esc just for practice's sake. This is what a new file would look like; if you opened an existing file you would see the content of the file.

    image of quitting vi using the colon, q and exclamation point to quit without saving
    Figure \(\PageIndex{2}\): Quitting vim. ("quit vi" by Patrick McClanahan is licensed under CC BY-SA 4.0)

    Now, this will be interesting. Press : (the colon key) followed by q! (i.e., :q!). Your screen will look like this:

    Pressing the colon in Normal mode switches vim to Command Line mode, and the :q! command quits (q) without saving (!). In other words, you are abandoning all changes. You can also use ZQ - choose whichever option is more convenient.

    A brief look at the other modes continues in the following pages.

    Adapted from:
    "Learning the vi Editor/Vim/Modes" by Multiple contributors, WikiBooks is licensed under CC BY-SA 3.0

    • Was this article helpful?