
A practical guide to editing configuration files and documents on Ubuntu/Debian and CentOS/AlmaLinux using nano, vim, and gedit.
Before starting make sure ur linux is ready.
- Ubuntu: ubuntu.com/download
- Debian: debian.org/distrib
- CentOS Stream: centos.org/download
- AlmaLinux: almalinux.org/download
- Talkecho full toturial: Click here
Install the Editors
# Ubuntu/Debian
sudo apt update
sudo apt install -y nano vim gedit
# CentOS/AlmaLinux
sudo dnf install -y nano vim gedit
Note: gedit
is a graphical editor (needs a desktop). On servers use nano
or vim
.
nano (Beginner-Friendly)
# open a file (create if missing)
nano /etc/hosts
# open as root (system files)
sudo nano /etc/ssh/sshd_config
Common nano Shortcuts
- Ctrl+O — Write (save)
- Ctrl+X — Exit
- Ctrl+W — Search
- Alt+R — Replace
- Ctrl+K — Cut line, Ctrl+U — Paste
- Alt+G — Go to line
Enable line numbers permanently by adding to ~/.nanorc
:
set linenumbers
set tabsize 2
set smooth
vim (Powerful & Modal)
vim ~/.bashrc
sudo vim /etc/fstab
Two Modes
- Normal — navigate and run commands.
- Insert — type text (i to enter, Esc to leave).
Essential vim Commands
:w " save
:q " quit
:wq " save and quit
:q! " quit without saving
u " undo
Ctrl+r " redo
/word " search forward
n / N " next / previous match
gg / G " go to top / bottom
yy / p " copy (yank) line / paste
Start with a friendlier config:
echo -e "set number\nset ignorecase smartcase\nsyntax on" >> ~/.vimrc
gedit (Graphical Editor)
gedit mynotes.txt & # open in background
pkexec gedit /etc/default/grub # open system file with GUI admin prompt
Use Find (Ctrl+F), Replace (Ctrl+H), and enable line numbers in Preferences → View.
Search & Replace Examples
nano
Ctrl+W, type the term, press Enter.
Alt+R to replace, enter old → new.
vim
:%s/old/new/g " replace in whole file
:%s/old/new/gc " confirm each match
Best Practices
- Create a quick backup before editing system files:
sudo cp /etc/ssh/sshd_config{,.bak}
- Validate syntax after edits (e.g., SSH):
sudo sshd -t && echo "OK"
- Use
sudo -e /path/file
to edit with your default editor safely. - Set your default terminal editor:
sudo update-alternatives --config editor # Debian/Ubuntu sudo update-alternatives --config editor # (present on many RHEL-based systems too)