How to save + close file when editing in bash?
Solution 1:
Esc will only throw you back into command mode in VI or Vim. To Save and quit press Shift + Z + Z, :wq, or :x in command mode. If you are opening the file in read only mode you will have to hit :q!.
Consider looking at this cheatsheet as well for more macros VI cheatsheet
Solution 2:
If you are new to Linux I would suggest using something other than vi
. For instance, nano
is fairly user-friendly, although much less powerful. Also, vim
is a variant of vi
that has some more features (like syntax highlighting) and is slightly easier to use.