Editing files¶
To edit a file from the Unix CLI, you can use nano or vim.
Nano¶
nano myfile.txt
Nano uses the Ctrl-key for special commands. The
interface tells you which shortcut does what, where ^X means
Ctrl X
| Shortcut | Command | |
|---|---|---|
^O |
Ctrl O |
save file |
^X |
Ctrl X |
exit; quit |
^W |
Ctrl W |
search |
Vim¶
vim myfile.txt
Vim has two modes, and starts in Command mode by default.
| Shortcut | Command |
|---|---|
| Command mode | |
i |
insert; go to editing mode |
w |
jump to next word |
dd |
delete a line |
p |
paste deleted line |
/foo |
search for text foo |
/ |
repeat previous search |
:syntax on |
enable syntax colors |
:u |
undo |
:w |
write / save file |
:q |
quit |
:wq |
write and quit |
:wq! |
force write and quit |
| Editing mode | |
Esc |
go to command mode |