Editing text with Nano and Vim
Quick answer
An editor changes a text buffer and saves it to a file. Nano uses visible shortcuts, while Vim uses modes. Learn how to save and leave each editor before using either on important configuration files.
Prepare the practice environment
Use the chapter fixture described in lab-fixtures/text-streams/README.md. Run setup as a normal user in a disposable Linux environment, enter the printed directory and check pwd. Every example assumes a fresh fixture. Commands omit the terminal prompt; outputs below are not commands.
How it works
In Nano with default bindings, type normally, press Ctrl+O to write, Enter to confirm the displayed filename, then Ctrl+X to quit. In Vim, normal mode interprets keys as commands; i enters insert mode, Esc returns to normal mode, and :wq followed by Enter saves and exits. :q! followed by Enter discards unsaved changes in the current window, so use it only deliberately. The colon commands are typed inside Vim, not at a shell prompt. Commands may not be installed; command -v checks availability. A text editor is not a word processor; use plain text and avoid editing system files with elevated privileges.
Think of the editing buffer as a working copy in memory. Until you save, another command reading the file may still see the previous bytes. After returning to the shell, check the intended filename and read it with cat; merely exiting the editor is not evidence that the desired changes were saved.
Try the examples
Type exactly hello nano, then Enter. Save using Ctrl+O, Enter and Ctrl+X (default shortcuts); if the command is missing, skip this path. Verify with cat nano-note.txt.
Manual interaction; no automated output asserted.
Press i, type hello vim, press Esc, type :wq and press Enter. Verify with cat vim-note.txt. Do not type the colon command in insert mode.
Manual interaction; no automated output asserted.
This independent read-only check shows how to verify saved text; substitute your own practice filename only after saving it.
Expected stdout:
startcheckfinishCommon mistakes
Closing a terminal is not a reliable save operation. In Vim, pressing letters in normal mode can edit or move text unexpectedly. Use Esc if unsure, then inspect the buffer before saving. In Nano check the filename prompt rather than overwriting another file.
Practice
Create one note with either installed editor containing the line hello learner. Save, exit, then use cat to verify. If neither editor is installed, describe the keyboard sequence instead.
Related references
Study: nano, vim. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Editing text with nano and Vim — Knowledge Check
Apply the lesson concepts to the controlled text fixture.
Which Vim key enters insert mode from normal mode?
Which Vim command saves and exits?
What does Nano Ctrl+O normally do?
What is the risk of :q!?