Linux command: vim
Edit a text file in the terminal
Vim is a text editor that runs in a terminal. It has modes because the keyboard does two jobs: in Insert mode, letters become text; in Normal mode, keys move around the file or issue editing commands. The open text sits in a buffer, Vim's working copy in memory. You must write the buffer to save changes to the file. A common first edit is to open a practice file, press i, type a line, then press Escape to return to Normal mode. From Normal mode, i starts typing before the cursor, a starts after it, and o opens a new line below.
When you have finished typing, the Escape key leaves Insert mode. If a key moves the cursor or triggers an edit command when you meant to type, check which mode is active. vim path/to/file opens an existing file or starts a new one at that path.
Save or leave the editor
From Normal mode, type : to open Vim's command line. These commands handle common choices:
:w write the current buffer to its file
:q quit when there are no unsaved changes
:wq write the file and quit
:q! quit without saving the current buffer
:w writes the buffer; :q refuses to discard unsaved edits. :wq does both operations in order. The ! in :q! overrides Vim's safeguard and discards edits that have not been written. It does not reverse earlier saves. If :w fails, check the filename, directory permissions, and whether the file is marked read-only before considering an ownership or privilege change.
A disposable file is a good place to practice:
vim /tmp/vim-practice.txt
Press i, type a couple of lines, press Escape, then enter :wq and press Enter. Inspect the result with cat /tmp/vim-practice.txt. Repeat the edit and use :q! to see that Vim discards only the unsaved buffer changes.
Find help and text
Vim's built-in help works from Normal mode. Enter :help or a topic such as :help :write or :help usr_02.txt, then press Enter. To search within a file, type /, enter a term, and press Enter; n moves to the next match. Read nearby lines before changing a setting. Many installations include vimtutor, an interactive introduction, but some systems ship a minimal vi-compatible build or disable features. If a command behaves differently, use the local help for the installed version.
Interactive exercises
Materials
- Getting Started with Vim Editor in Linux - GeeksforGeeksI think it will be useful for you





