In Vim the same x key either types a letter or erases the character under the cursor. The mode decides, and the editor has two.
Changing a line in a config takes a text editor. Servers almost always have Vim, so that is the one to learn. The command vim app.conf opens the file.
Vim has two main modes. In normal mode, keys are editor commands: move, delete, save. In insert mode, keys type text. Vim opens in normal mode, so a letter typed straight away runs a command and never shows up in the text.
| Keys | What they do |
|---|---|
i |
switch to insert mode, with -- INSERT -- at the bottom |
Esc |
go back to normal mode |
x |
delete the character under the cursor |
dd |
delete the whole line |
u |
undo the last change |
x, dd and u work in normal mode. Colon commands are typed there too and confirmed with Enter: :w saves the file, :q quits, :wq saves and quits, :q! quits without saving. Not sure which mode you are in? Press Esc: in normal mode it does nothing.
You saved the file with :w, made one more edit and quit with :q!. What does cat show after you quit?
-
:q!quits without saving: the last edit existed only in the editor, andcatdoes not show it. -
:whas already written the edit to disk.:q!discards only what changed after the last save. -
Quitting without saving leaves the file alone: the last saved version stays on disk.
:q! throws away only unsaved changes, and what :w saved is already on disk. Check cat app.conf after quitting: it shows the last saved version.
Key points
-
In normal mode keys are commands, in insert mode they are text;
iand Esc switch between them. -
:wqsaves the file and quits,:q!quits and throws away anything unsaved.