Skip to main content
Engineering LibreTexts

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

  • Page ID
    32116
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    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 .

    pbmac@pbmas-server $ vi
    
    
    

    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.

    ~
    ~
    ~
    ~
    :q!
    

    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


    05-A.2: Creating and Editing Text files - Vim Editor is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?