- Choosing a Text Editor
- Nano โ The Beginner-Friendly Editor
- Vim โ The Power Editor
- Neovim โ Modern Vim
- Other Editors
- Practice Exercises
| Editor | Learning Curve | Speed | Best For |
|---|---|---|---|
| nano | โญ Easy | Medium | Quick edits, beginners |
| vim | โญโญโญโญ Hard | Fast | Power users, servers |
| neovim | โญโญโญโญ Hard | Fastest | Modern vim experience |
| emacs | โญโญโญโญโญ Very Hard | Fast | Everything (it's practically an OS) |
| VS Code | โญโญ Easy | Medium | GUI development |
๐ก Recommendation: Learn nano for quick edits, and invest time in vim โ it's available on every Linux server and will make you incredibly productive.
Nano is pre-installed on most Linux systems and shows keyboard shortcuts at the bottom.
nano filename.txt # Open or create a file
nano +15 filename.txt # Open at line 15
nano -l filename.txt # Show line numbers
sudo nano /etc/hosts # Edit system files (need root)The ^ symbol means Ctrl and M- means Alt.
| Shortcut | Action |
|---|---|
Ctrl + O |
Save (Write Out) |
Ctrl + X |
Exit |
Ctrl + K |
Cut line |
Ctrl + U |
Paste line |
Ctrl + W |
Search |
Ctrl + \\ |
Search & Replace |
Ctrl + G |
Help |
Ctrl + _ |
Go to line number |
Alt + U |
Undo |
Alt + E |
Redo |
Ctrl + C |
Show current line number |
Alt + A |
Start selecting text |
Ctrl + ^ |
Start selecting (alternative) |
# Create/edit nano config
nano ~/.nanorc# ~/.nanorc โ Useful nano settings
set tabsize 4 # Set tab width to 4 spaces
set tabstospaces # Convert tabs to spaces
set linenumbers # Always show line numbers
set autoindent # Auto-indent new lines
set mouse # Enable mouse support
set smooth # Smooth scrolling
set constantshow # Always show cursor position
set softwrap # Soft wrap long lines
# Syntax highlighting (usually enabled by default)
include "/usr/share/nano/*.nanorc"Vim (Vi IMproved) is the most popular terminal editor on servers. It has a steep learning curve but extraordinary power once mastered.
๐ Analogy: Vim is like learning to touch-type. Slow and frustrating at first, but once you get it, you'll never go back.
sudo apt install vim # Debian/Ubuntu
sudo dnf install vim-enhanced # Fedora
sudo pacman -S vim # ArchVim is a modal editor โ keys do different things depending on which mode you're in:
โโโโโโโโโโโโโโโโโโโโ
i, a, o โ INSERT MODE โ Esc
โโโโโโโโโโโโโโโถโ Type text here โโโโโโโโโโโโโโโโ
โ โโโโโโโโโโโโโโโโโโโโ โ
โ โผ
โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ
โ โ COMMAND MODE โ โ NORMAL MODE โ
โ โ :w :q :wq :%s โโโโโโโโโโโ Navigate, editโ
โ โโโโโโโโโโโโโโโโโโโโ : โ copy, delete โ
โ โโโโโฌโโโโโโโโโโโโโ
โ โ v, V
โ โโโโโโโโโโโโโโโโโโโโ โ
โ โ VISUAL MODE โโโโโโโโโโโโโโโโ
โ โ Select text โ
โ โโโโโโโโโโโโโโโโโโโโ
| Mode | Purpose | Enter | Leave |
|---|---|---|---|
| Normal | Navigate, delete, copy | Esc |
Press mode key |
| Insert | Type text | i, a, o |
Esc |
| Visual | Select text | v, V, Ctrl+v |
Esc |
| Command | Run commands | : |
Enter or Esc |
1. Open: vim myfile.txt
2. Type text: Press 'i' (enters Insert mode), type your text
3. Stop typing: Press 'Esc' (back to Normal mode)
4. Save: Type ':w' and press Enter
5. Quit: Type ':q' and press Enter
6. Save+Quit: Type ':wq' and press Enter
7. Quit without saving: Type ':q!' and press Enter
๐จ Stuck in Vim? Press
Escthen type:q!and press Enter. This quits without saving.
Character Movement:
h โ left j โ down k โ up l โ right
Word Movement:
w โ next word start b โ previous word start
e โ next word end W โ next WORD (space-separated)
Line Movement:
0 โ start of line $ โ end of line
^ โ first non-space g_ โ last non-space
Screen Movement:
gg โ first line G โ last line
5G โ go to line 5 Ctrl+d โ half page down
Ctrl+u โ half page up H โ top of screen
M โ middle of screen L โ bottom of screen
Search:
/pattern โ search forward ?pattern โ search backward
n โ next match N โ previous match
* โ search word under cursor
Insert Text:
i โ insert before cursor a โ insert after cursor
I โ insert at line start A โ insert at line end
o โ new line below O โ new line above
s โ delete char + insert S โ delete line + insert
Delete:
x โ delete character X โ delete char before cursor
dd โ delete entire line D โ delete to end of line
dw โ delete word d$ โ delete to line end
d0 โ delete to line start 3dd โ delete 3 lines
Copy (Yank) & Paste:
yy โ copy line yw โ copy word
y$ โ copy to end of line p โ paste after cursor
P โ paste before cursor 3yy โ copy 3 lines
Undo & Redo:
u โ undo Ctrl+r โ redo
Change (delete + enter insert mode):
cw โ change word cc โ change line
c$ โ change to line end ci" โ change inside quotes
:w " Save
:q " Quit
:wq or :x or ZZ " Save and quit
:q! " Quit without saving
:w newfile.txt " Save as different file
:e otherfile.txt " Open another file
:%s/old/new/g " Replace all occurrences in file
:%s/old/new/gc " Replace with confirmation
:s/old/new/g " Replace in current line only
:set number " Show line numbers
:set nonumber " Hide line numbers
:set paste " Paste mode (disable auto-indent)
:set nopaste " Normal mode again
:! ls " Run external command
:r !date " Insert command output into file
:r filename " Insert contents of another file
:split file.txt " Horizontal split
:vsplit file.txt " Vertical split
Ctrl+w w " Switch between splits
Ctrl+w q " Close splitv โ character-wise selection (like click+drag)
V โ line-wise selection (select entire lines)
Ctrl+v โ block selection (select a rectangle)
After selecting:
d โ delete selection y โ copy selection
> โ indent right < โ indent left
~ โ toggle case U โ uppercase
u โ lowercase : โ command on selection
# Create ~/.vimrc for permanent settings
vim ~/.vimrc" ~/.vimrc โ Essential settings
set number " Show line numbers
set relativenumber " Relative line numbers
set tabstop=4 " Tab width
set shiftwidth=4 " Indent width
set expandtab " Tabs โ spaces
set autoindent " Auto-indent
set smartindent " Smart indentation
set hlsearch " Highlight search results
set incsearch " Incremental search
set ignorecase " Case-insensitive search
set smartcase " ...unless uppercase used
set wildmenu " Tab completion menu
set mouse=a " Enable mouse
set clipboard=unnamedplus " Use system clipboard
set cursorline " Highlight current line
syntax on " Syntax highlighting
set background=dark " Dark background
colorscheme desert " Color scheme
set showmatch " Highlight matching brackets
set encoding=utf-8 " UTF-8 encoding
set scrolloff=8 " Keep 8 lines visible above/below cursorNeovim is a refactored, modern Vim with better defaults, Lua scripting, and LSP support.
# Install
sudo apt install neovim # Debian/Ubuntu
sudo dnf install neovim # Fedora
sudo pacman -S neovim # Arch
# Run
nvim filename.txt
# Config location
# ~/.config/nvim/init.vim (Vim script)
# ~/.config/nvim/init.lua (Lua โ recommended)| Feature | Vim | Neovim |
|---|---|---|
| Config file | ~/.vimrc |
~/.config/nvim/init.lua |
| Plugin system | Vimscript | Lua (faster) |
| Built-in LSP | โ No | โ Yes |
| Built-in terminal | Basic | Full |
| Async support | Limited | Full |
# Emacs
sudo apt install emacs
emacs filename.txt
# micro โ modern terminal editor
sudo apt install micro
micro filename.txt
# Visual Studio Code (from terminal)
code filename.txt# Set default editor for the system
sudo update-alternatives --config editor
# Or set via environment variable
export EDITOR=vim
export VISUAL=vim
# Add to ~/.bashrc to make permanent
echo 'export EDITOR=vim' >> ~/.bashrc- Nano: Create a file
practice.txtwith nano, add 5 lines, save and exit - Vim Basics: Open vim, enter insert mode, type "Hello Vim", save and quit
- Vim Navigation: Open
/etc/passwdin vim, navigate to line 10 using10G - Vim Editing: In vim, delete a line (
dd), undo (u), copy a line (yy), paste (p) - Vim Search: Open a large file in vim and search for a word using
/word - Vim Replace: Use
:%s/old/new/gto replace text in a file - Vim Config: Create a
~/.vimrcwith at least 5 settings from above - Editor Choice: Set your preferred editor as the system default
โ Previous: Package Management ยท ๐ Home ยท Next: Shell Scripting Fundamentals โ