Technical skill

Linux commands group: file editors

Subject: .../LINUX

Change text with a terminal editor

A terminal editor lets you open a text file, make changes, and save them. While you edit, the program keeps a working copy in memory called a buffer. The file on disk changes only when you save successfully. That is why it helps to learn how saving and quitting work before editing an important file.

GNU nano, Vim, and GNU Emacs all run in a terminal, but their controls differ. Nano shows shortcut hints and accepts typed text directly. Vim has Normal and Insert modes: Normal mode uses keys as commands; Insert mode puts typed characters into the text. Emacs uses key combinations. For example, C-x C-s saves the current buffer in Emacs. Do not assume the same key has the same meaning in every editor.

Practice in a disposable file named practice.txt. These commands open it in each editor:

nano practice.txt
vim practice.txt
emacs -nw practice.txt

In nano, type a line, press Ctrl+O to write the buffer, confirm the filename, then press Ctrl+X to exit. In Vim, press i, type a change, press Esc, and enter :wq to save and quit. :q! discards edits still in the buffer; it does not undo text already saved to disk. In Emacs, C-x C-s saves and C-x C-c exits. Read any prompt before answering so you know whether the editor is asking about saving or quitting.

In Emacs notation, C means hold the Control key. Nano may show ^O for the same key combination; there, ^ means Control. The screen and shortcuts can vary with terminal layout and editor version. If a key behaves unexpectedly, use that editor's own help instead of trying combinations at random.

Before opening a real file, check its path. A relative name such as notes.txt depends on the shell's current folder, so the same name can refer to different files from different locations. Copy an existing file to a new path for an initial exercise and compare the saved result. When editing source code or structured data, inspect the file after saving. A line that looks wrapped on screen may still be one long line; an editor's hard-wrap setting can insert actual newlines. Check the documentation before changing line endings, encoding, indentation, or formatting settings.

Interactive exercises

Materials

Check yourself
Q:

How to exit vim text editor?

:q
:q!
:wq
:wq!
Skillsets
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Linux for backend developer preview
image descriptionLinux for backend developer
by Artem Naumenko (fb)
16 users
Skillset Devops preview
image descriptionDevops
by Dio
3 users
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful