Text Editors
Nano
Nano is a simple, user-friendly text editor included with most Linux distributions.
Basic Usage
nano filename
Keyboard Shortcuts
Ctrl + O: Save (Write Out)Ctrl + X: ExitCtrl + W: SearchCtrl + K: Cut lineCtrl + U: PasteCtrl + C: Show cursor positionCtrl + G: Help
Features
- Syntax highlighting (with nanorc configuration)
- Search and replace
- Line numbers
- Mouse support
Vim
Vim (Vi IMproved) is a powerful, modal text editor.
Modes
- Normal: For navigation and commands
- Insert: For typing text
- Visual: For selecting text
- Command-line: For commands
Basic Commands
vim filename
Navigation (Normal mode)
h,j,k,l: Move left, down, up, rightw: Next wordb: Previous word0: Beginning of line$: End of linegg: Beginning of fileG: End of file:[line]: Go to line number
Editing
i: Insert before cursora: Insert after cursoro: Open new line belowO: Open new line abovex: Delete characterdd: Delete lineyy: Yank (copy) linep: Paste after cursoru: UndoCtrl + r: Redo
Saving and Quitting
:w: Write (save):q: Quit:wqor:x: Write and quit:q!: Quit without saving
Advanced Features
- Search:
/pattern - Replace:
:%s/old/new/g - Multiple files:
:e filename - Split windows:
:vsplitor:split
Emacs
Emacs is a highly extensible text editor.
Basic Usage
emacs filename
Key Bindings
Ctrl + x Ctrl + s: SaveCtrl + x Ctrl + c: ExitCtrl + k: Kill (cut) lineCtrl + y: Yank (paste)Ctrl + s: Search forwardCtrl + r: Search backward
Features
- Built-in Lisp interpreter
- Email client, web browser, etc.
- Highly customizable
Choosing an Editor
- Nano: Best for beginners and quick edits
- Vim: Powerful for advanced users, ubiquitous on servers
- Emacs: Most feature-rich, steeper learning curve
Configuration
Nano
Edit ~/.nanorc:
set linenumbers
set mouse
include "/usr/share/nano/*.nanorc"
Vim
Edit ~/.vimrc:
syntax on
set number
set tabstop=4
set shiftwidth=4
set expandtab
Emacs
Edit ~/.emacs or ~/.emacs.d/init.el:
(global-linum-mode t)
(setq-default tab-width 4)
Practice Exercises
- Create a file with Nano and write a short paragraph.
- Open the same file with Vim and make some edits.
- Practice Vim navigation and editing commands.
- Configure your preferred editor with basic settings.
Next, we'll cover package management with APT.
