2.2 Linux Editors: nano, vim, and Remote Editing
On Linux servers, you often need to change a configuration file, write a small script, or add an environment variable. A graphical interface may not exist, so you should know at least one terminal editor.
nano: direct, friendly, beginner-safe
bash
nano app.confnano shows shortcuts at the bottom. ^ means Ctrl:
Ctrl+O: save.Enter: confirm the filename.Ctrl+X: exit.
If you just need to edit a small config quickly, nano is a good choice.
Loading concept check...
vim: powerful, but modal
bash
vim app.confvim confuses beginners because it is not always in "type text" mode. Common modes:
- Normal mode: move, delete, copy, and enter commands.
- Insert mode: type text.
- Command-line mode: enter commands such as
:w,:q, and:wq.
Minimum survival mantra:
text
i enter insert mode
Esc return to normal mode
:w save
:q quit
:q! force quit without saving
:wq save and quitLoading interactive lab...
Loading concept check...
Remote and local editing
In real projects, you do not always edit directly on a server. Common options include:
- VS Code Remote SSH: open a remote directory from local VS Code.
scporrsync: upload or synchronize files.- Git: edit locally, commit, push, and let the server pull or deploy.
Direct server editing is useful for temporary diagnosis and small config changes. Long-term projects should use version control and a deployment process.
Configuration editing principles
- Back up first:
cp app.conf app.conf.bak. - Validate after editing: services often have checks such as
nginx -torsystemctl status. - If unsure, edit a test file or comment first.
- For important configuration, record why the change happened.
Loading practice...